add support for metadata
authorMarius Mauch <genone@gentoo.org>
Mon, 16 Jul 2007 09:01:49 +0000 (09:01 -0000)
committerMarius Mauch <genone@gentoo.org>
Mon, 16 Jul 2007 09:01:49 +0000 (09:01 -0000)
svn path=/main/trunk/; revision=7276

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 ceebab5a219adef4fc7ce87dda775f9553a9beff..72e8b20916730f48d30a4a572152fdc01d311aab 100644 (file)
@@ -18,7 +18,8 @@ class PackageSet(object):
        # package sets, the latter doesn't make sense for some sets like "system"
        # or "security" and therefore isn't supported by them.
        _operations = ["merge"]
-
+       description = "generic package set"
+       
        def __init__(self, name):
                self._name = name
                self._atoms = set()
@@ -59,6 +60,12 @@ class PackageSet(object):
                                return True
                return False
        
+       def getMetadata(self, key):
+               if hasattr(self, key.lower()):
+                       return getattr(self, key.lower())
+               else:
+                       return ""
+       
 
 class EditablePackageSet(PackageSet):
        def getAtoms(self):
@@ -107,7 +114,9 @@ def make_default_sets(configroot, root, profile_paths, settings=None,
        from portage.sets.dbapi import EverythingSet
        
        rValue = set()
-       rValue.add(StaticFileSet("world", os.path.join(root, PRIVATE_PATH, "world")))
+       worldset = StaticFileSet("world", os.path.join(root, PRIVATE_PATH, "world"))
+       worldset.description = "Set of packages that were directly installed"
+       rValue.add(worldset)
        for suffix in ["mask", "unmask", "keywords", "use"]:
                myname = "package_"+suffix
                myset = ConfigFileSet(myname, os.path.join(configroot, USER_CONFIG_PATH.lstrip(os.sep), "package."+suffix))
@@ -156,6 +165,7 @@ if __name__ == "__main__":
                l = [s for s in l.union(l2) if s.getName() in sys.argv[1:]]
        for x in l:
                print x.getName()+":"
+               print "DESCRIPTION = %s" % x.getMetadata("Description")
                for n in sorted(x.getAtoms()):
                        print "- "+n
                print
index a1b064b574893591f4ede1ef1494bcd6087e2868..1b2520ef6049146fa1defbc9f097978c8fa06eae 100644 (file)
@@ -8,7 +8,8 @@ from portage.sets import PackageSet
 
 class EverythingSet(PackageSet):
        _operations = ["merge", "unmerge"]
-
+       description = "Package set containing all installed packages"
+       
        def __init__(self, name, vdbapi):
                super(EverythingSet, self).__init__(name)
                self._db = vdbapi
@@ -32,6 +33,11 @@ class CategorySet(PackageSet):
                self._db = portdbapi
                self._category = category
                self._check = only_visible
+               if only_visible:
+                       s="visible"
+               else:
+                       s="all"
+               self.description = "Package set containing %s packages of category %s" % (s, self._category)
                        
        def load(self):
                myatoms = []
index d79571c57db00d758adbc95c9962587f79e2b585..921d04b8c432ac751359e91b1394733957ed6c81 100644 (file)
@@ -2,7 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Id$
 
-from portage.util import grabfile_package, grabdict_package, write_atomic
+from portage.util import grabfile, grabfile_package, grabdict_package, write_atomic
 import os
 
 from portage.sets import PackageSet, EditablePackageSet
@@ -14,6 +14,20 @@ class StaticFileSet(EditablePackageSet):
                super(StaticFileSet, self).__init__(name)
                self._filename = filename
                self._mtime = None
+               self.description = "Package set loaded from file %s" % self._filename
+               metadata = grabfile(self._filename + ".metadata")
+               key = None
+               for line in metadata:
+                       if len(line) == 0 and key != None:
+                               setattr(self, key, " ".join(value))
+                               key = None
+                       elif line[-1] == ":" and key == None:
+                               key = line[:-1].lower()
+                               value = []
+                       elif key != None:
+                               value.append(line)
+                       else:
+                               pass
        
        def write(self):
                write_atomic(self._filename, "\n".join(self._atoms)+"\n")
@@ -31,6 +45,7 @@ class ConfigFileSet(PackageSet):
        def __init__(self, name, filename):
                super(ConfigFileSet, self).__init__(name)
                self._filename = filename
+               self.description = "Package set generated from %s" % self._filename
 
        def load(self):
                self._setAtoms(grabdict_package(self._filename, recursive=True).keys())
index 14394598e830cf857a3c29e0d902c1d6d092f081..55b7942f594f2a9b747c0be53a4eab8dc6b39af2 100644 (file)
@@ -13,6 +13,7 @@ class PackagesSystemSet(PackageSet):
        def __init__(self, name, profile_paths):
                super(PackagesSystemSet, self).__init__(name)
                self._profile_paths = profile_paths
+               self.description = "System packages for profile %s" % self._profile_paths[-1]
        
        def load(self):
                mylist = [grabfile_package(os.path.join(x, "packages")) for x in self._profile_paths]
index cf4af09408d4c5b1cf59f825491eb457506c8831..3bc9cbca4862e5a489052a1b639b3f224c0ad2dc 100644 (file)
@@ -13,6 +13,8 @@ class SecuritySet(PackageSet):
        _operations = ["merge"]
        _skip_applied = False
        
+       description = "package set that includes all packages possibly affected by a GLSA"
+               
        def __init__(self, name, settings, vardbapi, portdbapi):
                super(SecuritySet, self).__init__(name)
                self._settings = settings
@@ -53,10 +55,14 @@ class SecuritySet(PackageSet):
        
 class NewGlsaSet(SecuritySet):
        _skip_applied = True
+       description = "Package set that includes all packages possibly affected by an unapplied GLSA"
 
 class AffectedSet(SecuritySet):
+       description = "Package set that includes all packages affected by an unapplied GLSA"
+
        def useGlsa(self, myglsa):
                return myglsa.isVulnerable()
 
 class NewAffectedSet(AffectedSet):
        _skip_applied = True
+       description = "Package set that includes all packages affected by an unapplied GLSA"
index baef6dee01c6ec2042223a0e2b985b5911622a3f..2383dba81cf1463e94698f398f2eb39ea29e1d8b 100644 (file)
@@ -12,6 +12,7 @@ class CommandOutputSet(PackageSet):
        def __init__(self, name, command):
                super(CommandOutputSet, self).__init__(name)
                self._command = command
+               self.description = "Package set generated from output of '%s'" % self._command
        
        def load(self):
                pipe = subprocess.Popen(self._command, stdout=subprocess.PIPE, shell=True)