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

Contents of /src/packages/gentoo.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (hide annotations) (download) (as text)
Mon Oct 17 05:45:08 2005 UTC (8 years, 8 months ago) by marduk
Branch: MAIN
CVS Tags: v1_3_1, HEAD
Branch point for: v1_3
Changes since 1.15: +6 -5 lines
File MIME type: text/x-python
Backported arch/prevarch db format from pre_2-0

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

  ViewVC Help
Powered by ViewVC 1.1.20