s/node/atom/ and other minor updates
authorMarius Mauch <genone@gentoo.org>
Mon, 16 Jul 2007 06:39:27 +0000 (06:39 -0000)
committerMarius Mauch <genone@gentoo.org>
Mon, 16 Jul 2007 06:39:27 +0000 (06:39 -0000)
svn path=/main/trunk/; revision=7271

pym/portage/sets/__init__.py
pym/portage/sets/dbapi.py
pym/portage/sets/files.py
pym/portage/sets/profiles.py
pym/portage/sets/security.py
pym/portage/sets/shell.py

index e0be0047c975722ef4ae5a7e02bc0ab790efdfb8..4e1e68e4d96c5ad1d68884e0fea7db8f5cdfa857 100644 (file)
@@ -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
index dcc0552ef893a2da8cd2f0289d0988d082e5104f..a1b064b574893591f4ede1ef1494bcd6087e2868 100644 (file)
@@ -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)
        
index 8e1bca99cacf8783d3dd5785159b8792ddaaf44e..6fc9f042696b544f4f576ad3d82e8ca9aa0b2364 100644 (file)
@@ -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())
 
index fe7ab201a89a00912067be08c133bb9f2ba8ccb9..14394598e830cf857a3c29e0d902c1d6d092f081 100644 (file)
@@ -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] == "*"])
index d7db89d9584f688a6b561589bf5d102c0cc19473..4827886a86f49b822c0004397e2572f9e0150b50 100644 (file)
@@ -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
index 8874743c9855411bb6393ec2945bbc88fe8e974a..baef6dee01c6ec2042223a0e2b985b5911622a3f 100644 (file)
@@ -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"))