/[gentoo]/src/packages/gentoo.py
Gentoo

Contents of /src/packages/gentoo.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download) (as text)
Sat May 21 21:03:18 2005 UTC (9 years, 2 months ago) by marduk
Branch: MAIN
Changes since 1.8: +2 -2 lines
File MIME type: text/x-python
RSS: changed encoding to UTF-8

1 marduk 1.8 #!/usr/bin/python -O
2 marduk 1.2 """These functions mainly take ebuild info (grabbed from the database and
3     convert it to HTML. See the "main" function at the bottom."""
4    
5 marduk 1.9 __revision__ = "$Revision: 1.8 $"
6 marduk 1.4 # $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $
7 marduk 1.1
8     import config
9     import os
10     import time
11 marduk 1.7 import string
12 marduk 1.1 import sys
13     import ebuilddb
14 marduk 1.2 import bugs
15 marduk 1.1 import changelogs
16     from cgi import escape
17     from urllib import quote
18    
19 marduk 1.8 endversion={"pre":-2,"p":0,"alpha":-4,"beta":-3,"rc":-1}
20     # as there's no reliable way to set {}.keys() order
21     # netversion_keys will be used instead of endversion.keys
22     # to have fixed search order, so that "pre" is checked
23     # before "p"
24     endversion_keys = ["pre", "p", "alpha", "beta", "rc"]
25 marduk 1.2
26 marduk 1.3 def is_new(db, ebuild):
27 marduk 1.8 """Check for newness."""
28 marduk 1.1
29     c = db.cursor()
30 marduk 1.8 query = ('SELECT new FROM package WHERE category="%s" AND name="%s"'
31 marduk 1.2 % (ebuild['category'], ebuild['name']))
32 marduk 1.1 c.execute(query)
33     results = c.fetchall()
34 marduk 1.8 if len(results) == 1 and results[0][0]:
35 marduk 1.1 return 1
36     return 0
37    
38 marduk 1.2 def changelog_to_html(changelog):
39     """HTML-ize a changelog entry"""
40     html = ""
41     for char in changelog:
42     if char == '\n':
43     html = "%s<br>" % html
44 marduk 1.1 else:
45 marduk 1.2 html = "%s%s" % (html, escape(char))
46     html = changelogs.bugs_to_html(html)
47     return html
48    
49     def homepage_to_html(homepage):
50     """convert HOMEPAGE entry to HTML"""
51 marduk 1.3 if not homepage.strip():
52     return "?"
53 marduk 1.2 homepage = homepage.replace('|',' ')
54     pieces = homepage.split()
55     count = len(pieces)
56     if count == 1:
57     return ('<a class="homepage" href="%s">'
58     'Homepage</a>' % pieces[0])
59    
60     html = ['[<a href="%s">%s</a>]' % (page, index + 1) for index,
61     page in enumerate(pieces)]
62     return " ".join(['<span class="homepage">Homepages'] + html +
63     ['</span>'])
64    
65     def license_to_html(license):
66 marduk 1.3 """Create link to license[s]"""
67 marduk 1.2 if not license.strip(): return "?"
68     license = license.replace('|',' ')
69 marduk 1.8 license = license.replace('(', '')
70     license = license.replace(')', '')
71 marduk 1.2 pieces = license.split()
72     html = ['<a href="http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/'
73     'licenses/%s">%s</a>' % (piece, piece) for piece in pieces]
74     return '<br>\n'.join(html)
75 marduk 1.1
76 marduk 1.8 def package_to_html(pkginfo, db, full=False):
77 marduk 1.3 """This function needs a database (db) connection because it performs a
78     query_to_dict on the package"""
79 marduk 1.2
80     table_begin = '<table class="ebuild">'
81     name = '<tr><td class="fields">%s</td></tr>' % pkginfo['name']
82 marduk 1.8 if full:
83     image = ('<img class="pkgimg"alt="" src="%s/%s/%s.jpg" align="right">' %
84     (config.ICONS, pkginfo['category'], pkginfo['name'])
85     )
86     else:
87     image = ''
88 marduk 1.2 description = ('<tr><td class="item">'
89 marduk 1.8 '%s<b>Description: </b>%s</td></tr>'
90     % (image, escape(pkginfo['description']))
91     )
92 marduk 1.3 ebuilds = get_recent_releases(pkginfo, db)
93 marduk 1.2 releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases')
94     #bug_string = ('<br><h3>Related bugs:</h3>\n%s'
95     # % bugs_to_html(pkginfo['name']))
96     general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo)
97 marduk 1.7 similar = '<tr><td>%s</td></tr>' % create_similar_pkgs_link(pkginfo)
98 marduk 1.2 table_end = '</table>'
99     rows = '\n\t'.join([name, description, releases, general])
100     return '\n\t'.join([table_begin, rows, table_end])
101    
102     def archs_to_html(ebuilds, heading = None):
103 marduk 1.3 """Create table for availability on each architecture"""
104 marduk 1.2 heading = heading or '&nbsp;'
105     table_begin = '<table class="releases">'
106     header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] +
107 marduk 1.7 ['<th class="arch">%s</th>' % i.replace('-',' ') for i in config.ARCHLIST] +
108 marduk 1.2 ['</tr>']
109     )
110     rows = []
111 marduk 1.7 ebuilds.sort(cmp_ebuilds)
112     ebuilds.reverse()
113 marduk 1.2 for ebuild in ebuilds:
114     archs = ebuild['arch'].split()
115     row_start = ('<tr>\n\t<th class="releases"><a href="%sebuilds/?%s-%s"'
116     ' title="%s">%s</a></th>\n' % (config.FEHOME,
117     ebuild['name'], ebuild['version'], ebuild['time'],
118     ebuild['version']))
119     row_data = []
120     for arch in config.ARCHLIST:
121     if arch in archs:
122     arch_string = '+'
123     elif '~%s' % arch in archs:
124     arch_string = '~'
125     else:
126     arch_string = '-'
127 marduk 1.8 if arch_string != '-' and ebuild['masked']:
128 marduk 1.2 arch_string = 'M' + arch_string
129     row_data.append('\t<td class="archcell" arch="%s">%s</td>'
130     % (arch_string, arch_string))
131     row_end = '</tr>'
132     rows.append('\n\t'.join([row_start] + row_data + [row_end]))
133     table_end = '</table>'
134     return '\n\t'.join([table_begin] + [header_row] + rows + [table_end])
135 marduk 1.1
136 marduk 1.8 def ebuild_to_html(ebinfo, new=0, show_bugs=0, full = False):
137 marduk 1.3 """Convert ebuild (dict) to html, if new, print out a "this is new" notice
138     if show_bugs, show bugs for this particular ebuild (requires access to
139     bugzilla"""
140 marduk 1.1 if new:
141     new_string = """ &nbsp;&nbsp;<span class="new">new!</span> """
142     else:
143     new_string = ""
144    
145 marduk 1.2 table_begin = '<table class="ebuild">'
146     name_and_date = ('<tr><td class="fields">'
147 marduk 1.1 '<a href="%spackages/?category=%s;name=%s">%s</a> %s%s<br>'
148 marduk 1.2 '<span class="time">%s</span>'
149     '</td></tr>' % (config.FEHOME, quote(ebinfo['category']),
150     quote(ebinfo['name']),
151     ebinfo['name'],
152     ebinfo['version'],
153     new_string,
154     ebinfo['time'].localtime().strftime("%c %Z")))
155    
156 marduk 1.8 if full:
157     image = ('<img class="pkgimg" alt="" src="%s/%s/%s.jpg" align="right">' %
158     (config.ICONS, ebinfo['category'], ebinfo['name'])
159     )
160     else:
161     image = ''
162 marduk 1.2 desc_and_changes = ('<tr><td class="item" valign="top">'
163 marduk 1.8 '<p><b>Description:</b> %s %s</p>'
164 marduk 1.2 '<p><b>Changes:</b><br>'
165     '%s</p></td></tr>' % (
166     escape(ebinfo['description']),
167 marduk 1.8 image,
168 marduk 1.2 changelog_to_html(ebinfo['changelog'])))
169    
170     archs = '<tr><td>%s</td></tr>' % archs_to_html([ebinfo])
171     general = '<tr><td>%s</td></tr>' % general_info_to_html(ebinfo)
172     table_end = '</table>'
173    
174 marduk 1.8 bug_string = ''
175     if show_bugs:
176     bug_string = bugs_to_html(ebinfo['name'])
177     if bug_string:
178     bug_string = '<br><h3 class="bugs">Related bugs:</h3>%s' \
179     % bug_string
180 marduk 1.2
181     return '\n\t'.join([table_begin,
182     name_and_date,
183     desc_and_changes,
184     archs,
185     general,
186     table_end,
187     bug_string])
188    
189 marduk 1.1 def general_info_to_html(pkg):
190     """This actually will (should) take either a package or ebuild dict
191     as an argument"""
192    
193 marduk 1.8 import forums
194    
195 marduk 1.1 changelogurl = ('http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/'
196     '%s/%s/ChangeLog' % (pkg['category'],pkg['name']))
197 marduk 1.2 cat_header = '<th class="category">Category</th>'
198     license_header = '<th class="license">License</th>'
199     category = ('<td class="category">'
200     '<a href="%spackages/?category=%s">%s</a></td>' % (config.FEHOME,
201     pkg['category'], pkg['category']))
202     homepage = ('<td class="homepage" rowspan="2">%s</td>'
203     % homepage_to_html(pkg['homepage']))
204     license = ('<td class="license">%s</td>'
205     % license_to_html(pkg['license']))
206     changelog = ('<td class="changelog" rowspan="2">'
207 marduk 1.7 '<a href="%s">ChangeLog</a></td>' % changelogurl)
208     similar = ('<td class="similar" rowspan="2">'
209     '%s</td>' % create_similar_pkgs_link(pkg))
210 marduk 1.8 related_bugs = ('<td class="related_bugs" rowspan="2">'
211     '%s</td>' % create_related_bugs_link(pkg))
212     forums = ('<td class="forums" rowspan="2">'
213     '%s</td>' % forums.create_forums_link(pkg))
214 marduk 1.2
215     return '\n\t'.join(['<table class="general_info">',
216     '<tr>',
217     cat_header,
218     homepage,
219     license_header,
220     changelog,
221 marduk 1.7 similar,
222 marduk 1.8 related_bugs,
223     forums,
224 marduk 1.2 '</tr>',
225     '<tr>',
226     category,
227     license,
228     '</tr>',
229     '</table>'])
230 marduk 1.1
231 marduk 1.7 def create_similar_pkgs_link(pkg):
232     """Create a link to similar packages"""
233    
234     def strip_chars(mystring):
235     newstring = ''
236     for char in mystring:
237     if char not in string.punctuation:
238     newstring = newstring + char
239     else:
240     newstring = newstring + ' '
241     return newstring
242    
243     description = strip_chars(pkg['description'].lower())
244    
245     words = [word for word in description.split()
246     if word and len(word)>2 and word not in config.EXCLUDED_FROM_SIMILAR]
247     words = words[:config.SIMILAR_MAX_WORDS] + [pkg['name']]
248     #query = ['[[:<:]]%s[[:>:]].*' % word for word in words]
249     query = ['[[:<:]]%s.*' % word for word in words]
250     query = '(%s){%s,}' % ('|'.join(query), config.SIMILAR_MIN_MATCHES)
251     url = '%ssearch/?sstring=%s' % (config.FEHOME, escape(query))
252 marduk 1.8 return '<a href="%s">Similar</a>' % url
253 marduk 1.7
254 marduk 1.8 def create_related_bugs_link(pkg):
255     """Create a link to related bugs"""
256    
257     url = ('http://bugs.gentoo.org/buglist.cgi?query_format='
258     '&amp;short_desc_type=allwords'
259     '&amp;short_desc=%s'
260     '&amp;bug_status=UNCONFIRMED'
261     '&amp;bug_status=NEW'
262     '&amp;bug_status=ASSIGNED'
263     '&amp;bug_status=REOPENED'
264     % escape(pkg['name']))
265    
266     return '<a title="bugs.gentoo.org" href="%s">Bugs</a>' % url
267    
268 marduk 1.2 def bugs_to_html(package):
269     """Given package name (no version #s), return html text of bugs as
270     reported by bugzilla"""
271     # Right now we have an issue with the bugzilla site. New interface
272     # needs to be written, Bail out.
273 marduk 1.8 #return ""
274 marduk 1.2 import urllib2
275     url = ('http://bugs.gentoo.org/buglist.cgi?query_format='
276 marduk 1.8 '&amp;short_desc_type=allwords'
277     '&amp;short_desc=%s'
278     '&amp;bug_status=UNCONFIRMED'
279     '&amp;bug_status=NEW'
280     '&amp;bug_status=ASSIGNED'
281     '&amp;bug_status=REOPENED'
282     '&amp;ctype=csv'
283     % package)
284 marduk 1.2 fp = urllib2.urlopen(url)
285     factory = bugs.BugFactory()
286     package_bugs = factory.fromCSV(fp)
287     if package_bugs:
288     writer = bugs.HTMLWriter(package_bugs, 'bugs.gentoo.org')
289     return str(writer)
290     else:
291 marduk 1.8 return ""
292 marduk 1.2
293 marduk 1.8 def get_most_recent(db, max=config.MAXPERPAGE, arch="", branch="", new = False):
294 marduk 1.1 c = db.cursor()
295     extra = ''
296     if arch:
297     stable_extra = ('ebuild.arch REGEXP "^%s| %s" '
298     ' AND ebuild.prevarch NOT REGEXP"^%s| %s"'
299     % (arch,arch,arch,arch))
300     testing_extra = ('ebuild.arch REGEXP "^~%s| ~%s" '
301     ' AND ebuild.prevarch NOT REGEXP "^~%s| ~%s"'
302     % (arch,arch,arch,arch))
303     if branch == 'stable':
304     extra = ' AND (%s) ' % stable_extra
305     elif branch == 'testing':
306     extra = ' AND (%s) ' % testing_extra
307     else:
308     extra = ' AND ((%s) OR (%s)) ' % (stable_extra, testing_extra)
309 marduk 1.8
310     if new:
311     extra = ('%s AND package.new=1 ' % extra)
312    
313 marduk 1.1 query = """SELECT ebuild.category,ebuild.name,version,when_found,description,
314 marduk 1.8 changelog,arch,homepage,license,is_masked FROM ebuild,package WHERE ebuild.name=\
315 marduk 1.1 package.name AND ebuild.category=package.category %s ORDER by when_found DESC \
316     LIMIT %s""" % (extra,max)
317     c.execute(query)
318     results = c.fetchall()
319     return results
320    
321 marduk 1.8 def get_most_recent_bumps(db, max=config.MAXPERPAGE):
322     """Return most recent version bumps (pkgs with no prevarch)"""
323     c = db.cursor()
324     query = ('SELECT ebuild.category, ebuild.name, version, when_found, '
325     'description, changelog, arch, homepage, license,is_masked FROM ebuild, package '
326     'WHERE ebuild.name=package.name AND ebuild.category=package.category '
327     'AND prevarch="" AND version NOT LIKE "%%-r_" AND version NOT LIKE '
328     '"%%-r__" AND NOT new ORDER by when_found '
329     'DESC LIMIT %s' % max)
330    
331     c.execute(query)
332     results = c.fetchall()
333     return results
334    
335 marduk 1.1 def query_to_dict(d):
336 marduk 1.3 """Convert a SQL query to a dict"""
337 marduk 1.1 einfo = {}
338 marduk 1.3 keys = ('category', 'name', 'version', 'time', 'description', 'changelog',
339 marduk 1.8 'arch', 'homepage', 'license', 'masked')
340 marduk 1.1 for i in range(len(keys)):
341     try:
342     einfo[keys[i]] = d[i]
343     except IndexError:
344     continue
345     return einfo
346    
347 marduk 1.3 def get_recent_releases(pkg, db, max=config.MAX_RECENT_RELEASES):
348 marduk 1.1 """Return MAX_RECENT_RELEASES most recent releases for pkg. Returns and
349     ebuild-type dict"""
350     c = db.cursor()
351 marduk 1.3 query = ('SELECT category,name,version,when_found,NULL,changelog,arch ,'
352 marduk 1.8 'NULL,NULL,is_masked FROM ebuild WHERE name="%s" AND category="%s" ORDER BY '
353 marduk 1.3 'version DESC LIMIT %s' % (pkg['name'],pkg['category'],max))
354 marduk 1.1 c.execute(query)
355     results = c.fetchall()
356     #print results
357     return [ query_to_dict(i) for i in results ]
358 marduk 1.7
359     def cmp_ebuilds(a, b):
360     """Compare two ebuilds"""
361 marduk 1.8 fields_a = pkgsplit('%s-%s' % (a['name'], a['version']))
362     fields_b = pkgsplit('%s-%s' % (b['name'], b['version']))
363     return pkgcmp(fields_a, fields_b)
364    
365     pkgcache={}
366    
367     def pkgsplit(mypkg,silent=1):
368     try:
369     if not pkgcache[mypkg]:
370     return None
371     return pkgcache[mypkg][:]
372     except KeyError:
373     pass
374     myparts=string.split(mypkg,'-')
375     if len(myparts)<2:
376     if not silent:
377     print "!!! Name error in",mypkg+": missing a version or name part."
378     pkgcache[mypkg]=None
379     return None
380     for x in myparts:
381     if len(x)==0:
382     if not silent:
383     print "!!! Name error in",mypkg+": empty \"-\" part."
384     pkgcache[mypkg]=None
385     return None
386     #verify rev
387     revok=0
388     myrev=myparts[-1]
389     if len(myrev) and myrev[0]=="r":
390     try:
391     int(myrev[1:])
392     revok=1
393     except SystemExit, e:
394     raise
395     except:
396     pass
397     if revok:
398     if ververify(myparts[-2]):
399     if len(myparts)==2:
400     pkgcache[mypkg]=None
401     return None
402     else:
403     for x in myparts[:-2]:
404     if ververify(x):
405     pkgcache[mypkg]=None
406     return None
407     #names can't have versiony looking parts
408     myval=[string.join(myparts[:-2],"-"),myparts[-2],myparts[-1]]
409     pkgcache[mypkg]=myval
410     return myval
411     else:
412     pkgcache[mypkg]=None
413     return None
414    
415     elif ververify(myparts[-1],silent=silent):
416     if len(myparts)==1:
417     if not silent:
418     print "!!! Name error in",mypkg+": missing name part."
419     pkgcache[mypkg]=None
420     return None
421     else:
422     for x in myparts[:-1]:
423     if ververify(x):
424     if not silent:
425     print "!!! Name error in",mypkg+": multiple version parts."
426     pkgcache[mypkg]=None
427     return None
428     myval=[string.join(myparts[:-1],"-"),myparts[-1],"r0"]
429     pkgcache[mypkg]=myval[:]
430     return myval
431     else:
432     pkgcache[mypkg]=None
433     return None
434    
435     vercache={}
436     def ververify(myorigval,silent=1):
437     try:
438     return vercache[myorigval]
439     except KeyError:
440     pass
441     if len(myorigval)==0:
442     if not silent:
443     print "!!! Name error: package contains empty \"-\" part."
444     return 0
445     myval=string.split(myorigval,'.')
446     if len(myval)==0:
447     if not silent:
448     print "!!! Name error: empty version string."
449     vercache[myorigval]=0
450     return 0
451     #all but the last version must be a numeric
452     for x in myval[:-1]:
453     if not len(x):
454     if not silent:
455     print "!!! Name error in",myorigval+": two decimal points in a row"
456     vercache[myorigval]=0
457     return 0
458     try:
459     foo=int(x)
460     except SystemExit, e:
461     raise
462     except:
463     if not silent:
464     print "!!! Name error in",myorigval+": \""+x+"\" is not a valid version component."
465     vercache[myorigval]=0
466     return 0
467     if not len(myval[-1]):
468     if not silent:
469     print "!!! Name error in",myorigval+": two decimal points in a row"
470     vercache[myorigval]=0
471     return 0
472     try:
473     foo=int(myval[-1])
474     vercache[myorigval]=1
475     return 1
476     except SystemExit, e:
477     raise
478     except:
479     pass
480     #ok, our last component is not a plain number or blank, let's continue
481     if myval[-1][-1] in string.lowercase:
482     try:
483     foo=int(myval[-1][:-1])
484     vercache[myorigval]=1
485     return 1
486     # 1a, 2.0b, etc.
487     except SystemExit, e:
488     raise
489     except:
490     pass
491     #ok, maybe we have a 1_alpha or 1_beta2; let's see
492     #ep="endpart"
493     ep=string.split(myval[-1],"_")
494     if len(ep)!=2:
495     if not silent:
496     print "!!! Name error in",myorigval
497     vercache[myorigval]=0
498     return 0
499     try:
500     foo=int(ep[0][-1])
501     chk=ep[0]
502     except SystemExit, e:
503     raise
504     except:
505     # because it's ok last char is not numeric. example: foo-1.0.0a_pre1
506     chk=ep[0][:-1]
507    
508     try:
509     foo=int(chk)
510     except SystemExit, e:
511     raise
512     except:
513     #this needs to be numeric or numeric+single letter,
514     #i.e. the "1" in "1_alpha" or "1a_alpha"
515     if not silent:
516     print "!!! Name error in",myorigval+": characters before _ must be numeric or numeric+single letter"
517     vercache[myorigval]=0
518     return 0
519     for mye in endversion_keys:
520     if ep[1][0:len(mye)]==mye:
521     if len(mye)==len(ep[1]):
522     #no trailing numeric; ok
523     vercache[myorigval]=1
524     return 1
525     else:
526     try:
527     foo=int(ep[1][len(mye):])
528     vercache[myorigval]=1
529     return 1
530     except SystemExit, e:
531     raise
532     except:
533     #if no endversions work, *then* we return 0
534     pass
535     if not silent:
536     print "!!! Name error in",myorigval
537     vercache[myorigval]=0
538     return 0
539    
540     def relparse(myver):
541     "converts last version part into three components"
542     number=0
543     suffix=0
544     endtype=0
545     endnumber=0
546    
547     mynewver=string.split(myver,"_")
548     myver=mynewver[0]
549    
550     #normal number or number with letter at end
551     divider=len(myver)-1
552     if myver[divider:] not in "1234567890":
553     #letter at end
554     suffix=ord(myver[divider:])
555     number=string.atof(myver[0:divider])
556     else:
557     number=string.atof(myver)
558    
559     if len(mynewver)==2:
560     #an endversion
561     for x in endversion_keys:
562     elen=len(x)
563     if mynewver[1][:elen] == x:
564     match=1
565     endtype=endversion[x]
566     try:
567     endnumber=string.atof(mynewver[1][elen:])
568     except SystemExit, e:
569     raise
570     except:
571     endnumber=0
572     break
573     return [number,suffix,endtype,endnumber]
574    
575     # vercmp:
576     # ripped from portage.py to prevent having to import
577     vcmpcache={}
578     def vercmp(val1,val2):
579     if val1==val2:
580     #quick short-circuit
581     return 0
582     valkey=val1+" "+val2
583     try:
584     return vcmpcache[valkey]
585     try:
586     return -vcmpcache[val2+" "+val1]
587     except KeyError:
588     pass
589     except KeyError:
590     pass
591    
592     # consider 1_p2 vc 1.1
593     # after expansion will become (1_p2,0) vc (1,1)
594     # then 1_p2 is compared with 1 before 0 is compared with 1
595     # to solve the bug we need to convert it to (1,0_p2)
596     # by splitting _prepart part and adding it back _after_expansion
597     val1_prepart = val2_prepart = ''
598     if val1.count('_'):
599     val1, val1_prepart = val1.split('_', 1)
600     if val2.count('_'):
601     val2, val2_prepart = val2.split('_', 1)
602    
603     # replace '-' by '.'
604     # FIXME: Is it needed? can val1/2 contain '-'?
605     val1=string.split(val1,'-')
606     if len(val1)==2:
607     val1[0]=val1[0]+"."+val1[1]
608     val2=string.split(val2,'-')
609     if len(val2)==2:
610     val2[0]=val2[0]+"."+val2[1]
611    
612     val1=string.split(val1[0],'.')
613     val2=string.split(val2[0],'.')
614    
615     #add back decimal point so that .03 does not become "3" !
616     for x in range(1,len(val1)):
617     if val1[x][0] == '0' :
618     val1[x]='.' + val1[x]
619     for x in range(1,len(val2)):
620     if val2[x][0] == '0' :
621     val2[x]='.' + val2[x]
622    
623     # extend version numbers
624     if len(val2)<len(val1):
625     val2.extend(["0"]*(len(val1)-len(val2)))
626     elif len(val1)<len(val2):
627     val1.extend(["0"]*(len(val2)-len(val1)))
628    
629     # add back _prepart tails
630     if val1_prepart:
631     val1[-1] += '_' + val1_prepart
632     if val2_prepart:
633     val2[-1] += '_' + val2_prepart
634     #The above code will extend version numbers out so they
635     #have the same number of digits.
636     for x in range(0,len(val1)):
637     cmp1=relparse(val1[x])
638     cmp2=relparse(val2[x])
639     for y in range(0,4):
640     myret=cmp1[y]-cmp2[y]
641     if myret != 0:
642     vcmpcache[valkey]=myret
643     return myret
644     vcmpcache[valkey]=0
645     return 0
646    
647     # pkgcmp:
648     # ripped from portage.py to prevent having to import
649     def pkgcmp(pkg1,pkg2):
650     """if returnval is less than zero, then pkg2 is newer than pkg1, zero if equal and positive if older."""
651     if pkg1[0] != pkg2[0]:
652     return None
653     mycmp=vercmp(pkg1[1],pkg2[1])
654     if mycmp>0:
655     return 1
656     if mycmp<0:
657     return -1
658     r1=int(pkg1[2][1:])
659     r2=int(pkg2[2][1:])
660     if r1>r2:
661     return 1
662     if r2>r1:
663     return -1
664     return 0
665 marduk 1.7
666 marduk 1.3 def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""):
667 marduk 1.1 """write out ebuild info to RSS file (fp)"""
668 marduk 1.9 fp.write("""<?xml version="1.0" encoding="UTF-8"?>
669 marduk 1.1 <rss version="0.92">
670     <channel>
671 marduk 1.7 <title>packages.gentoo.org [ %s ]</title>
672 marduk 1.1 <link>%s</link>
673     <description>Latest ebuilds from the Gentoo Linux portage tree</description>
674     <webMaster>www@gentoo.org</webMaster>
675     <managingEditor>marduk@gentoo.org</managingEditor>
676 marduk 1.8 <pubDate>%s</pubDate>""" % (subtitle,config.FEHOME,
677 marduk 1.1 time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())))
678    
679     for ebuild in ebuilds:
680     if simple:
681     description = escape(ebuild['description'])
682     else:
683 marduk 1.8 description = ('\n'
684     '<![CDATA[\n'
685     '<link rel="stylesheet" type="text/css" href="%s"></link>\n'
686     '%s\n]]>' % (config.STYLESHEET, ebuild_to_html(ebuild, full=True))
687     )
688 marduk 1.1
689     fp.write("""<item>
690     <title>%s %s</title>
691     <link>%sebuilds/?%s-%s</link>
692     <description>
693     %s
694     </description>
695     <pubDate>%s</pubDate>
696     </item>
697     """ % (ebuild['name'],
698     ebuild['version'],
699     config.FEHOME,
700     ebuild['name'],
701     ebuild['version'],
702     description,
703     ebuild['time'].gmtime().strftime("%a, %d %b %Y %H:%M:%S +0000"))
704     )
705    
706     fp.write("</channel>\n</rss>\n")
707    
708 marduk 1.6 def main(argv=None):
709     if argv is None:
710     argv = sys.argv
711 marduk 1.1 try:
712 marduk 1.5 if argv[1] == '-g':
713 marduk 1.1 ebuilddb.main()
714     except IndexError:
715 marduk 1.3 pass
716 marduk 1.2
717 marduk 1.1 db = ebuilddb.db_connect()
718 marduk 1.3 branches = ('', 'stable', 'testing')
719 marduk 1.1 for arch in [''] + config.ARCHLIST:
720     for branch in branches:
721 marduk 1.3 fullpath = os.path.join(config.LOCALHOME, "archs", arch, branch,
722     config.INDEX)
723 marduk 1.1 index = open(fullpath,'w')
724     if arch:
725     sarch = arch
726     else:
727     sarch = 'all'
728     if branch:
729     sbranch = branch
730     else:
731     sbranch = 'all'
732    
733     index.write("""<table border="0" cellpadding="0" cellspacing="5"
734     width="100%">\n""")
735     index.write("""<tr><td valign="top">\n""")
736 marduk 1.3 index.write('<!--#include file="archnav.html" -->\n\n</td></tr>\n'
737     '<tr><td>')
738     results = get_most_recent(db, arch=arch, branch=branch)
739 marduk 1.1 ebuilds = [ query_to_dict(i) for i in results ]
740     for ebuild in ebuilds:
741 marduk 1.3 new = is_new(db, ebuild)
742 marduk 1.1 pkgfilename = "%s/%s-%s.html" % (
743     config.EBUILD_FILES,ebuild['name'],ebuild['version'])
744 marduk 1.8 ebuild_html = ebuild_to_html(ebuild, new, show_bugs = False)
745 marduk 1.3 if arch == '' and branch == '':
746 marduk 1.1 pkgfile = open(pkgfilename,'w')
747     pkgfile.write(ebuild_html)
748     pkgfile.close()
749 marduk 1.3 ebuildfilename = "%s/%s/%s/%s-%s.ebuild" \
750     % (ebuilddb.config.PORTAGE_DIR,
751 marduk 1.1 ebuild['category'],ebuild['name'],ebuild['name'],
752     ebuild['version'])
753 marduk 1.2 os.system('touch -r %s %s || touch -d "today -1 year" %s'
754     % (ebuildfilename,pkgfilename,pkgfilename))
755 marduk 1.1
756     try:
757 marduk 1.2 index.write('%s\n\n' % (ebuild_html))
758 marduk 1.1 except IOError:
759 marduk 1.3 continue
760 marduk 1.1 index.write("""</table>\n""")
761     index.close()
762    
763 marduk 1.3 subtitle = ' %s %s' % (arch, branch)
764     rss = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
765     config.RSS), 'w')
766     ebuilds_to_rss(rss, ebuilds, simple=False, subtitle=subtitle)
767 marduk 1.1 rss.close()
768    
769 marduk 1.3 rss2 = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
770     config.RSS2), 'w')
771     ebuilds_to_rss(rss2, ebuilds, simple=True, subtitle=subtitle)
772 marduk 1.1 rss.close()
773 marduk 1.5
774     if __name__ == '__main__':
775     sys.exit(main())

  ViewVC Help
Powered by ViewVC 1.1.20