2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Id: /var/cvsroot/gentoo-src/portage/bin/portageq,v 1.13.2.1 2005/04/12 12:23:41 jstubbs Exp $
7 os.environ["PORTAGE_CALLER"] = "portageq"
8 sys.path = ["/usr/lib/portage/pym"]+sys.path
13 #-----------------------------------------------------------------------------
15 # To add functionality to this tool, add a function below.
17 # The format for functions is:
20 # """<list of options for this function>
21 # <description of the function>
25 # "argv" is an array of the command line parameters provided after the command.
27 # Make sure you document the function in the right format. The documentation
28 # is used to display help on the function.
30 # You do not need to add the function to any lists, this tool is introspective,
31 # and will automaticly add a command by the same name as the function!
35 def has_version(argv):
36 """<root> <category/package>
37 Return code 0 if it's available, 1 otherwise.
40 print "ERROR: insufficient parameters!"
43 mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
50 has_version.uses_root = True
53 def best_version(argv):
54 """<root> <category/package>
55 Returns category/package-version (without .ebuild).
58 print "ERROR: insufficient parameters!"
61 mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
62 print portage.best(mylist)
65 best_version.uses_root = True
68 def mass_best_version(argv):
69 """<root> [<category/package>]+
70 Returns category/package-version (without .ebuild).
73 print "ERROR: insufficient parameters!"
77 mylist=portage.db[argv[0]]["vartree"].dbapi.match(pack)
78 print pack+":"+portage.best(mylist)
81 mass_best_version.uses_root = True
84 def best_visible(argv):
85 """<root> [<category/package>]+
86 Returns category/package-version (without .ebuild).
89 print "ERROR: insufficient parameters!"
92 mylist=portage.db[argv[0]]["porttree"].dbapi.match(argv[1])
93 print portage.best(mylist)
96 best_visible.uses_root = True
99 def mass_best_visible(argv):
100 """<root> [<category/package>]+
101 Returns category/package-version (without .ebuild).
104 print "ERROR: insufficient parameters!"
107 for pack in argv[1:]:
108 mylist=portage.db[argv[0]]["porttree"].dbapi.match(pack)
109 print pack+":"+portage.best(mylist)
112 mass_best_visible.uses_root = True
115 def all_best_visible(argv):
117 Returns all best_visible packages (without .ebuild).
120 print "ERROR: insufficient parameters!"
122 #print portage.db[argv[0]]["porttree"].dbapi.cp_all()
123 for pkg in portage.db[argv[0]]["porttree"].dbapi.cp_all():
124 mybest=portage.best(portage.db[argv[0]]["porttree"].dbapi.match(pkg))
127 all_best_visible.uses_root = True
131 """<root> <category/package>
132 Returns \n seperated list of category/package-version
135 print "ERROR: insufficient parameters!"
138 print string.join(portage.db[argv[0]]["vartree"].dbapi.match(argv[1]),"\n")
141 match.uses_root = True
146 Returns the path used for the var(installed) package database for the
147 set environment/configuration options.
149 print portage.root+portage.VDB_PATH
152 def gentoo_mirrors(argv):
154 Returns the mirrors set to use in the portage configuration.
156 print portage.settings["GENTOO_MIRRORS"]
161 Returns the PORTDIR path.
163 print portage.settings["PORTDIR"]
166 def config_protect(argv):
168 Returns the CONFIG_PROTECT paths.
170 print portage.settings["CONFIG_PROTECT"]
173 def config_protect_mask(argv):
175 Returns the CONFIG_PROTECT_MASK paths.
177 print portage.settings["CONFIG_PROTECT_MASK"]
180 def portdir_overlay(argv):
182 Returns the PORTDIR_OVERLAY path.
184 print portage.settings["PORTDIR_OVERLAY"]
189 Returns the PKGDIR path.
191 print portage.settings["PKGDIR"]
196 Returns the DISTDIR path.
198 print portage.settings["DISTDIR"]
203 Returns a specific environment variable as exists prior to ebuild.sh.
204 Similar to: emerge --verbose --info | egrep '^<variable>='
206 if (argv[0] == "-v"):
213 print arg +"='"+ portage.settings[arg] +"'"
215 print portage.settings[arg]
218 #-----------------------------------------------------------------------------
220 # DO NOT CHANGE CODE BEYOND THIS POINT - IT'S NOT NEEDED!
224 rev="$Revision: 1.13.2.1 $"
225 ver=string.split(rev, ' ')[1]
226 print ">>> Portage information query tool -- version "+ver
227 print ">>> Usage: portageq <command> [<option> ...]"
229 print "Available commands:"
232 # Show our commands -- we do this by scanning the functions in this
233 # file, and formatting each functions documentation.
235 for name in globals().keys():
236 # Drop python stuff, modules, and our own support functions.
237 if (name in ("usage", "__doc__", "__name__", "main", "os", "portage", "sys", "__builtins__", "types", "string")):
241 obj = globals()[name]
242 if (type(obj) != types.FunctionType):
248 print " MISSING DOCUMENTATION!"
252 lines = string.split(doc, '\n')
253 print " "+name+" "+string.strip(lines[0])
254 if (len(sys.argv) > 1):
255 if ("--help" not in sys.argv):
257 for line in lines[1:]:
258 print " "+string.strip(line)
259 if (len(sys.argv) == 1):
260 print "\nRun portageq with --help for info"
263 if (len(sys.argv) < 2) or ("-h" in sys.argv or "--help" in sys.argv):
269 function = globals()[cmd]
270 uses_root = (getattr(function, "uses_root", False) and len(sys.argv) > 2)
272 os.environ["ROOT"] = sys.argv[2]
276 sys.argv[2] = portage.root
277 function(sys.argv[2:])
284 #-----------------------------------------------------------------------------