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:
23 sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym"))
28 #-----------------------------------------------------------------------------
30 # To add functionality to this tool, add a function below.
32 # The format for functions is:
35 # """<list of options for this function>
36 # <description of the function>
40 # "argv" is an array of the command line parameters provided after the command.
42 # Make sure you document the function in the right format. The documentation
43 # is used to display help on the function.
45 # You do not need to add the function to any lists, this tool is introspective,
46 # and will automaticly add a command by the same name as the function!
50 def has_version(argv):
51 """<root> <category/package>
52 Return code 0 if it's available, 1 otherwise.
55 print "ERROR: insufficient parameters!"
58 mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
65 has_version.uses_root = True
68 def best_version(argv):
69 """<root> <category/package>
70 Returns category/package-version (without .ebuild).
73 print "ERROR: insufficient parameters!"
76 mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
77 print portage.best(mylist)
80 best_version.uses_root = True
83 def mass_best_version(argv):
84 """<root> [<category/package>]+
85 Returns category/package-version (without .ebuild).
88 print "ERROR: insufficient parameters!"
92 mylist=portage.db[argv[0]]["vartree"].dbapi.match(pack)
93 print pack+":"+portage.best(mylist)
96 mass_best_version.uses_root = True
99 """<root> <pkgtype> <category/package> [<key>]+
100 Returns metadata values for the specified package.
103 print >> sys.stderr, "ERROR: insufficient parameters!"
106 root, pkgtype, pkgspec = argv[0:3]
111 "installed":"vartree"}
112 if pkgtype not in type_map:
113 print >> sys.stderr, "Unrecognized package type: '%s'" % pkgtype
116 if os.path.realpath(root) == os.path.realpath(portage.settings["ROOT"]):
117 root = portage.settings["ROOT"] # contains the normalized $ROOT
119 values = trees[root][type_map[pkgtype]].dbapi.aux_get(
124 print >> sys.stderr, "Package not found: '%s'" % pkgspec
127 metadata.uses_root = True
129 def best_visible(argv):
130 """<root> [<category/package>]+
131 Returns category/package-version (without .ebuild).
134 print "ERROR: insufficient parameters!"
137 mylist=portage.db[argv[0]]["porttree"].dbapi.match(argv[1])
138 print portage.best(mylist)
141 best_visible.uses_root = True
144 def mass_best_visible(argv):
145 """<root> [<category/package>]+
146 Returns category/package-version (without .ebuild).
149 print "ERROR: insufficient parameters!"
152 for pack in argv[1:]:
153 mylist=portage.db[argv[0]]["porttree"].dbapi.match(pack)
154 print pack+":"+portage.best(mylist)
157 mass_best_visible.uses_root = True
160 def all_best_visible(argv):
162 Returns all best_visible packages (without .ebuild).
165 print "ERROR: insufficient parameters!"
167 #print portage.db[argv[0]]["porttree"].dbapi.cp_all()
168 for pkg in portage.db[argv[0]]["porttree"].dbapi.cp_all():
169 mybest=portage.best(portage.db[argv[0]]["porttree"].dbapi.match(pkg))
172 all_best_visible.uses_root = True
176 """<root> <category/package>
177 Returns \n seperated list of category/package-version
180 print "ERROR: insufficient parameters!"
183 print string.join(portage.db[argv[0]]["vartree"].dbapi.match(argv[1]),"\n")
184 except ValueError, e:
185 # Multiple matches thrown from cpv_expand
187 # An error has occurred so we writemsg to stderr and exit nonzero.
188 portage.writemsg("The following packages available:\n", noiselevel=-1)
190 portage.writemsg("* %s\n" % pkg, noiselevel=-1)
191 portage.writemsg("\nPlease use a more specific atom.\n", noiselevel=-1)
194 portage.writemsg("%s\n" % str(e), noiselevel=-1)
196 match.uses_root = True
201 Returns the path used for the var(installed) package database for the
202 set environment/configuration options.
204 print portage.root+portage.VDB_PATH
207 def gentoo_mirrors(argv):
209 Returns the mirrors set to use in the portage configuration.
211 print portage.settings["GENTOO_MIRRORS"]
216 Returns the PORTDIR path.
218 print portage.settings["PORTDIR"]
221 def config_protect(argv):
223 Returns the CONFIG_PROTECT paths.
225 print portage.settings["CONFIG_PROTECT"]
228 def config_protect_mask(argv):
230 Returns the CONFIG_PROTECT_MASK paths.
232 print portage.settings["CONFIG_PROTECT_MASK"]
235 def portdir_overlay(argv):
237 Returns the PORTDIR_OVERLAY path.
239 print portage.settings["PORTDIR_OVERLAY"]
244 Returns the PKGDIR path.
246 print portage.settings["PKGDIR"]
251 Returns the DISTDIR path.
253 print portage.settings["DISTDIR"]
258 Returns a specific environment variable as exists prior to ebuild.sh.
259 Similar to: emerge --verbose --info | egrep '^<variable>='
261 verbose = "-v" in argv
263 argv.pop(argv.index("-v"))
266 print "ERROR: insufficient parameters!"
271 print arg +"='"+ portage.settings[arg] +"'"
273 print portage.settings[arg]
276 #-----------------------------------------------------------------------------
278 # DO NOT CHANGE CODE BEYOND THIS POINT - IT'S NOT NEEDED!
282 rev="$Revision: 1.13.2.1 $"
283 ver=string.split(rev, ' ')[1]
284 print ">>> Portage information query tool -- version "+ver
285 print ">>> Usage: portageq <command> [<option> ...]"
287 print "Available commands:"
290 # Show our commands -- we do this by scanning the functions in this
291 # file, and formatting each functions documentation.
293 for name in globals().keys():
294 # Drop python stuff, modules, and our own support functions.
295 if (name in ("usage", "__doc__", "__name__", "main", "os", "portage", "sys", "__builtins__", "types", "string")):
299 obj = globals()[name]
300 if (type(obj) != types.FunctionType):
306 print " MISSING DOCUMENTATION!"
310 lines = string.split(doc, '\n')
311 print " "+name+" "+string.strip(lines[0])
312 if (len(sys.argv) > 1):
313 if ("--help" not in sys.argv):
315 for line in lines[1:]:
316 print " "+string.strip(line)
317 if (len(sys.argv) == 1):
318 print "\nRun portageq with --help for info"
321 if "-h" in sys.argv or "--help" in sys.argv:
324 elif len(sys.argv) < 2:
326 sys.exit(os.EX_USAGE)
330 function = globals()[cmd]
331 uses_root = (getattr(function, "uses_root", False) and len(sys.argv) > 2)
333 os.environ["ROOT"] = sys.argv[2]
337 sys.argv[2] = portage.root
338 function(sys.argv[2:])
341 sys.exit(os.EX_USAGE)
345 #-----------------------------------------------------------------------------