diff options
Diffstat (limited to 'portato/backend')
-rw-r--r-- | portato/backend/flags.py | 2 | ||||
-rw-r--r-- | portato/backend/package.py | 23 | ||||
-rw-r--r-- | portato/backend/portage/package.py | 60 | ||||
-rw-r--r-- | portato/backend/portage/system.py | 207 | ||||
-rw-r--r-- | portato/backend/system_interface.py | 133 |
5 files changed, 144 insertions, 281 deletions
diff --git a/portato/backend/flags.py b/portato/backend/flags.py index d388e08..018e804 100644 --- a/portato/backend/flags.py +++ b/portato/backend/flags.py @@ -677,7 +677,7 @@ def set_testing (pkg, enable): if (enable and line != "-1") or (not enable and line == "-1"): newTesting[cpv].remove((file, line)) - if (enable and not pkg.is_testing(use_keywords=True)) or (not enable and pkg.is_testing(use_keywords=True)): + if (enable and not pkg.is_testing()) or (not enable and pkg.is_testing()): return if not enable: diff --git a/portato/backend/package.py b/portato/backend/package.py index 1e17b1f..6d73a42 100644 --- a/portato/backend/package.py +++ b/portato/backend/package.py @@ -88,13 +88,15 @@ class Package (_Package): if f[0] == "~": f = f[1:] removed = True + + invf = flags.invert_use_flag(f) if f[0] == '-': - if flags.invert_use_flag(f) in i_flags and not (removed and flags.invert_use_flag(f) in m_flags): - i_flags.remove(flags.invert_use_flag(f)) + if invf in i_flags and not (removed and invf in m_flags): + i_flags.remove(invf) elif f not in i_flags: - if not (removed and flags.invert_use_flag(f) in m_flags): + if not (removed and invf in m_flags): i_flags.append(f) return i_flags @@ -165,9 +167,8 @@ class Package (_Package): p = self.get_ebuild_path() sp = p.split("/") - if len(sp): - import string - return string.join(sp[:-1],"/") + if sp: + return "/".join(sp[:-1]) def get_dependencies (self): """ @@ -243,7 +244,7 @@ class Package (_Package): raise NotImplementedError - def is_overlay(self): + def is_in_overlay(self): """Returns true if the package is in an overlay. @rtype: boolean""" @@ -271,7 +272,7 @@ class Package (_Package): raise NotImplementedError - def is_testing(self, use_keywords = False): + def is_testing(self, use_keywords = True): """Checks whether a package is marked as testing. @param use_keywords: Controls whether possible keywords are taken into account or not. @@ -370,13 +371,13 @@ class Package (_Package): raise NotImplementedError - def get_package_settings(self, var, tree = None): + def get_package_settings(self, var, installed = True): """Returns a package specific setting, such as DESCRIPTION, SRC_URI, IUSE ... @param var: the setting to get @type var: string - @param tree: an object defining whether to take the information from the installed package or from the ebuild - @type tree: unknown + @param installed: take the vartree or the porttree + @type installed: boolean @returns: the value of the setting @rtype: string""" diff --git a/portato/backend/portage/package.py b/portato/backend/portage/package.py index b07dc93..3502306 100644 --- a/portato/backend/portage/package.py +++ b/portato/backend/portage/package.py @@ -88,8 +88,8 @@ class PortagePackage (Package): def is_installed(self): return self._settings.vartree.dbapi.cpv_exists(self._cpv) - def is_overlay(self): - dir,ovl = self._settings.porttree.dbapi.findname2(self._cpv) + def is_in_overlay(self): + ovl = self.get_overlay_path() return ovl != self._settings.settings["PORTDIR"] and str(ovl) != "0" def get_overlay_path (self): @@ -100,23 +100,17 @@ class PortagePackage (Package): return (self._status != None) def is_missing_keyword(self): - if self._status and "missing keyword" in self._status: - return True - return False + return self._status and "missing keyword" in self._status - def is_testing(self, use_keywords = False): + def is_testing(self, use_keywords = True): testArch = "~" + self.get_global_settings("ARCH") if not use_keywords: # keywords are NOT taken into account - if testArch in self.get_package_settings("KEYWORDS").split(): - return True - return False + return testArch in self.get_package_settings("KEYWORDS").split() else: # keywords are taken into account status = flags.new_testing_status(self.get_cpv()) if status is None: # we haven't changed it in any way - if self._status and testArch+" keyword" in self._status: - return True - return False + return self._status and testArch+" keyword" in self._status else: return status @@ -130,15 +124,13 @@ class PortagePackage (Package): else: error(_("BUG in flags.new_masking_status. It returns \'%s\'"), status) else: # we have not touched the status - if self._status and ("profile" in self._status or "package.mask" in self._status): - return True - return False + return self._status and ("profile" in self._status or "package.mask" in self._status) + else: # we want the original portage value XXX: bug if masked by user AND by system # get the normal masked ones if self._status and ("profile" in self._status or "package.mask" in self._status): - if not flags.is_locally_masked(self, changes = False): # assume that if it is locally masked, it is not masked by the system - return True + return not flags.is_locally_masked(self, changes = False) # assume that if it is locally masked, it is not masked by the system else: # more difficult: get the ones we unmasked, but are masked by the system try: masked = self._settings.settings.pmaskdict[self.get_cp()] @@ -147,10 +139,7 @@ class PortagePackage (Package): for cpv in masked: if self.matches(cpv): - if not flags.is_locally_masked(self, changes = False): # assume that if it is locally masked, it is not masked by the system - return True - else: - return False + return not flags.is_locally_masked(self, changes = False) # assume that if it is locally masked, it is not masked by the system return False @@ -158,17 +147,15 @@ class PortagePackage (Package): reason = portage.getmaskingreason(self.get_cpv(), settings = self._settings.settings) if reason: - return reason[:-1] # strip of last \n + return reason.strip() else: return reason def get_iuse_flags (self, installed = False, removeForced = True): - if installed or not self.is_in_system(): - tree = self._settings.vartree - else: - tree = self._settings.porttree + if not self.is_in_system(): + installed = True - iuse = flags.filter_defaults(self.get_package_settings("IUSE", tree = tree).split()) + iuse = flags.filter_defaults(self.get_package_settings("IUSE", installed = installed).split()) iuse = set(iuse) @@ -184,11 +171,11 @@ class PortagePackage (Package): depstring = "" try: for d in depvar: - depstring += self.get_package_settings(d, tree = self._settings.porttree)+" " + depstring += self.get_package_settings(d, installed = False)+" " except KeyError: # not found in porttree - use vartree depstring = "" for d in depvar: - depstring += self.get_package_settings(d, tree = self._settings.vartree)+" " + depstring += self.get_package_settings(d, installed = True)+" " deps = portage.dep_check(depstring, None, self._settings.settings, myuse = actual, trees = self._trees) @@ -210,7 +197,7 @@ class PortagePackage (Package): depstring = "" for d in depvar: - depstring += self.get_package_settings(d, tree=self._settings.porttree)+" " + depstring += self.get_package_settings(d, installed = False)+" " # let portage do the main stuff ;) # pay attention to any changes here @@ -234,7 +221,7 @@ class PortagePackage (Package): for dep in deps: if dep[0] == '!': # blocking sth - blocked = system.find_installed_packages(dep[1:]) + blocked = system.find_packages(dep, "installed", only_cpv = True) if len(blocked) == 1: # only exact one match allowed to be harmless if blocked[0].get_slot_cp() == self.get_slot_cp(): # blocks in the same slot are harmless continue @@ -290,20 +277,19 @@ class PortagePackage (Package): for line in f: yield line.split()[1].strip() - def get_package_settings(self, var, tree = None): - if not tree: + def get_package_settings(self, var, installed = True): + if installed and self.is_installed(): mytree = self._settings.vartree - if not self.is_installed(): - mytree = self._settings.porttree else: - mytree = tree + mytree = self._settings.porttree + r = mytree.dbapi.aux_get(self._cpv,[var]) return r[0] def get_installed_use_flags(self): if self.is_installed(): - return self.get_package_settings("USE", tree = self._settings.vartree).split() + return self.get_package_settings("USE", installed = True).split() else: return [] def compare_version(self,other): diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py index 51f4857..0d81945 100644 --- a/portato/backend/portage/system.py +++ b/portato/backend/portage/system.py @@ -160,26 +160,16 @@ class PortageSystem (SystemInterface): t = [] if not only_installed: - try: - if masked: - t = self.settings.porttree.dbapi.xmatch("match-all", search_key) - else: - t = self.settings.porttree.dbapi.match(search_key) - except ValueError, e: # ambigous package - if isinstance(e[0], list): - t = [] - for cp in e[0]: - if masked: - t += self.settings.porttree.dbapi.xmatch("match-all", cp) - else: - t += self.settings.porttree.dbapi.match(cp) - else: - raise + pkgSet = "tree" + else: + pkgSet = "installed" + + t = self.find_packages(search_key, pkgSet = pkgSet, masked = masked, with_version = True, only_cpv = True) - if self._version >= (2,1,5): - t += [pkg.get_cpv() for pkg in self.find_installed_packages(search_key) if not (pkg.is_testing(True) or pkg.is_masked())] + if self._version >= (2,1,5): + t += [pkg.get_cpv() for pkg in self.find_packages(search_key, "installed") if not (pkg.is_testing(True) or pkg.is_masked())] else: - t = self.find_installed_packages(search_key, only_cpv=True) + t = self.find_packages(search_key, "installed", only_cpv=True) if t: t = unique_array(t) @@ -187,45 +177,99 @@ class PortageSystem (SystemInterface): return None - def find_packages (self, search_key, masked=False, only_cpv = False): - try: - if masked: - t = self.settings.porttree.dbapi.xmatch("match-all", search_key) - t += self.settings.vartree.dbapi.match(search_key) + def find_packages (self, key = "", pkgSet = "all", masked = False, with_version = True, only_cpv = False): + if key is None: key = "" + + is_regexp = key == "" or ("*" in key and key[0] not in ("*","=","<",">","~","!")) + + def installed(key): + if is_regexp: + if with_version: + t = self.settings.vartree.dbapi.cpv_all() + else: + t = self.settings.vartree.dbapi.cp_all() + + if key: + t = filter(lambda x: re.match(key, x, re.I), t) + + return t + else: + return self.settings.vartree.dbapi.match(key) + + def tree(key): + if is_regexp: + if with_version: + t = self.settings.porttree.dbapi.cpv_all() + else: + t = self.settings.porttree.dbapi.cp_all() + + if key: + t = filter(lambda x: re.match(key, x, re.I), t) + + elif masked: + t = self.settings.porttree.dbapi.xmatch("match-all", key) else: - t = self.settings.porttree.dbapi.match(search_key) - t += self.settings.vartree.dbapi.match(search_key) + t = self.settings.porttree.dbapi.match(key) + + return t + + def all(key): + return unique_array(installed(key)+tree(key)) + + def uninstalled (key): + alist = set(all(key)) + inst = set(installed(key)) + return list(alist - inst) + + def _ws (key, crit, pkglist): + pkgs = self.__find_resolved_unresolved(pkglist, crit, only_cpv = with_version)[0] + if not with_version: + pkgs = [x.get_cp(x) for x in list] + + if is_regexp: + return filter(lambda x: re.match(key, x, re.I), pkgs) + + return pkgs + + def world (key): + with open(portage.WORLD_FILE) as f: + pkglist = f.readlines() + + return _ws(key, lambda cpv: cpv[0] != "#", pkglist) + + def system (key): + return _ws(key, lambda cpv: cpv[0] == "*", self.settings.settings.packages) + + funcmap = { + "all" : all, + "installed" : installed, + "uninstalled" : uninstalled, + "world" : world, + "system" : system, + "tree" : tree + } + + pkgSet = pkgSet.lower() + if pkgSet == "": pkgSet = "all" + + func = funcmap[pkgSet] + + try: + t = func(key) # catch the "ambigous package" Exception except ValueError, e: if isinstance(e[0], list): t = [] for cp in e[0]: - if masked: - t += self.settings.porttree.dbapi.xmatch("match-all", cp) - t += self.settings.vartree.dbapi.match(cp) - else: - t += self.settings.porttree.dbapi.match(cp) - t += self.settings.vartree.dbapi.match(cp) + t += func(cp) else: raise + # Make the list of packages unique t = unique_array(t) t.sort() - return self.geneticize_list(t, only_cpv) - - def find_installed_packages (self, search_key, masked = False, only_cpv = False): - try: - t = self.settings.vartree.dbapi.match(search_key) - # catch the "ambigous package" Exception - except ValueError, e: - if isinstance(e[0], list): - t = [] - for cp in e[0]: - t += self.settings.vartree.dbapi.match(cp) - else: - raise ValueError(e) - return self.geneticize_list(t, only_cpv) + return self.geneticize_list(t, only_cpv or not with_version) def __find_resolved_unresolved (self, list, check, only_cpv = False): """Checks a given list and divides it into a "resolved" and an "unresolved" part. @@ -250,63 +294,6 @@ class PortageSystem (SystemInterface): else: unresolved.append(self.find_best_match(cpv, True, only_cpv = only_cpv)) return (resolved, unresolved) - - def find_system_packages (self, only_cpv = False): - pkglist = self.settings.settings.packages - - return self.__find_resolved_unresolved(pkglist, lambda cpv: cpv[0] == "*", only_cpv) - - def find_world_packages (self, only_cpv = False): - f = open(portage.WORLD_FILE) - pkglist = f.readlines() - f.close() - - return self.__find_resolved_unresolved(pkglist, lambda cpv: cpv[0] != "#", only_cpv) - - def find_all_installed_packages (self, name = None, withVersion=True, only_cpv = False): - if withVersion: - t = self.settings.vartree.dbapi.cpv_all() - if name: - t = filter(self.find_lambda(name),t) - return self.geneticize_list(t, only_cpv) - - else: - t = self.settings.vartree.dbapi.cp_all() - if name: - t = filter(self.find_lambda(name),t) - return t - - def find_all_uninstalled_packages (self, name = None, only_cpv = False): - alist = self.find_all_packages(name) - return self.geneticize_list([x.get_cpv() for x in alist if not x.is_installed()], only_cpv) - - def find_all_packages (self, name = None, withVersion = True, only_cpv = False): - t = self.settings.porttree.dbapi.cp_all() - t += self.settings.vartree.dbapi.cp_all() - if name: - t = filter(self.find_lambda(name),t) - - t = filter(lambda x: not self.unwantedPkgsRE.match(x), unique_array(t)) - - if withVersion: - t2 = [] - for x in t: - t2 += self.settings.porttree.dbapi.cp_list(x) - t2 += self.settings.vartree.dbapi.cp_list(x) - t2 = unique_array(t2) - return self.geneticize_list(t2, only_cpv) - else: - return t - - def find_all_world_packages (self, name = None, only_cpv = False): - world = filter(self.find_lambda(name), self.find_world_packages(only_cpv = True)[0]) - world = unique_array(world) - return self.geneticize_list(world, only_cpv) - - def find_all_system_packages (self, name = None): - sys = filter(self.find_lambda(name), self.find_system_packages(only_cpv = True)[0]) - sys = unique_array(sys) - return self.geneticize_list(sys) def list_categories (self, name = None): categories = self.settings.settings.categories @@ -334,7 +321,7 @@ class PortageSystem (SystemInterface): new_packages = [] for p in packages: - inst = self.find_installed_packages(p) + inst = self.find_packages(p, "installed") best_p = self.find_best_match(p) if best_p is None: @@ -353,16 +340,14 @@ class PortageSystem (SystemInterface): myslots.add(best_p.get_package_settings("SLOT")) # add the slot of the best package in portage for slot in myslots: new_packages.append(\ - self.find_best(\ - [x.get_cpv() for x in self.find_packages("%s:%s" % (i.get_cp(), slot))]\ - )) + self.find_best(self.find_packages("%s:%s" % (i.get_cp(), slot), only_cpv = True))) else: new_packages.append(best_p) return new_packages def get_updated_packages (self): - packages = self.get_new_packages(self.find_all_installed_packages(withVersion = False)) + packages = self.get_new_packages(self.find_packages(pkgSet = "installed", with_version = False)) packages = [x for x in packages if x is not None and not x.is_installed()] return packages @@ -378,7 +363,7 @@ class PortageSystem (SystemInterface): world.close() # append system packages - packages.extend(unique_array([p.get_cp() for p in self.find_all_system_packages()])) + packages.extend(unique_array([p.get_cp() for p in self.find_packages(pkgSet = "system")])) states = [(["RDEPEND", "PDEPEND"], True)] if self.with_bdeps(): @@ -404,11 +389,11 @@ class PortageSystem (SystemInterface): tempDeep = False if not p.is_installed(): - oldList = self.find_installed_packages(p.get_slot_cp()) + oldList = self.find_packages(p.get_slot_cp(), "installed") if oldList: old = oldList[0] # we should only have one package here - else it is a bug else: - oldList = self.sort_package_list(self.find_installed_packages(p.get_cp())) + oldList = self.sort_package_list(self.find_packages(p.get_cp(), "installed")) if not oldList: info(_("Found a not installed dependency: %s.") % p.get_cpv()) oldList = [p] @@ -458,7 +443,7 @@ class PortageSystem (SystemInterface): if not pkg: continue if not pkg.is_installed() and (pkg.is_masked() or pkg.is_testing(True)): # check to not update unnecessairily cont = False - for inst in self.find_installed_packages(pkg.get_cp(), only_cpv = True): + for inst in self.find_packages(pkg.get_cp(), "installed", only_cpv = True): if self.cpv_matches(inst, i): debug("The installed %s matches %s. Discarding upgrade to masked version.", inst, i) cont = True diff --git a/portato/backend/system_interface.py b/portato/backend/system_interface.py index a523af7..4b0f8df 100644 --- a/portato/backend/system_interface.py +++ b/portato/backend/system_interface.py @@ -3,7 +3,7 @@ # File: portato/backend/system_interface.py # This file is part of the Portato-Project, a graphical portage-frontend. # -# Copyright (C) 2007 René 'Necoro' Neumann +# Copyright (C) 2007-2008 René 'Necoro' Neumann # This is free software. You may redistribute copies of it under the terms of # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. @@ -75,31 +75,20 @@ class SystemInterface (object): raise NotImplementedError - def find_packages (self, search_key, masked = False, only_cpv = False): - """This returns a list of packages which have to fit exactly. Additionally ranges like '<,>,=,~,!' et. al. are possible. + def find_packages (self, key, pkgSet = "all", masked = False, with_version = True, only_cpv = False): + """This returns a list of packages matching the key. + As key, it is allowed to use basic regexps (".*") and the normal package specs. But not a combination + of them. - @param search_key: the key to look for - @type search_key: string - @param masked: if True, also look for masked packages - @type masked: boolean - @param only_cpv: do not return package but only the cpv - @type only_cpv: boolean - - @returns: list of found packages - @rtype: backend.Package[] or string[] - """ - - raise NotImplementedError - - - def find_installed_packages (self, search_key, masked = False, only_cpv = False): - """This returns a list of packages which have to fit exactly. Additionally ranges like '<,>,=,~,!' et. al. are possible. - - @param search_key: the key to look for - @type search_key: string + @param key: the key to look for + @type key: string + @param all: the package set to use + @type all: string @param masked: if True, also look for masked packages @type masked: boolean - @param only_cpv: do not return package but only the cpv + @param with_version: if True, return CPVs - else CP + @type with_version: boolean + @param only_cpv: do not return package but only the cpv. if with_version is False, this is ignored @type only_cpv: boolean @returns: list of found packages @@ -108,104 +97,6 @@ class SystemInterface (object): raise NotImplementedError - def find_system_packages (self, only_cpv = False): - """Looks for all packages saved as "system-packages". - - @param only_cpv: do not return package but only the cpv - @type only_cpv: boolean - - @returns: a tuple of (resolved_packages, unresolved_packages). - @rtype: (backend.Package[], backend.Package[]) or (string[], string[]) - """ - - raise NotImplementedError - - def find_world_packages (self, only_cpv = False): - """Looks for all packages saved in the world-file. - - @param only_cpv: do not return package but only the cpv - @type only_cpv: boolean - - @returns: a tuple of (resolved_packages, unresolved_packages). - @rtype: (backend.Package[], backend.Package[]) or (string[], string[]) - """ - - raise NotImplementedError - - def find_all_installed_packages (self, name = None, withVersion = True, only_cpv = False): - """Finds all installed packages matching a name or all if no name is specified. - - @param name: the name to look for - it is expanded to .*name.* ; if None, all packages are returned - @type name: string or None - @param withVersion: if True version-specific packages are returned; else only the cat/package-strings a delivered - @type withVersion: boolean - @param only_cpv: do not return package but only the cpv - @type only_cpv: boolean - - @returns: all packages/cp-strings found - @rtype: backend.Package[] or string[] - """ - - raise NotImplementedError - - def find_all_uninstalled_packages (self, name = None, only_cpv = False): - """Finds all uninstalled packages matching a name or all if no name is specified. - - @param name: the name to look for - it is expanded to .*name.* ; if None, all packages are returned - @type name: string or None - @param only_cpv: do not return package but only the cpv - @type only_cpv: boolean - - @returns: all packages found - @rtype: backend.Package[] or string[] - """ - - raise NotImplementedError - - def find_all_packages (self, name = None, withVersion = True, only_cpv = False): - """Finds all packages matching a name or all if no name is specified. - - @param name: the name to look for - it is expanded to .*name.* ; if None, all packages are returned - @type name: string or None - @param withVersion: if True version-specific packages are returned; else only the cat/package-strings a delivered - @type withVersion: boolean - @param only_cpv: do not return package but only the cpv - @type only_cpv: boolean - - @returns: all packages/cp-strings found - @rtype: backend.Package[] or string[] - """ - - raise NotImplementedError - - def find_all_world_packages (self, name = None, only_cpv = False): - """Finds all world packages matching a name or all if no name is specified. - - @param name: the name to look for - it is expanded to .*name.* ; if None, all packages are returned - @type name: string or None - @param only_cpv: do not return package but only the cpv - @type only_cpv: boolean - - @returns: all packages found - @rtype: backend.Package[] or string[] - """ - - raise NotImplementedError - - def find_all_system_packages (self, name = None, only_cpv = False): - """Finds all system packages matching a name or all if no name is specified. - - @param name: the name to look for - it is expanded to .*name.* ; if None, all packages are returned - @type name: string or None - @param only_cpv: do not return package but only the cpv - @type only_cpv: boolean - - @returns: all packages found - @rtype: backend.Package[] or string[] - """ - - raise NotImplementedError - def list_categories (self, name = None): """Finds all categories matching a name or all if no name is specified. |