2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
7 # This block ensures that ^C interrupts are handled quietly.
11 def exithandler(signum, frame):
12 signal.signal(signal.SIGINT, signal.SIG_IGN)
13 signal.signal(signal.SIGTERM, signal.SIG_IGN)
16 signal.signal(signal.SIGINT, exithandler)
17 signal.signal(signal.SIGTERM, exithandler)
19 except KeyboardInterrupt:
26 #-----------------------------------------------------------------------------
28 # To add functionality to this tool, add a function below.
30 # The format for functions is:
33 # """<list of options for this function>
34 # <description of the function>
38 # "argv" is an array of the command line parameters provided after the command.
40 # Make sure you document the function in the right format. The documentation
41 # is used to display help on the function.
43 # You do not need to add the function to any lists, this tool is introspective,
44 # and will automaticly add a command by the same name as the function!
48 def has_version(argv):
49 """<root> <category/package>
50 Return code 0 if it's available, 1 otherwise.
53 print "ERROR: insufficient parameters!"
56 mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
63 has_version.uses_root = True
66 def best_version(argv):
67 """<root> <category/package>
68 Returns category/package-version (without .ebuild).
71 print "ERROR: insufficient parameters!"
74 mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
75 print portage.best(mylist)
78 best_version.uses_root = True
81 def mass_best_version(argv):
82 """<root> [<category/package>]+
83 Returns category/package-version (without .ebuild).
86 print "ERROR: insufficient parameters!"
90 mylist=portage.db[argv[0]]["vartree"].dbapi.match(pack)
91 print pack+":"+portage.best(mylist)
94 mass_best_version.uses_root = True
97 """<root> <pkgtype> <category/package> [<key>]+
98 Returns metadata values for the specified package.
101 print >> sys.stderr, "ERROR: insufficient parameters!"
104 root, pkgtype, pkgspec = argv[0:3]
109 "installed":"vartree"}
110 if pkgtype not in type_map:
111 print >> sys.stderr, "Unrecognized package type: '%s'" % pkgtype
114 if os.path.realpath(root) == os.path.realpath(portage.settings["ROOT"]):
115 root = portage.settings["ROOT"] # contains the normalized $ROOT
117 values = trees[root][type_map[pkgtype]].dbapi.aux_get(
122 print >> sys.stderr, "Package not found: '%s'" % pkgspec
125 metadata.uses_root = True
127 def best_visible(argv):
128 """<root> [<category/package>]+
129 Returns category/package-version (without .ebuild).
132 print "ERROR: insufficient parameters!"
135 mylist=portage.db[argv[0]]["porttree"].dbapi.match(argv[1])
136 visible=portage.best(mylist)
144 best_visible.uses_root = True
147 def mass_best_visible(argv):
148 """<root> [<category/package>]+
149 Returns category/package-version (without .ebuild).
152 print "ERROR: insufficient parameters!"
155 for pack in argv[1:]:
156 mylist=portage.db[argv[0]]["porttree"].dbapi.match(pack)
157 print pack+":"+portage.best(mylist)
160 mass_best_visible.uses_root = True
163 def all_best_visible(argv):
165 Returns all best_visible packages (without .ebuild).
168 print "ERROR: insufficient parameters!"
170 #print portage.db[argv[0]]["porttree"].dbapi.cp_all()
171 for pkg in portage.db[argv[0]]["porttree"].dbapi.cp_all():
172 mybest=portage.best(portage.db[argv[0]]["porttree"].dbapi.match(pkg))
175 all_best_visible.uses_root = True
179 """<root> <category/package>
180 Returns \n seperated list of category/package-version
183 print "ERROR: insufficient parameters!"
186 print "\n".join(portage.db[argv[0]]["vartree"].dbapi.match(argv[1]))
187 except ValueError, e:
188 # Multiple matches thrown from cpv_expand
190 # An error has occurred so we writemsg to stderr and exit nonzero.
191 portage.writemsg("The following packages available:\n", noiselevel=-1)
193 portage.writemsg("* %s\n" % pkg, noiselevel=-1)
194 portage.writemsg("\nPlease use a more specific atom.\n", noiselevel=-1)
197 portage.writemsg("%s\n" % str(e), noiselevel=-1)
199 match.uses_root = True
204 Returns the path used for the var(installed) package database for the
205 set environment/configuration options.
207 print portage.root+portage.VDB_PATH
210 def gentoo_mirrors(argv):
212 Returns the mirrors set to use in the portage configuration.
214 print portage.settings["GENTOO_MIRRORS"]
219 Returns the PORTDIR path.
221 print portage.settings["PORTDIR"]
224 def config_protect(argv):
226 Returns the CONFIG_PROTECT paths.
228 print portage.settings["CONFIG_PROTECT"]
231 def config_protect_mask(argv):
233 Returns the CONFIG_PROTECT_MASK paths.
235 print portage.settings["CONFIG_PROTECT_MASK"]
238 def portdir_overlay(argv):
240 Returns the PORTDIR_OVERLAY path.
242 print portage.settings["PORTDIR_OVERLAY"]
247 Returns the PKGDIR path.
249 print portage.settings["PKGDIR"]
254 Returns the DISTDIR path.
256 print portage.settings["DISTDIR"]
261 Returns a specific environment variable as exists prior to ebuild.sh.
262 Similar to: emerge --verbose --info | egrep '^<variable>='
264 verbose = "-v" in argv
266 argv.pop(argv.index("-v"))
269 print "ERROR: insufficient parameters!"
274 print arg +"='"+ portage.settings[arg] +"'"
276 print portage.settings[arg]
280 Returns all repos with names (repo_name file) argv[0] = $ROOT
283 print "ERROR: insufficient parameters!"
285 print " ".join(portage.db[argv[0]]["porttree"].dbapi.getRepositories())
287 def get_repo_path(argv):
289 Returns the path to the repo named argv[1], argv[0] = $ROOT
292 print "ERROR: insufficient parameters!"
295 print portage.db[argv[0]]["porttree"].dbapi.getRepositoryPath(argv[1])
297 #-----------------------------------------------------------------------------
299 # DO NOT CHANGE CODE BEYOND THIS POINT - IT'S NOT NEEDED!
303 rev="$Revision: 1.13.2.1 $"
304 ver= rev.split(' ')[1]
305 print ">>> Portage information query tool -- version "+ver
306 print ">>> Usage: portageq <command> [<option> ...]"
308 print "Available commands:"
311 # Show our commands -- we do this by scanning the functions in this
312 # file, and formatting each functions documentation.
314 for name in globals().keys():
315 # Drop python stuff, modules, and our own support functions.
316 if (name in ("usage", "__doc__", "__name__", "main", "os", "portage", "sys", "__builtins__", "types", "string","exithandler")):
320 obj = globals()[name]
321 if (type(obj) != types.FunctionType):
327 print " MISSING DOCUMENTATION!"
331 lines = doc.split("\n")
332 print " "+name+" "+lines[0].strip()
333 if (len(sys.argv) > 1):
334 if ("--help" not in sys.argv):
336 for line in lines[1:]:
337 print " "+line.strip()
338 if (len(sys.argv) == 1):
339 print "\nRun portageq with --help for info"
342 if "-h" in sys.argv or "--help" in sys.argv:
345 elif len(sys.argv) < 2:
347 sys.exit(os.EX_USAGE)
351 function = globals()[cmd]
352 uses_root = (getattr(function, "uses_root", False) and len(sys.argv) > 2)
354 os.environ["ROOT"] = sys.argv[2]
359 from os import path as osp
360 sys.path.insert(0, osp.join(osp.dirname(osp.dirname(__file__)), "pym"))
363 sys.argv[2] = portage.root
364 function(sys.argv[2:])
367 sys.exit(os.EX_USAGE)
371 #-----------------------------------------------------------------------------