diff options
-rw-r--r-- | doc/Changelog | 1 | ||||
-rw-r--r-- | doc/TODO | 1 | ||||
-rw-r--r-- | portato/backend/portage/system.py | 90 | ||||
-rw-r--r-- | portato/backend/system_interface.py | 143 |
4 files changed, 157 insertions, 78 deletions
diff --git a/doc/Changelog b/doc/Changelog index 56ef968..54815e0 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ next: - "porting" to python-2.5 - adding support for the "--with-bdeps=y" option in EMERGE_DEFAULT_OPTS +- fix update world 0.8.5: - added an uncaught exception dialog @@ -19,7 +19,6 @@ Backend: - make sure, a package being removed from the queue is not needed as a dependency by another package - "nach hause telefonieren" :) -- downgrades do not work in update world GUI: ==== diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py index 8d8e6da..5916a9f 100644 --- a/portato/backend/portage/system.py +++ b/portato/backend/portage/system.py @@ -113,7 +113,8 @@ class PortageSystem (SystemInterface): @returns: 1. None if no name is given 2. a lambda function - @rtype: function""" + @rtype: function + """ if name != None: if isinstance(name, str): @@ -123,35 +124,52 @@ class PortageSystem (SystemInterface): else: return lambda x: True - def geneticize_list (self, list_of_packages): + def geneticize_list (self, list_of_packages, only_cpv = False): """Convertes a list of cpv's into L{backend.Package}s. @param list_of_packages: the list of packages - @type list_of_packages: list of gentoolkit.Packages + @type list_of_packages: string[] + @param only_cpv: do nothing - return the passed list + @type only_cpv: boolean @returns: converted list - @rtype: PortagePackage[]""" + @rtype: PortagePackage[] + """ - return [PortagePackage(x) for x in list_of_packages] + if not only_cpv: + return [PortagePackage(x) for x in list_of_packages] + else: + return list_of_packages def get_global_settings (self, key): return self.settings.settings[key] - def find_best (self, list): - return PortagePackage(portage.best(list)) + def find_best (self, list, only_cpv = False): + if only_cpv: + return portage.best(list) + else: + return PortagePackage(portage.best(list)) - def find_best_match (self, search_key, only_installed = False): + def find_best_match (self, search_key, only_installed = False, only_cpv = False): t = None if not only_installed: - t = self.find_packages(search_key) + try: + t = self.settings.porttree.dbapi.match(search_key) + except ValueError, e: # ambigous package + if isinstance(e[0], list): + t = [] + for cp in e[0]: + t += self.settings.porttree.dbapi.match(cp) + else: + raise else: - t = self.find_installed_packages(search_key) + t = self.find_installed_packages(search_key, only_cpv = True) if t: - return self.find_best([x.get_cpv() for x in t]) + return self.find_best(t, only_cpv) return None - def find_packages (self, search_key, masked=False): + def find_packages (self, search_key, masked=False, only_cpv = False): try: if masked: t = self.settings.porttree.dbapi.xmatch("match-all", search_key) @@ -171,13 +189,13 @@ class PortageSystem (SystemInterface): t += self.settings.porttree.dbapi.match(cp) t += self.settings.vartree.dbapi.match(cp) else: - raise ValueError(e) + raise # Make the list of packages unique t = unique_array(t) t.sort() - return self.geneticize_list(t) + return self.geneticize_list(t, only_cpv) - def find_installed_packages (self, search_key, masked = False): + 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 @@ -189,48 +207,50 @@ class PortageSystem (SystemInterface): else: raise ValueError(e) - return self.geneticize_list(t) + return self.geneticize_list(t, only_cpv) - def __find_resolved_unresolved (self, list, check): + def __find_resolved_unresolved (self, list, check, only_cpv = False): """Checks a given list and divides it into a "resolved" and an "unresolved" part. @param list: list of cpv's @type list: string[] @param check: function called to check whether an entry is ok @type check: function(cpv) + @param only_cpv: do not return packages but cpv-strings + @type only_cpv: boolean @returns: the divided list: (resolved, unresolved) - @rtype: (Package[], Package[])""" + @rtype: (Package[], Package[]) or (string[], string[])""" resolved = [] unresolved = [] for x in list: cpv = x.strip() if len(cpv) and check(cpv): - pkg = self.find_best_match(cpv) + pkg = self.find_best_match(cpv, only_cpv = only_cpv) if pkg: resolved.append(pkg) else: - unresolved.append(self.find_best_match(cpv, True)) + unresolved.append(self.find_best_match(cpv, True, only_cpv = only_cpv)) return (resolved, unresolved) - def find_system_packages (self): + def find_system_packages (self, only_cpv = False): pkglist = self.settings.settings.packages - return self.__find_resolved_unresolved(pkglist, lambda cpv: cpv[0] == "*") + return self.__find_resolved_unresolved(pkglist, lambda cpv: cpv[0] == "*", only_cpv) - def find_world_packages (self): + 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] != "#") + return self.__find_resolved_unresolved(pkglist, lambda cpv: cpv[0] != "#", only_cpv) - def find_all_installed_packages (self, name = None, withVersion=True): + 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) + return self.geneticize_list(t, only_cpv) else: t = self.settings.vartree.dbapi.cp_all() @@ -238,11 +258,11 @@ class PortageSystem (SystemInterface): t = filter(self.find_lambda(name),t) return t - def find_all_uninstalled_packages (self, name = None): + def find_all_uninstalled_packages (self, name = None, only_cpv = False): alist = self.find_all_packages(name) - return self.geneticize_list([x for x in alist if not x.is_installed()]) + 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): + 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: @@ -250,23 +270,23 @@ class PortageSystem (SystemInterface): t = filter(lambda x: not self.unwantedPkgsRE.match(x), unique_array(t)) - if (withVersion): + 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) + return self.geneticize_list(t2, only_cpv) else: return t - def find_all_world_packages (self, name = None): - world = filter(self.find_lambda(name), (x.get_cpv() for x in self.find_world_packages()[0])) + 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) + return self.geneticize_list(world, only_cpv) def find_all_system_packages (self, name = None): - sys = filter(self.find_lambda(name), (x.get_cpv() for x in self.find_system_packages()[0])) + sys = filter(self.find_lambda(name), self.find_system_packages(only_cpv = True)[0]) sys = unique_array(sys) return self.geneticize_list(sys) diff --git a/portato/backend/system_interface.py b/portato/backend/system_interface.py index 4e9618b..c0f4e68 100644 --- a/portato/backend/system_interface.py +++ b/portato/backend/system_interface.py @@ -18,7 +18,8 @@ class SystemInterface (object): @param cpv: the cpv to split @type cpv: string @returns: the splitted cpv - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -30,129 +31,169 @@ class SystemInterface (object): @param criterion: criterion to check against @type criterion: string @returns: match result - @rtype: boolean""" + @rtype: boolean + """ raise NotImplementedError - def find_best(self, list): + def find_best(self, list, only_cpv = False): """Returns the best package out of a list of packages. @param list: the list of packages to select from @type list: string[] + @param only_cpv: do not return package but only the cpv + @type only_cpv: boolean + @returns: the best package - @rtype: backend.Package""" + @rtype: backend.Package or string + """ raise NotImplementedError - def find_best_match (self, search_key, only_installed = False): + def find_best_match (self, search_key, only_installed = False, only_cpv = False): """Finds the best match in the portage tree. It does not find masked packages! @param search_key: the key to find in the portage tree @type search_key: string @param only_installed: if True, only installed packages are searched @type only_installed: boolean + @param only_cpv: do not return package but only the cpv + @type only_cpv: boolean @returns: the package found or None - @rtype: backend.Package""" + @rtype: backend.Package or string + """ raise NotImplementedError - def find_packages (self, search_key, masked=False): + 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. @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[]""" + @rtype: backend.Package[] or string[] + """ raise NotImplementedError - def find_installed_packages (self, search_key, masked = False): + 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 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[]""" + @rtype: backend.Package[] or string[] + """ raise NotImplementedError - def find_system_packages (self): + 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[])""" + @rtype: (backend.Package[], backend.Package[]) or (string[], string[]) + """ raise NotImplementedError - def find_world_packages (self): + 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[])""" + @rtype: (backend.Package[], backend.Package[]) or (string[], string[]) + """ raise NotImplementedError - def find_all_installed_packages (self, name = None, withVersion = True): + 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 cp-string[]""" + @rtype: backend.Package[] or string[] + """ raise NotImplementedError - def find_all_uninstalled_packages (self, name = None): + 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[]""" + @rtype: backend.Package[] or string[] + """ raise NotImplementedError - def find_all_packages (self, name = None, withVersion = True): + 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 cp-string[]""" + @rtype: backend.Package[] or string[] + """ raise NotImplementedError - def find_all_world_packages (self, name = None): + 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[]""" + @rtype: backend.Package[] or string[] + """ raise NotImplementedError - def find_all_system_packages (self, name = None): + 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[]""" + @rtype: backend.Package[] or string[] + """ raise NotImplementedError @@ -162,7 +203,8 @@ class SystemInterface (object): @param name: the name to look for - it is expanded to .*name.* ; if None, all categories are returned @type name: string or None @returns: all categories found - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -170,7 +212,8 @@ class SystemInterface (object): """Sorts a package list in the same manner portage does. @param pkglist: list to sort - @type pkglist: Packages[]""" + @type pkglist: Packages[] + """ raise NotImplementedError @@ -187,7 +230,8 @@ class SystemInterface (object): @param deep: Not only check world packages but also there dependencies. @type deep: boolean @returns: a list of the tuple (new_package, old_package) - @rtype: (backend.Package, backend.Package)[]""" + @rtype: (backend.Package, backend.Package)[] + """ raise NotImplementedError @@ -196,7 +240,8 @@ class SystemInterface (object): This differs from update_world as it takes all installed packages into account but ignores changed useflags. @returns: the list of new packages - @rtype: backend.Package[]""" + @rtype: backend.Package[] + """ raise NotImplementedError @@ -209,7 +254,8 @@ class SystemInterface (object): @param package: name of a package: if given local use descriptions are searched too @type package: cp-string @returns: found description - @rtype: string""" + @rtype: string + """ raise NotImplementedError @@ -219,7 +265,8 @@ class SystemInterface (object): @param key: the setting to return @type key: string @returns: the value of this setting - @rtype: string""" + @rtype: string + """ raise NotImplementedError @@ -229,7 +276,8 @@ class SystemInterface (object): @param cpv: the cpv to create the package from @type cpv: string @returns: a new Package-object. - @rtype: Package""" + @rtype: Package + """ raise NotImplementedError @@ -237,7 +285,8 @@ class SystemInterface (object): """Returns the actual path to the config files. @returns: the path, e.g. /etc/portage - @rtype: string""" + @rtype: string + """ raise NotImplementedError @@ -245,7 +294,8 @@ class SystemInterface (object): """Returns the path to the world file. @returns: the path of the world file - @rtype: string""" + @rtype: string + """ raise NotImplementedError @@ -253,7 +303,8 @@ class SystemInterface (object): """Returns the command(s) to run for syncing. This can be overridden by the user. @returns: command to run - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -261,7 +312,8 @@ class SystemInterface (object): """Returns the command(s) to run for the merging. @returns: command to run - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -269,7 +321,8 @@ class SystemInterface (object): """Returns the options to append for marking a merge as "oneshot". @returns: option(s) to append - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -277,7 +330,8 @@ class SystemInterface (object): """Returns the options to append for marking a merge as "newuse". @returns: option(s) to append - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -285,7 +339,8 @@ class SystemInterface (object): """Returns the options to append for marking a merge as "deep". @returns: option(s) to append - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -293,7 +348,8 @@ class SystemInterface (object): """Returns the options to append for marking a merge as "update". @returns: option(s) to append - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -301,7 +357,8 @@ class SystemInterface (object): """Returns the options to append for marking a merge as "pretend". @returns: option(s) to append - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -309,7 +366,8 @@ class SystemInterface (object): """Returns the options to append for marking a merge as "unmerge". @returns: option(s) to append - @rtype: string[]""" + @rtype: string[] + """ raise NotImplementedError @@ -317,6 +375,7 @@ class SystemInterface (object): """Returns a dictionary of environment variables to set prior to do an emerge. @returns: environment variables - @rtype: dict{string : string}""" + @rtype: dict{string : string} + """ raise NotImplementedError |