fix metadata parsing for file-based sets, add support for user-defined file sets...
authorMarius Mauch <genone@gentoo.org>
Mon, 16 Jul 2007 09:15:54 +0000 (09:15 -0000)
committerMarius Mauch <genone@gentoo.org>
Mon, 16 Jul 2007 09:15:54 +0000 (09:15 -0000)
svn path=/main/trunk/; revision=7277

pym/portage/sets/__init__.py
pym/portage/sets/files.py

index 72e8b20916730f48d30a4a572152fdc01d311aab..e2087d816a5ef5ded1efa2f917d48102dd2cf8c7 100644 (file)
@@ -157,12 +157,22 @@ def make_category_sets(portdbapi, settings, only_visible=True):
 
 # adhoc test code
 if __name__ == "__main__":
-       import portage, sys
+       import portage, sys, os
+       from portage.sets.dbapi import CategorySet
+       from portage.sets.files import StaticFileSet
        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 s in sys.argv[1:]:
+                       if s.startswith("category_"):
+                               c = s[9:]
+                               l.add(CategorySet("category_%s" % c, c, portdbapi, only_visible=only_visible))
+                       elif os.path.exists(s):
+                               l.add(StaticFileSet(os.path.basename(s), s))
+                       elif s != "*":
+                               print "ERROR: could not create set '%s'" % s
+               if not "*" in sys.argv:
+                       l = [s for s in l if s.getName() in sys.argv[1:]]
        for x in l:
                print x.getName()+":"
                print "DESCRIPTION = %s" % x.getMetadata("Description")
index 921d04b8c432ac751359e91b1394733957ed6c81..9558cc7a30a0ab3999fc686e0e4bc150d5b92520 100644 (file)
@@ -18,6 +18,7 @@ class StaticFileSet(EditablePackageSet):
                metadata = grabfile(self._filename + ".metadata")
                key = None
                for line in metadata:
+                       line = line.strip()
                        if len(line) == 0 and key != None:
                                setattr(self, key, " ".join(value))
                                key = None
@@ -28,6 +29,9 @@ class StaticFileSet(EditablePackageSet):
                                value.append(line)
                        else:
                                pass
+               else:
+                       if key != None:
+                               setattr(self, key, " ".join(value))
        
        def write(self):
                write_atomic(self._filename, "\n".join(self._atoms)+"\n")