Add a new portageq metadata function that wraps dbapi.aux_get() so that things like...
authorZac Medico <zmedico@gentoo.org>
Mon, 31 Jul 2006 18:51:15 +0000 (18:51 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 31 Jul 2006 18:51:15 +0000 (18:51 -0000)
svn path=/main/branches/2.1/; revision=4071

bin/portageq

index ab1a9311f72a7bc33e08ea0a9b1290f8a95cb441..433375671753361945fb66ed2e617d7abae2e522 100755 (executable)
@@ -80,6 +80,36 @@ def mass_best_version(argv):
                sys.exit(1)
 mass_best_version.uses_root = True
 
+def metadata(argv):
+       """<root> <pkgtype> <category/package> [<key>]+
+       Returns metadata values for the specified package.
+       """
+       if (len(argv) < 4):
+               print >> sys.stderr, "ERROR: insufficient parameters!"
+               sys.exit(2)
+
+       root, pkgtype, pkgspec = argv[0:3]
+       metakeys = argv[3:]
+       type_map = {
+               "ebuild":"porttree",
+               "binary":"bintree",
+               "installed":"vartree"}
+       if pkgtype not in type_map:
+               print >> sys.stderr, "Unrecognized package type: '%s'" % pkgtype
+               sys.exit(1)
+       trees = portage.db
+       if os.path.realpath(root) == os.path.realpath(portage.settings["ROOT"]):
+               root = portage.settings["ROOT"] # contains the normalized $ROOT
+       try:
+                       values = trees[root][type_map[pkgtype]].dbapi.aux_get(
+                               pkgspec, metakeys)
+                       for value in values:
+                               print value
+       except KeyError:
+               print >> sys.stderr, "Package not found: '%s'" % pkgspec
+               sys.exit(1)
+
+metadata.uses_root = True
 
 def best_visible(argv):
        """<root> [<category/package>]+