1 |
Author: idl0r |
2 |
Date: 2009-09-09 16:22:35 +0000 (Wed, 09 Sep 2009) |
3 |
New Revision: 678 |
4 |
|
5 |
Modified: |
6 |
trunk/gentoolkit-dev/ChangeLog |
7 |
trunk/gentoolkit-dev/src/imlate/imlate |
8 |
Log: |
9 |
Bump imlate to 0.0.4, see ChangeLog for more details. |
10 |
|
11 |
|
12 |
Modified: trunk/gentoolkit-dev/ChangeLog |
13 |
=================================================================== |
14 |
--- trunk/gentoolkit-dev/ChangeLog 2009-09-08 18:09:48 UTC (rev 677) |
15 |
+++ trunk/gentoolkit-dev/ChangeLog 2009-09-09 16:22:35 UTC (rev 678) |
16 |
@@ -1,3 +1,11 @@ |
17 |
+2009-09-09: Christian Ruppert <idl0r@g.o> |
18 |
+ * src/imlate/imlate: Bump to 0.0.4. |
19 |
+ Add SLOT support. |
20 |
+ Add option to specify the minimum mtime for the mtime check. |
21 |
+ Add search by herd or maintainer. |
22 |
+ Add single package mode. |
23 |
+ Automatic detection of TARGET/MAIN-_ARCH. |
24 |
+ |
25 |
2009-09-06: Christian Ruppert <idl0r@g.o> |
26 |
* src/echangelog/echangelog: Fix regex, thanks to Magnus Granberg (zorry) <zorry@×××.nu>. |
27 |
|
28 |
|
29 |
Modified: trunk/gentoolkit-dev/src/imlate/imlate |
30 |
=================================================================== |
31 |
--- trunk/gentoolkit-dev/src/imlate/imlate 2009-09-08 18:09:48 UTC (rev 677) |
32 |
+++ trunk/gentoolkit-dev/src/imlate/imlate 2009-09-09 16:22:35 UTC (rev 678) |
33 |
@@ -6,11 +6,16 @@ |
34 |
|
35 |
# author: Christian Ruppert <idl0r@g.o> |
36 |
|
37 |
-VERSION = "0.0.3" |
38 |
+VERSION = "0.0.4" |
39 |
|
40 |
# works just with stable keywords! |
41 |
-MAIN_ARCH = "amd64" # can be overridden by -m ARCH |
42 |
-TARGET_ARCH = "x86" # can be overridden by -t ARCH |
43 |
+MAIN_ARCH = "auto" # can be overridden by -m ARCH |
44 |
+TARGET_ARCH = "auto" # can be overridden by -t ARCH |
45 |
+# auto means e.g.: |
46 |
+# MAIN_ARCH = amd64 |
47 |
+# TARGET_ARCH = ~amd64 |
48 |
+# That will show you general stable candidates for amd64. |
49 |
+# The arch will be taken from your portage settings (e.g. make.conf). |
50 |
|
51 |
################################ |
52 |
# do not change anything below # |
53 |
@@ -20,6 +25,8 @@ |
54 |
from sys import stderr, stdout |
55 |
from os import stat |
56 |
from time import time |
57 |
+from xml.dom import minidom, NotFoundErr |
58 |
+from xml.parsers.expat import ExpatError |
59 |
# TODO: just import needed stuff to safe memory and maybe use "as foo" |
60 |
import portage |
61 |
|
62 |
@@ -71,7 +78,7 @@ |
63 |
col2 = 20 |
64 |
|
65 |
_header = "%s candidates for 'gentoo' on '%s'" |
66 |
- _helper = "category/package our version best version" |
67 |
+ _helper = "category/package[:SLOT] our version best version" |
68 |
_cand = "" |
69 |
header = "" |
70 |
|
71 |
@@ -111,6 +118,85 @@ |
72 |
if conf["FILE"] != "stdout": |
73 |
out.close() |
74 |
|
75 |
+def _get_metadata(metadata, element, tag): |
76 |
+ values = [] |
77 |
+ |
78 |
+ try: |
79 |
+ metadatadom = minidom.parse(metadata) |
80 |
+ except ExpatError, e: |
81 |
+ raise ExpatError("%s: %s" % (metadata, e,)) |
82 |
+ |
83 |
+ try: |
84 |
+ elements = metadatadom.getElementsByTagName(element) |
85 |
+ if not elements: |
86 |
+ return values |
87 |
+ except NotFoundErr: |
88 |
+ return values |
89 |
+ |
90 |
+ try: |
91 |
+ for _element in elements: |
92 |
+ node = _element.getElementsByTagName(tag) |
93 |
+ |
94 |
+ if tag == "herd" and (not node or not node[0].childNodes): |
95 |
+ print >> stderr, "'%s' is missing a <herd> tag or it is empty," % metadata |
96 |
+ print >> stderr, "please file a bug at https://bugs.gentoo.org and refer to http://www.gentoo.org/proj/en/devrel/handbook/handbook.xml?part=2&chap=4" |
97 |
+ values.append("no-herd") |
98 |
+ continue |
99 |
+ |
100 |
+ values.append(node[0].childNodes[0].data) |
101 |
+ except NotFoundErr: |
102 |
+ raise NotFoundErr("%s: Malformed input: missing 'flag' tag(s)" % (metadata)) |
103 |
+ |
104 |
+ metadatadom.unlink() |
105 |
+ return values |
106 |
+ |
107 |
+def is_maintainer(maintainer, metadata): |
108 |
+ data = [] |
109 |
+ |
110 |
+ if maintainer == None: |
111 |
+ return True |
112 |
+ |
113 |
+ mtainer = maintainer.split(",") |
114 |
+ |
115 |
+ data = _get_metadata(metadata, "maintainer", "email") |
116 |
+ |
117 |
+ if not data and len(maintainer) == 0: |
118 |
+ return True |
119 |
+ elif not data and len(maintainer) > 0: |
120 |
+ return False |
121 |
+ else: |
122 |
+ for addy in data: |
123 |
+ for foo in mtainer: |
124 |
+ if addy == foo: |
125 |
+ return True |
126 |
+ if addy.startswith(foo): |
127 |
+ return True |
128 |
+ return False |
129 |
+ |
130 |
+def is_herd(herd, metadata): |
131 |
+ data = [] |
132 |
+ |
133 |
+ if herd == None: |
134 |
+ return True |
135 |
+ |
136 |
+ hrd = herd.split(",") |
137 |
+ data = _get_metadata(metadata, "pkgmetadata", "herd") |
138 |
+ |
139 |
+ if not data and len(herd) == 0: |
140 |
+ return True |
141 |
+ elif not data and len(herd) > 0: |
142 |
+ return False |
143 |
+ else: |
144 |
+ for hd in data: |
145 |
+ for hd2 in hrd: |
146 |
+ if hd == hd2: |
147 |
+ return True |
148 |
+ if hd.startswith(hd2): |
149 |
+ return True |
150 |
+ |
151 |
+ return False |
152 |
+ |
153 |
+ |
154 |
# fetch a list of arch (just stable) packages |
155 |
# -* is important to be sure that just arch is used |
156 |
def get_packages( conf ): |
157 |
@@ -120,20 +206,45 @@ |
158 |
conf["portdb"].settings ) |
159 |
|
160 |
for cp in conf["portdb"].dbapi.cp_all(): |
161 |
- cpvr = portage.best( conf["portdb"].dbapi.match( cp ) ) |
162 |
- if cpvr: |
163 |
- ( cat, pkg, ver, rev ) = portage.catpkgsplit( cpvr ) |
164 |
+ cpvrs = [] |
165 |
+ slots = {} |
166 |
|
167 |
- if not cat in _pkgs.keys(): |
168 |
- _pkgs[cat] = {} |
169 |
- if not pkg in _pkgs[cat].keys(): |
170 |
- _pkgs[cat][pkg] = [] |
171 |
+ if conf["USER_PKGS"]: |
172 |
+ if not cp in conf["USER_PKGS"]: |
173 |
+ continue |
174 |
|
175 |
- if rev != "r0": |
176 |
- ver = "%s-%s" % ( ver, rev ) |
177 |
+ # None is important to match also on empty string |
178 |
+ if conf["MAINTAINER"] != None: |
179 |
+ if not is_maintainer(conf["MAINTAINER"], join(conf["PORTDIR"], cp, "metadata.xml")): |
180 |
+ continue |
181 |
+ if conf["HERD"] != None: |
182 |
+ if not is_herd(conf["HERD"], join(conf["PORTDIR"], cp, "metadata.xml")): |
183 |
+ continue |
184 |
|
185 |
- _pkgs[cat][pkg].append( ver ) |
186 |
+ cpvrs = conf["portdb"].dbapi.match( cp ) |
187 |
|
188 |
+ for cpvr in cpvrs: |
189 |
+ slot = conf["portdb"].dbapi.aux_get( cpvr, ["SLOT"] )[0] |
190 |
+ if not slot in slots: |
191 |
+ slots[slot] = [] |
192 |
+ slots[slot].append(cpvr) |
193 |
+ |
194 |
+ for slot in sorted(slots): |
195 |
+ cpvr = portage.best( slots[slot] ) |
196 |
+ |
197 |
+ if cpvr: |
198 |
+ ( cat, pkg, ver, rev ) = portage.catpkgsplit( cpvr ) |
199 |
+ |
200 |
+ if not cat in _pkgs.keys(): |
201 |
+ _pkgs[cat] = {} |
202 |
+ if not pkg in _pkgs[cat].keys(): |
203 |
+ _pkgs[cat][pkg] = [] |
204 |
+ |
205 |
+ if rev != "r0": |
206 |
+ ver = "%s-%s" % ( ver, rev ) |
207 |
+ |
208 |
+ _pkgs[cat][pkg].append( ver ) |
209 |
+ |
210 |
return _pkgs |
211 |
|
212 |
# compare get_packages() against MAIN_ARCH |
213 |
@@ -150,82 +261,89 @@ |
214 |
|
215 |
for cat in sorted( pkgs.keys() ): |
216 |
for pkg in sorted( pkgs[cat].keys() ): |
217 |
- cpvr = "" |
218 |
- abs_pkg = "" |
219 |
- kwds = "" |
220 |
- our = "" |
221 |
- our_ver = "" |
222 |
- mtime = 0 |
223 |
+ for vr in pkgs[cat][pkg]: |
224 |
+ cpvr = "" |
225 |
+ abs_pkg = "" |
226 |
+ kwds = "" |
227 |
+ our = "" |
228 |
+ our_ver = "" |
229 |
+ mtime = 0 |
230 |
+ slot = 0 |
231 |
+ |
232 |
+ # 0 = none(default), 1 = testing(~arch), 2 = stable(arch), |
233 |
+ # 3 = exclude(-arch), 4 = exclude_all(-*) |
234 |
+ # -* would be overridden by ~arch or arch |
235 |
+ kwd_type = 0 |
236 |
|
237 |
- # 0 = none(default), 1 = testing(~arch), 2 = stable(arch), |
238 |
- # 3 = exclude(-arch), 4 = exclude_all(-*) |
239 |
- # -* would be overridden by ~arch or arch |
240 |
- kwd_type = 0 |
241 |
- |
242 |
- cpvr = "%s/%s-%s" % ( cat, pkg, pkgs[cat][pkg][0] ) |
243 |
- |
244 |
- # absolute ebuild path for mtime check |
245 |
- abs_pkg = join( conf["PORTDIR"], cat, pkg, basename( cpvr ) ) |
246 |
- abs_pkg = "%s.ebuild" % str( abs_pkg ) |
247 |
- |
248 |
- kwds = conf["portdb"].dbapi.aux_get( cpvr, ["KEYWORDS"] )[0] |
249 |
- |
250 |
- # sorted() to keep the right order |
251 |
- # e.g. -* first, -arch second, arch third and ~arch fourth |
252 |
- # -* -foo ~arch |
253 |
- # example: -* would be overridden by ~arch |
254 |
- for kwd in sorted( kwds.split() ): |
255 |
- if kwd == stable: |
256 |
- kwd_type = 2 |
257 |
- break |
258 |
- elif kwd == exclude: |
259 |
- kwd_type = 3 |
260 |
- break |
261 |
+ cpvr = "%s/%s-%s" % ( cat, pkg, vr ) |
262 |
+ |
263 |
+ # absolute ebuild path for mtime check |
264 |
+ abs_pkg = join( conf["PORTDIR"], cat, pkg, basename( cpvr ) ) |
265 |
+ abs_pkg = "%s.ebuild" % str( abs_pkg ) |
266 |
+ |
267 |
+ kwds = conf["portdb"].dbapi.aux_get( cpvr, ["KEYWORDS"] )[0] |
268 |
+ |
269 |
+ # FIXME: %s is bad.. maybe even cast it, else there are issues because its unicode |
270 |
+ slot = ":%s" % conf["portdb"].dbapi.aux_get( cpvr, ["SLOT"] )[0] |
271 |
+ if slot == ":0": |
272 |
+ slot = "" |
273 |
+ |
274 |
+ # sorted() to keep the right order |
275 |
+ # e.g. -* first, -arch second, arch third and ~arch fourth |
276 |
+ # -* -foo ~arch |
277 |
+ # example: -* would be overridden by ~arch |
278 |
+ for kwd in sorted( kwds.split() ): |
279 |
+ if kwd == stable: |
280 |
+ kwd_type = 2 |
281 |
+ break |
282 |
+ elif kwd == exclude: |
283 |
+ kwd_type = 3 |
284 |
+ break |
285 |
+ # EXPERIMENTAL |
286 |
+ elif kwd == exclude_all and conf["EXPERIMENTAL"]: |
287 |
+ kwd_type = 4 |
288 |
+ elif kwd == testing: |
289 |
+ kwd_type = 1 |
290 |
+ break |
291 |
+ |
292 |
+ # ignore -arch and already stabilized packages |
293 |
+ if kwd_type == 3 or kwd_type == 2: |
294 |
+ continue |
295 |
# EXPERIMENTAL |
296 |
- elif kwd == exclude_all and conf["EXPERIMENTAL"]: |
297 |
- kwd_type = 4 |
298 |
- elif kwd == testing: |
299 |
- kwd_type = 1 |
300 |
- break |
301 |
- |
302 |
- # ignore -arch and already stabilized packages |
303 |
- if kwd_type == 3 or kwd_type == 2: |
304 |
- continue |
305 |
- # EXPERIMENTAL |
306 |
- # drop packages without ~arch or arch but -* |
307 |
- # even if there is another version which includes arch or ~arch |
308 |
- if kwd_type == 4 and conf["EXPERIMENTAL"]: |
309 |
- continue |
310 |
- # drop "stable candidates" with mtime < 30 days |
311 |
- # Shall we use gmtime/UTC here? |
312 |
- if kwd_type == 1: |
313 |
- mtime = int( ( time() - stat( abs_pkg ).st_mtime ) / 60 / 60 / 24 ) |
314 |
- if mtime < 30: |
315 |
+ # drop packages without ~arch or arch but -* |
316 |
+ # even if there is another version which includes arch or ~arch |
317 |
+ if kwd_type == 4 and conf["EXPERIMENTAL"]: |
318 |
continue |
319 |
+ # drop "stable candidates" with mtime < 30 days |
320 |
+ # Shall we use gmtime/UTC here? |
321 |
+ if kwd_type == 1: |
322 |
+ mtime = int( ( time() - stat( abs_pkg ).st_mtime ) / 60 / 60 / 24 ) |
323 |
+ if mtime < conf["MTIME"]: |
324 |
+ continue |
325 |
+ |
326 |
+ # look for an existing stable version |
327 |
+ our = portage.best( conf["portdb"].dbapi.match( "%s/%s%s" % ( cat, pkg, slot ) ) ) |
328 |
+ if our: |
329 |
+ _foo = portage.pkgsplit( our ) |
330 |
+ our_ver = _foo[1] |
331 |
+ if _foo[2] != "r0": |
332 |
+ our_ver = "%s-%s" % ( our_ver, _foo[2] ) |
333 |
+ else: |
334 |
+ our_ver = "" |
335 |
+ |
336 |
+ # we just need the version if > our_ver |
337 |
+ if our_ver: |
338 |
+ if portage.vercmp( our_ver, vr ) >= 0: |
339 |
+ continue |
340 |
+ |
341 |
+ if kwd_type == 1 and conf["STABLE"]: |
342 |
+ imlate = _add_ent( imlate, cat, ("%s%s" % (pkg, slot)), vr, our_ver ) |
343 |
+ conf["STABLE_SUM"] += 1 |
344 |
+ elif kwd_type == 0 and conf["KEYWORD"]: |
345 |
+ conf["KEYWORD_SUM"] += 1 |
346 |
+ imlate = _add_ent( imlate, cat, ( "~%s%s" % (pkg, slot) ), |
347 |
+ vr, our_ver ) |
348 |
|
349 |
- # look for an existing stable version |
350 |
- our = portage.best( conf["portdb"].dbapi.match( "%s/%s" % ( cat, pkg ) ) ) |
351 |
- if our: |
352 |
- _foo = portage.pkgsplit( our ) |
353 |
- our_ver = _foo[1] |
354 |
- if _foo[2] != "r0": |
355 |
- our_ver = "%s-%s" % ( our_ver, _foo[2] ) |
356 |
- else: |
357 |
- our_ver = "" |
358 |
- |
359 |
- # we just need the version if > our_ver |
360 |
- if our_ver: |
361 |
- if portage.vercmp( our_ver, pkgs[cat][pkg][0] ) >= 0: |
362 |
- continue |
363 |
- |
364 |
- if kwd_type == 1 and conf["STABLE"]: |
365 |
- imlate = _add_ent( imlate, cat, pkg, pkgs[cat][pkg][0], our_ver ) |
366 |
- conf["STABLE_SUM"] += 1 |
367 |
- elif kwd_type == 0 and conf["KEYWORD"]: |
368 |
- conf["KEYWORD_SUM"] += 1 |
369 |
- imlate = _add_ent( imlate, cat, ( "~%s" % str( pkg ) ), |
370 |
- pkgs[cat][pkg][0], our_ver ) |
371 |
- |
372 |
return imlate |
373 |
|
374 |
# fetch portage related settings |
375 |
@@ -238,6 +356,11 @@ |
376 |
# TODO: maybe we should improve it a bit ;) |
377 |
mysettings = portage.config( config_incrementals = portage.const.INCREMENTALS, local_config = False ) |
378 |
|
379 |
+ if conf["MAIN_ARCH"] == "auto": |
380 |
+ conf["MAIN_ARCH"] = "%s" % mysettings["ACCEPT_KEYWORDS"].split(" ")[0].lstrip("~") |
381 |
+ if conf["TARGET_ARCH"] == "auto": |
382 |
+ conf["TARGET_ARCH"] = "~%s" % mysettings["ACCEPT_KEYWORDS"].split(" ")[0].lstrip("~") |
383 |
+ |
384 |
# TODO: exclude overlay categories from check |
385 |
if conf["CATEGORIES"]: |
386 |
_mycats = [] |
387 |
@@ -271,6 +394,7 @@ |
388 |
pkgs = {} |
389 |
|
390 |
parser = OptionParser( version = "%prog " + VERSION ) |
391 |
+ parser.usage = "%prog [options] [category/package] ..." |
392 |
parser.disable_interspersed_args() |
393 |
|
394 |
parser.add_option( "-f", "--file", dest = "filename", action = "store", type = "string", |
395 |
@@ -279,6 +403,8 @@ |
396 |
help = "set main ARCH (e.g. your arch) [default: %default]", metavar = "ARCH", default = MAIN_ARCH ) |
397 |
parser.add_option( "-t", "--target", dest = "target_arch", action = "store", type = "string", |
398 |
help = "set target ARCH (e.g. x86) [default: %default]", metavar = "ARCH", default = TARGET_ARCH ) |
399 |
+ parser.add_option( "--mtime", dest = "mtime", action = "store", type = "int", |
400 |
+ help = "set minimum MTIME in days [default: %default]", metavar = "MTIME", default = 30 ) |
401 |
|
402 |
# TODO: leave a good comment here (about True/False) :) |
403 |
parser.add_option( "-s", "--stable", dest = "stable", action = "store_true", default = False, |
404 |
@@ -286,6 +412,12 @@ |
405 |
parser.add_option( "-k", "--keyword", dest = "keyword", action = "store_true", default = False, |
406 |
help = "just show keyword candidates (e.g. -s and -k is the default result) [default: True]" ) |
407 |
|
408 |
+ parser.add_option( "-M", "--maintainer", dest = "maintainer", action = "store", type = "string", |
409 |
+ help = "Show only packages from the specified maintainer", metavar = "MAINTAINER", default = None) |
410 |
+ |
411 |
+ parser.add_option( "-H", "--herd", dest = "herd", action = "store", type = "string", |
412 |
+ help = "Show only packages from the specified herd", metavar = "HERD", default = None) |
413 |
+ |
414 |
# EXPERIMENTAL |
415 |
parser.add_option( "-e", "--experimental", dest = "experimental", action = "store_true", default = False, |
416 |
help = "enables experimental functions/features (have a look for # EXPERIMENTAL comments in the source) [default: %default]" ) |
417 |
@@ -297,8 +429,9 @@ |
418 |
( options, args ) = parser.parse_args() |
419 |
|
420 |
if len( args ) > 0: |
421 |
- parser.print_help() |
422 |
- parser.error( "unknown arg(s)" ) |
423 |
+ conf["USER_PKGS"] = args |
424 |
+ else: |
425 |
+ conf["USER_PKGS"] = [] |
426 |
|
427 |
# cleanup optparse |
428 |
try: |
429 |
@@ -316,15 +449,16 @@ |
430 |
conf["KEYWORD_SUM"] = 0 |
431 |
conf["STABLE_SUM"] = 0 |
432 |
|
433 |
- if not options.main_arch in portage.archlist: |
434 |
+ if not options.main_arch in portage.archlist and options.main_arch != "auto": |
435 |
raise ValueError, "invalid MAIN ARCH defined!" |
436 |
- if not options.target_arch in portage.archlist: |
437 |
+ if not options.target_arch in portage.archlist and options.target_arch != "auto": |
438 |
raise ValueError, "invalid TARGET ARCH defined!" |
439 |
|
440 |
conf["MAIN_ARCH"] = options.main_arch |
441 |
conf["TARGET_ARCH"] = options.target_arch |
442 |
|
443 |
conf["FILE"] = options.filename |
444 |
+ conf["MTIME"] = options.mtime |
445 |
|
446 |
if not options.stable and not options.keyword: |
447 |
conf["STABLE"] = True |
448 |
@@ -336,6 +470,9 @@ |
449 |
conf["EXPERIMENTAL"] = options.experimental |
450 |
conf["CATEGORIES"] = options.categories |
451 |
|
452 |
+ conf["MAINTAINER"] = options.maintainer |
453 |
+ conf["HERD"] = options.herd |
454 |
+ |
455 |
# append to our existing |
456 |
conf = get_settings( conf ) |
457 |
pkgs = get_packages( conf ) |