summaryrefslogtreecommitdiff
path: root/portato/backend
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--portato/backend/portage/sets.py111
-rw-r--r--portato/backend/portage/system.py9
2 files changed, 64 insertions, 56 deletions
diff --git a/portato/backend/portage/sets.py b/portato/backend/portage/sets.py
index c1971b7..6c483c9 100644
--- a/portato/backend/portage/sets.py
+++ b/portato/backend/portage/sets.py
@@ -43,68 +43,34 @@ class Set(object):
return t
-class FilterSet (Set):
+class InstalledSet (Set):
+ """For the moment do not use the portage-2.2 @installed set.
+ It only contains the current slot-cps - and to get the cpvs
+ via the PortageSet results in an infinite recursion :(."""
- def get_list(self):
- raise NotImplementedError
-
- def get_pkgs (self, key, is_regexp, masked, with_version, only_cpv):
- t = set()
- for pkg in self.get_list():
- if is_regexp and key:
- if not re.search(key, pkg, re.I): continue
+ def _get_regexp (self, key, with_version):
+ if with_version:
+ t = system.settings.vartree.dbapi.cpv_all()
+ else:
+ t = system.settings.vartree.dbapi.cp_all()
- if not with_version:
- t.add(portage.dep.dep_getkey(pkg))
- else:
- t.add(system.find_best_match(pkg, only_cpv = True))
+ if key:
+ t = filter(lambda x: re.search(key, x, re.I), t)
return t
-class PortageSet (FilterSet):
- def __init__ (self, name):
- debug("Loading portage set '%s'", name)
- self.name = name
-
- def get_list(self):
- return itt.imap(str, system.settings.setsconfig.getSetAtoms(self.name))
-
-class SystemSet (FilterSet):
-
- def get_list(self):
- for cp in system.settings.global_settings.packages:
- if cp[0] == "*": yield cp[1:]
-
-class WorldSet (FilterSet):
-
- def get_list(self):
- with open(portage.WORLD_FILE) as f:
- for cp in f:
- cp = cp.strip()
- if cp and cp[0] != "#":
- yield cp
+ def _get_by_key (self, key, with_version):
+ t = system.settings.vartree.dbapi.match(key)
+ if not with_version:
+ t = itt.imap(portage.cpv_getkey, t)
-class InstalledSet (Set):
- """For the moment do not use the portage-2.2 @installed set.
- It only contains the current slot-cps - and to get the cpvs
- via the PortageSet results in an infinite recursion :(."""
+ return t
def get_pkgs (self, key, is_regexp, masked, with_version, only_cpv):
if is_regexp:
- if with_version:
- t = system.settings.vartree.dbapi.cpv_all()
- else:
- t = system.settings.vartree.dbapi.cp_all()
-
- if key:
- t = filter(lambda x: re.search(key, x, re.I), t)
-
+ return set(self._get_regexp(key, with_version))
else:
- t = system.settings.vartree.dbapi.match(key)
- if not with_version:
- t = itt.imap(portage.cpv_getkey, t)
-
- return set(t)
+ return set(self._get_by_key(key, with_version))
class TreeSet (Set):
@@ -150,3 +116,44 @@ class UninstalledSet (Set):
def find (self, *args, **kwargs):
return self.all.find(*args, **kwargs) - self.installed.find(*args, **kwargs)
+class FilterSet (InstalledSet):
+
+ def get_list(self):
+ raise NotImplementedError
+
+ def get_pkgs (self, key, is_regexp, masked, with_version, only_cpv):
+ t = set()
+ for pkg in self.get_list():
+ if is_regexp and key:
+ if not re.search(key, pkg, re.I): continue
+
+ if not with_version:
+ t.add(portage.dep.dep_getkey(pkg))
+ else:
+ t.update(self._get_by_key(pkg, with_version))
+
+ return t
+
+class PortageSet (FilterSet):
+ def __init__ (self, name):
+ debug("Loading portage set '%s'", name)
+ self.name = name
+
+ def get_list(self):
+ return itt.imap(str, system.settings.setsconfig.getSetAtoms(self.name))
+
+class SystemSet (FilterSet):
+
+ def get_list(self):
+ for cp in system.settings.global_settings.packages:
+ if cp[0] == "*": yield cp[1:]
+
+class WorldSet (FilterSet):
+
+ def get_list(self):
+ with open(portage.WORLD_FILE) as f:
+ for cp in f:
+ cp = cp.strip()
+ if cp and cp[0] != "#":
+ yield cp
+
diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py
index 3aaa060..990a39a 100644
--- a/portato/backend/portage/system.py
+++ b/portato/backend/portage/system.py
@@ -209,10 +209,11 @@ class PortageSystem (SystemInterface):
t = self.find_packages(search_key, pkgSet = pkgSet, masked = masked, with_version = True, only_cpv = True)
- if VERSION >= (2,1,5):
- t += [pkg.get_cpv() for pkg in self.find_packages(search_key, self.SET_INSTALLED) if not (pkg.is_testing(True) or pkg.is_masked())]
- elif not only_installed: # no need to run twice
- t += self.find_packages(search_key, self.SET_INSTALLED, only_cpv=True)
+ if not only_installed:
+ if VERSION >= (2,1,5):
+ t += [pkg.get_cpv() for pkg in self.find_packages(search_key, self.SET_INSTALLED) if not (pkg.is_testing(True) or pkg.is_masked())]
+ else: # no need to run twice
+ t += self.find_packages(search_key, self.SET_INSTALLED, only_cpv=True)
if t:
t = list(set(t))