/[gentoo-src]/portage/pym/portageq.py
Gentoo

Contents of /portage/pym/portageq.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download) (as text)
Sun Dec 5 13:35:59 2004 UTC (9 years, 10 months ago) by ferringb
Branch: MAIN
CVS Tags: HEAD
Branch point for: portage_2_1
Changes since 1.1: +1 -5 lines
File MIME type: text/x-python
cleanup, removed the sys import and a lingering sys.exit

1 #!/usr/bin/python -O
2 # Copyright 1999-2003 Gentoo Technologies, Inc.
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-src/portage/pym/portageq.py,v 1.1 2004/11/07 12:54:40 ferringb Exp $
5
6 # this is the core portageq functionality, stuck in a module so ebuild_daemon can use it.
7 # bin/portageq doesn't currently use this, but should for the sake of reduction of code
8 # duplication.
9
10 import portage,types,string
11
12
13 #-----------------------------------------------------------------------------
14 #
15 # To add functionality to this tool, add a function below.
16 #
17 # The format for functions is:
18 #
19 # def function(argv):
20 # """<list of options for this function>
21 # <description of the function>
22 # """
23 # <code>
24 #
25 # "argv" is an array of the command line parameters provided after the command.
26 #
27 # Make sure you document the function in the right format. The documentation
28 # is used to display help on the function.
29 #
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!
32 #
33
34
35 def has_version(argv):
36 """<root> <category/package>
37 Return code 0 if it's available, 1 otherwise.
38 """
39 if (len(argv) < 2):
40 print "ERROR: insufficient parameters!"
41 raise Exception
42 try:
43 mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
44 if mylist:
45 return 0, ""
46 else:
47 return 1, ""
48 except KeyError:
49 return 1, ""
50
51
52 def best_version(argv):
53 """<root> <category/package>
54 Returns category/package-version (without .ebuild).
55 """
56 if (len(argv) < 2):
57 print "ERROR: insufficient parameters!"
58 raise Exception
59 try:
60 mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
61 return 0, portage.best(mylist)
62 except KeyError:
63 return 1, ""
64
65
66 def mass_best_version(argv):
67 """<root> [<category/package>]+
68 Returns category/package-version (without .ebuild).
69 """
70 if (len(argv) < 2):
71 print "ERROR: insufficient parameters!"
72 raise Exception
73 try:
74 s=''
75 for pack in argv[1:]:
76 mylist=portage.db[argv[0]]["vartree"].dbapi.match(pack)
77 s += "%s:%s\n" % (pack, portage.best(mylist))
78 return 0, s
79 except KeyError:
80 return 1, ""
81
82
83 def best_visible(argv):
84 """<root> [<category/package>]+
85 Returns category/package-version (without .ebuild).
86 """
87 if (len(argv) < 2):
88 raise Exception("insufficient parameters")
89 try:
90 mylist=portage.db[argv[0]]["porttree"].dbapi.match(argv[1])
91 return 0, portage.best(mylist)
92 except KeyError:
93 return 1, ""
94
95
96 def mass_best_visible(argv):
97 """<root> [<category/package>]+
98 Returns category/package-version (without .ebuild).
99 """
100 if (len(argv) < 2):
101 print "ERROR: insufficient parameters!"
102 raise Exception
103 try:
104 s=''
105 for pack in argv[1:]:
106 mylist=portage.db[argv[0]]["porttree"].dbapi.match(pack)
107 s += "%s:%s\n" % (pack, portage.best(mylist))
108 return 0,s
109 except KeyError:
110 return 1, ''
111
112
113 def all_best_visible(argv):
114 """<root>
115 Returns all best_visible packages (without .ebuild).
116 """
117 if (len(argv) < 1):
118 print "ERROR: insufficient parameters!"
119 raise Exception("ERROR: insufficient parameters!")
120
121 #print portage.db[argv[0]]["porttree"].dbapi.cp_all()
122 s=''
123 for pkg in portage.db[argv[0]]["porttree"].dbapi.cp_all():
124 mybest=portage.best(portage.db[argv[0]]["porttree"].dbapi.match(pkg))
125 if mybest:
126 s += mybest +"\n"
127 return 0,s
128
129 def match(argv):
130 """<root> <category/package>
131 Returns \n seperated list of category/package-version
132 """
133 if (len(argv) < 2):
134 print "ERROR: insufficient parameters!"
135 raise Exception
136 try:
137 return 0, string.join(portage.db[argv[0]]["vartree"].dbapi.match(argv[1]),"\n")
138 except KeyError:
139 return 1,''
140
141
142 def vdb_path(argv):
143 """
144 Returns the path used for the var(installed) package database for the
145 set environment/configuration options.
146 """
147 return 0, portage.root+portage.VDB_PATH+"\n"
148
149 def gentoo_mirrors(argv):
150 """
151 Returns the mirrors set to use in the portage configuration.
152 """
153 return 0,portage.settings["GENTOO_MIRRORS"]+"\n"
154
155
156 def portdir(argv):
157 """
158 Returns the PORTDIR path as defined in the portage configuration.
159 """
160 return 0, portage.settings["PORTDIR"]+"\n"
161
162
163 def config_protect(argv):
164 """
165 Returns the CONFIG_PROTECT paths as defined in the portage configuration.
166 """
167 return 0, portage.settings["PORTDIR"]+"\n"
168
169
170 def config_protect_mask(argv):
171 """
172 Returns the CONFIG_PROTECT_MASK paths as defined in the portage configuration.
173 """
174 return 0, portage.settings["CONFIG_PROTECT_MASK"]+"\n"
175
176
177 def portdir_overlay(argv):
178 """
179 Returns the PORTDIR_OVERLAY path as defined in the portage configuration.
180 """
181 return 0, portage.settings["PORTDIR_OVERLAY"]+"\n"
182
183
184 def pkgdir(argv):
185 """
186 Returns the PKGDIR path as defined in the portage configuration.
187 """
188 return 0, portage.settings["PKGDIR"]+"\n"
189
190
191 def distdir(argv):
192 """
193 Returns the DISTDIR path as defined in the portage configuration.
194 """
195 return 0, portage.settings["DISTDIR"]+"\n"
196
197
198 def envvar(argv):
199 """<variable>
200 Returns a specific environment variable as exists prior to ebuild.sh.
201 Similar to: emerge --verbose --info | egrep '^<variable>='
202 """
203 return 0, portage.settings[argv[0]]+"\n"

  ViewVC Help
Powered by ViewVC 1.1.20