summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/sets/__init__.py78
-rw-r--r--pym/portage/sets/dbapi.py14
-rw-r--r--pym/portage/sets/files.py6
-rw-r--r--pym/portage/sets/profiles.py2
-rw-r--r--pym/portage/sets/security.py12
-rw-r--r--pym/portage/sets/shell.py2
6 files changed, 70 insertions, 44 deletions
diff --git a/pym/portage/sets/__init__.py b/pym/portage/sets/__init__.py
index e0be0047c..4e1e68e4d 100644
--- a/pym/portage/sets/__init__.py
+++ b/pym/portage/sets/__init__.py
@@ -6,18 +6,22 @@ import os
from portage.const import PRIVATE_PATH, USER_CONFIG_PATH
from portage.exception import InvalidAtom
-from portage.dep import isvalidatom
+from portage.dep import isvalidatom, match_from_list, dep_getkey
OPERATIONS = ["merge", "unmerge", "edit"]
DEFAULT_SETS = ["world", "system", "everything", "security"] \
+["package_"+x for x in ["mask", "unmask", "use", "keywords"]]
class PackageSet(object):
+ # That this to operations that are supported by this set class. While
+ # technically there is no difference between "merge" and "unmerge" regarding
+ # package sets, the latter doesn't make sense for some sets like "system"
+ # or "security" and therefore isn't supported by them.
_operations = ["merge"]
def __init__(self, name):
self._name = name
- self._nodes = []
+ self._atoms = []
self._loaded = False
def supportsOperation(self, op):
@@ -25,48 +29,66 @@ class PackageSet(object):
raise ValueError(op)
return op in self._operations
- def getNodes(self):
+ def getAtoms(self):
if not self._loaded:
self.load()
self._loaded = True
- return self._nodes
-
- def _setNodes(self, nodes):
- nodes = map(str.strip, nodes)
- for n in nodes[:]:
- if n == "":
- nodes.remove(n)
- elif not isvalidatom(n):
- raise InvalidAtom(n)
- self._nodes = nodes
+ return self._atoms
+
+ def _setAtoms(self, atoms):
+ atoms = map(str.strip, atoms)
+ for a in atoms[:]:
+ if a == "":
+ atoms.remove(a)
+ elif not isvalidatom(a):
+ raise InvalidAtom(a)
+ self._atoms = atoms
def getName(self):
return self._name
- def addNode(self, node):
+ def addAtom(self, atom):
if self.supportsOperation("edit"):
self.load()
- self._nodes.append(node)
+ self._atoms.append(atom)
self.write()
else:
raise NotImplementedError()
- def removeNode(self, node):
+ def removeAtom(self, atom):
if self.supportsOperation("edit"):
self.load()
- self._nodes.remove(node)
+ self._atoms.remove(atom)
self.write()
else:
raise NotImplementedError()
+ def removePackageAtoms(self, cp):
+ for a in self.getAtoms():
+ if dep_getkey(a) == cp:
+ self.removeAtom(a)
+
def write(self):
+ # This method must be overwritten in subclasses that should be editable
raise NotImplementedError()
def load(self):
+ # This method must be overwritten by subclasses
raise NotImplementedError()
-class EmptyPackageSet(PackageSet):
- _operations = ["merge", "unmerge"]
+ def containsCPV(self, cpv):
+ for a in self.getAtoms():
+ if match_from_list(a, cpv):
+ return True
+ return False
+
+
+class InternalPackageSet(PackageSet):
+ _operations = ["merge", "unmerge", "edit"]
+
+ def load(self):
+ pass
+
def make_default_sets(configroot, root, profile_paths, settings=None,
vdbapi=None, portdbapi=None):
@@ -85,11 +107,11 @@ def make_default_sets(configroot, root, profile_paths, settings=None,
if settings != None and portdbapi != None:
rValue.add(AffectedSet("security", settings, vdbapi, portdbapi))
else:
- rValue.add(EmptyPackageSet("security"))
+ rValue.add(InternalPackageSet("security"))
if vdbapi != None:
rValue.add(EverythingSet("everything", vdbapi))
else:
- rValue.add(EmptyPackageSet("everything"))
+ rValue.add(InternalPackageSet("everything"))
return rValue
@@ -108,13 +130,23 @@ def make_extra_static_sets(configroot):
rValue.add(StaticFileSet(fname, os.path.join(mydir, myname)))
return rValue
+def make_category_sets(portdbapi, settings, only_visible=True):
+ from portage.sets.dbapi import CategorySet
+ rValue = set()
+ for c in settings.categories:
+ rValue.add(CategorySet("category_%s" % c, c, portdbapi, only_visible=only_visible))
+ return rValue
+
# adhoc test code
if __name__ == "__main__":
- import portage
+ import portage, sys
l = make_default_sets("/", "/", portage.settings.profiles, portage.settings, portage.db["/"]["vartree"].dbapi, portage.db["/"]["porttree"].dbapi)
l.update(make_extra_static_sets("/"))
+ l2 = make_category_sets(portage.db["/"]["porttree"].dbapi, portage.settings)
+ if len(sys.argv) > 1:
+ l = [s for s in l.union(l2) if s.getName() in sys.argv[1:]]
for x in l:
print x.getName()+":"
- for n in sorted(x.getNodes()):
+ for n in sorted(x.getAtoms()):
print "- "+n
print
diff --git a/pym/portage/sets/dbapi.py b/pym/portage/sets/dbapi.py
index dcc0552ef..a1b064b57 100644
--- a/pym/portage/sets/dbapi.py
+++ b/pym/portage/sets/dbapi.py
@@ -14,15 +14,15 @@ class EverythingSet(PackageSet):
self._db = vdbapi
def load(self):
- mynodes = []
+ myatoms = []
for cp in self._db.cp_all():
if len(self._db.cp_list(cp)) > 1:
for cpv in self._db.cp_list(cp):
myslot = self._db.aux_get(cpv, ["SLOT"])[0]
- mynodes.append(cp+":"+myslot)
+ myatoms.append(cp+":"+myslot)
else:
- mynodes.append(cp)
- self._setNodes(mynodes)
+ myatoms.append(cp)
+ self._setAtoms(myatoms)
class CategorySet(PackageSet):
_operations = ["merge", "unmerge"]
@@ -34,10 +34,10 @@ class CategorySet(PackageSet):
self._check = only_visible
def load(self):
- mynodes = []
+ myatoms = []
for cp in self._db.cp_all():
if catsplit(cp)[0] == self._category:
if (not self._check) or len(self._db.match(cp)) > 0:
- mynodes.append(cp)
- self._setNodes(mynodes)
+ myatoms.append(cp)
+ self._setAtoms(myatoms)
diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py
index 8e1bca99c..6fc9f0426 100644
--- a/pym/portage/sets/files.py
+++ b/pym/portage/sets/files.py
@@ -14,10 +14,10 @@ class StaticFileSet(PackageSet):
self._filename = filename
def write(self):
- write_atomic(self._filename, "\n".join(self._nodes)+"\n")
+ write_atomic(self._filename, "\n".join(self._atoms)+"\n")
def load(self):
- self._setNodes(grabfile_package(self._filename, recursive=True))
+ self._setAtoms(grabfile_package(self._filename, recursive=True))
class ConfigFileSet(StaticFileSet):
_operations = ["merge", "unmerge"]
@@ -26,5 +26,5 @@ class ConfigFileSet(StaticFileSet):
raise NotImplementedError()
def load(self):
- self._setNodes(grabdict_package(self._filename, recursive=True).keys())
+ self._setAtoms(grabdict_package(self._filename, recursive=True).keys())
diff --git a/pym/portage/sets/profiles.py b/pym/portage/sets/profiles.py
index fe7ab201a..14394598e 100644
--- a/pym/portage/sets/profiles.py
+++ b/pym/portage/sets/profiles.py
@@ -17,4 +17,4 @@ class PackagesSystemSet(PackageSet):
def load(self):
mylist = [grabfile_package(os.path.join(x, "packages")) for x in self._profile_paths]
mylist = stack_lists(mylist, incremental=1)
- self._setNodes([x[1:] for x in mylist if x[0] == "*"])
+ self._setAtoms([x[1:] for x in mylist if x[0] == "*"])
diff --git a/pym/portage/sets/security.py b/pym/portage/sets/security.py
index d7db89d95..4827886a8 100644
--- a/pym/portage/sets/security.py
+++ b/pym/portage/sets/security.py
@@ -15,21 +15,15 @@ class SecuritySet(PackageSet):
self._vardbapi = vardbapi
self._portdbapi = portdbapi
- def loadCheckfile(self):
- self._appliedlist = grabfile(os.path.join(os.sep, self._settings["ROOT"], CACHE_PATH, "glsa"))
-
def load(self):
glsaindexlist = glsa.get_glsa_list(self._settings)
- nodelist = []
+ atomlist = []
for glsaid in glsaindexlist:
myglsa = glsa.Glsa(glsaid, self._settings, self._vardbapi, self._portdbapi)
#print glsaid, myglsa.isVulnerable(), myglsa.isApplied(), myglsa.getMergeList()
if self.useGlsa(myglsa):
- nodelist += myglsa.getMergeList(least_change=False)
- self._setNodes(nodelist)
-
- def useGlsaId(self, glsaid):
- return True
+ atomlist += myglsa.getMergeList(least_change=False)
+ self._setAtoms(atomlist)
def useGlsa(self, myglsa):
return True
diff --git a/pym/portage/sets/shell.py b/pym/portage/sets/shell.py
index 8874743c9..baef6dee0 100644
--- a/pym/portage/sets/shell.py
+++ b/pym/portage/sets/shell.py
@@ -17,5 +17,5 @@ class CommandOutputSet(PackageSet):
pipe = subprocess.Popen(self._command, stdout=subprocess.PIPE, shell=True)
if pipe.wait() == os.EX_OK:
text = pipe.stdout.read()
- self._setNodes(text.split("\n"))
+ self._setAtoms(text.split("\n"))