2 # Copyright 1999-2004 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
10 import portage,types,string
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])
52 def best_version(argv):
53 """<root> <category/package>
54 Returns category/package-version (without .ebuild).
57 print "ERROR: insufficient parameters!"
60 mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
61 print portage.best(mylist)
66 def mass_best_version(argv):
67 """<root> [<category/package>]+
68 Returns category/package-version (without .ebuild).
71 print "ERROR: insufficient parameters!"
75 mylist=portage.db[argv[0]]["vartree"].dbapi.match(pack)
76 print pack+":"+portage.best(mylist)
81 def best_visible(argv):
82 """<root> [<category/package>]+
83 Returns category/package-version (without .ebuild).
86 print "ERROR: insufficient parameters!"
89 mylist=portage.db[argv[0]]["porttree"].dbapi.match(argv[1])
90 print portage.best(mylist)
95 def mass_best_visible(argv):
96 """<root> [<category/package>]+
97 Returns category/package-version (without .ebuild).
100 print "ERROR: insufficient parameters!"
103 for pack in argv[1:]:
104 mylist=portage.db[argv[0]]["porttree"].dbapi.match(pack)
105 print pack+":"+portage.best(mylist)
110 def all_best_visible(argv):
112 Returns all best_visible packages (without .ebuild).
115 print "ERROR: insufficient parameters!"
117 #print portage.db[argv[0]]["porttree"].dbapi.cp_all()
118 for pkg in portage.db[argv[0]]["porttree"].dbapi.cp_all():
119 mybest=portage.best(portage.db[argv[0]]["porttree"].dbapi.match(pkg))
124 """<root> <category/package>
125 Returns \n seperated list of category/package-version
128 print "ERROR: insufficient parameters!"
131 print string.join(portage.db[argv[0]]["vartree"].dbapi.match(argv[1]),"\n")
138 Returns the path used for the var(installed) package database for the
139 set environment/configuration options.
141 print portage.root+portage.VDB_PATH
143 def gentoo_mirrors(argv):
145 Returns the mirrors set to use in the portage configuration.
147 print portage.settings["GENTOO_MIRRORS"]
152 Returns the PORTDIR path as defined in the portage configuration.
154 print portage.settings["PORTDIR"]
157 def config_protect(argv):
159 Returns the CONFIG_PROTECT paths as defined in the portage configuration.
161 print portage.settings["CONFIG_PROTECT"]
164 def config_protect_mask(argv):
166 Returns the CONFIG_PROTECT_MASK paths as defined in the portage configuration.
168 print portage.settings["CONFIG_PROTECT_MASK"]
171 def portdir_overlay(argv):
173 Returns the PORTDIR_OVERLAY path as defined in the portage configuration.
175 print portage.settings["PORTDIR_OVERLAY"]
180 Returns the PKGDIR path as defined in the portage configuration.
182 print portage.settings["PKGDIR"]
187 Returns the DISTDIR path as defined in the portage configuration.
189 print portage.settings["DISTDIR"]
194 Returns a specific environment variable as exists prior to ebuild.sh.
195 Similar to: emerge --verbose --info | egrep '^<variable>='
197 print portage.settings[argv[0]]
200 #-----------------------------------------------------------------------------
202 # DO NOT CHANGE CODE BEYOND THIS POINT - IT'S NOT NEEDED!
206 rev="$Revision: 1.13.2.1 $"
207 ver=string.split(rev, ' ')[1]
208 print ">>> Portage information query tool -- version "+ver
209 print ">>> Usage: portageq <command> [<option> ...]"
211 print "Available commands:"
214 # Show our commands -- we do this by scanning the functions in this
215 # file, and formatting each functions documentation.
217 for name in globals().keys():
218 # Drop python stuff, modules, and our own support functions.
219 if (name in ("usage", "__doc__", "__name__", "main", "os", "portage", "sys", "__builtins__", "types", "string")):
223 obj = globals()[name]
224 if (type(obj) != types.FunctionType):
230 print " MISSING DOCUMENTATION!"
234 lines = string.split(doc, '\n')
235 print " "+name+" "+string.strip(lines[0])
236 for line in lines[1:]:
237 print " "+string.strip(line)
241 if (len(sys.argv) < 2):
247 function = globals()[cmd]
248 function(sys.argv[2:])
256 #-----------------------------------------------------------------------------