diff options
Diffstat (limited to '')
-rw-r--r-- | portato/backend/portage/system.py | 78 | ||||
-rw-r--r-- | portato/backend/system_interface.py | 2 | ||||
-rw-r--r-- | portato/helper.py | 2 |
3 files changed, 29 insertions, 53 deletions
diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py index 58f687e..229bcc9 100644 --- a/portato/backend/portage/system.py +++ b/portato/backend/portage/system.py @@ -14,6 +14,11 @@ from __future__ import absolute_import, with_statement import re, os, os.path import portage +try: + import portage.dep as portage_dep +except ImportError: + import portage_dep + from collections import defaultdict from . import VERSION @@ -226,24 +231,30 @@ class PortageSystem (SystemInterface): 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() + for cp in f: + cp = cp.strip() + if cp and cp[0] != "#": + if is_regexp: + if not re.match(key, cp, re.I): continue - return _ws(key, lambda cpv: cpv[0] != "#", pkglist) + if not with_version: + yield portage_dep.dep_getkey(cp) + + yield self.find_best_match(cp, only_cpv = True) def system (key): - return _ws(key, lambda cpv: cpv[0] == "*", self.settings.settings.packages) + for cp in self.settings.settings.packages: + if cp[0] != "*": continue + + if is_regexp: + if not re.match(key, cp, re.I): continue + + if not with_version: + yield portage_dep.dep_getkey(cp) + + yield self.find_best_match(cp, only_cpv = True) funcmap = { "all" : all, @@ -272,34 +283,9 @@ class PortageSystem (SystemInterface): # Make the list of packages unique t = unique_array(t) - t.sort() 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. - - @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[]) or (string[], string[])""" - resolved = [] - unresolved = [] - for x in list: - cpv = x.strip() - if cpv and check(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, only_cpv = only_cpv)) - return (resolved, unresolved) - def list_categories (self, name = None): categories = self.settings.settings.categories return filter(self.find_lambda(name), categories) @@ -357,19 +343,9 @@ class PortageSystem (SystemInterface): return packages def update_world (self, newuse = False, deep = False): - # read world file - world = open(portage.WORLD_FILE) - packages = [] - for line in world: - line = line.strip() - if len(line) == 0: continue # empty line - if line[0] == "#": continue # comment - packages.append(line) - world.close() - - # append system packages - packages.extend(unique_array([p.get_cp() for p in self.find_packages(pkgSet = "system")])) - + packages = self.find_packages(pkgSet="world", with_version = False) + packages.extend(self.find_packages(pkgSet = "system", with_version = False)) + states = [(["RDEPEND", "PDEPEND"], True)] if self.with_bdeps(): states.append((["DEPEND"], True)) diff --git a/portato/backend/system_interface.py b/portato/backend/system_interface.py index 16f0a9c..c118f6d 100644 --- a/portato/backend/system_interface.py +++ b/portato/backend/system_interface.py @@ -23,7 +23,7 @@ class SystemInterface (object): """Returns all supported sets in tuples consisting of name and description. If sets aren't supported, at least "world" and "system" have to be returned. - @rtype: (string, string)[] + @rtype: iter(string, string) """ raise NotImplementedError diff --git a/portato/helper.py b/portato/helper.py index 31e25d9..145716e 100644 --- a/portato/helper.py +++ b/portato/helper.py @@ -110,7 +110,6 @@ def unique_array(s): """Stolen from portage_utils: lifted from python cookbook, credit: Tim Peters Return a list of the elements in s in arbitrary order, sans duplicates""" - n = len(s) # assume all elements are hashable, if so, it's linear try: return list(set(s)) @@ -124,6 +123,7 @@ def unique_array(s): except TypeError: pass else: + n = len(s) assert n > 0 last = t[0] lasti = i = 1 |