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

Contents of /src/packages/gentoo.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16.2.4 - (hide annotations) (download) (as text)
Sat Mar 3 19:39:30 2007 UTC (7 years, 1 month ago) by marduk
Branch: v1_3
Changes since 1.16.2.3: +3 -3 lines
File MIME type: text/x-python
Changed RSS verbage (emerge -Ss no longer applies)

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.2.4 __revision__ = "$Revision: 1.16.2.3 $"
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 marduk 1.16.2.3 from portage_versions import pkgcmp, pkgsplit
19 marduk 1.2
20 marduk 1.3 def is_new(db, ebuild):
21 marduk 1.8 """Check for newness."""
22 marduk 1.11
23 marduk 1.1 c = db.cursor()
24 marduk 1.8 query = ('SELECT new FROM package WHERE category="%s" AND name="%s"'
25 marduk 1.2 % (ebuild['category'], ebuild['name']))
26 marduk 1.1 c.execute(query)
27     results = c.fetchall()
28 marduk 1.8 if len(results) == 1 and results[0][0]:
29 marduk 1.1 return 1
30     return 0
31    
32 marduk 1.15 changelog_to_html = changelogs.bugs_to_html
33 marduk 1.2
34     def homepage_to_html(homepage):
35     """convert HOMEPAGE entry to HTML"""
36 marduk 1.11 if not homepage.strip():
37 marduk 1.3 return "?"
38 marduk 1.2 homepage = homepage.replace('|',' ')
39     pieces = homepage.split()
40     count = len(pieces)
41     if count == 1:
42     return ('<a class="homepage" href="%s">'
43     'Homepage</a>' % pieces[0])
44 marduk 1.11
45 marduk 1.2 html = ['[<a href="%s">%s</a>]' % (page, index + 1) for index,
46     page in enumerate(pieces)]
47 marduk 1.11 return " ".join(['<span class="homepage">Homepages'] + html +
48 marduk 1.2 ['</span>'])
49    
50     def license_to_html(license):
51 marduk 1.3 """Create link to license[s]"""
52 marduk 1.2 if not license.strip(): return "?"
53     license = license.replace('|',' ')
54 marduk 1.8 license = license.replace('(', '')
55     license = license.replace(')', '')
56 marduk 1.2 pieces = license.split()
57 marduk 1.16.2.2 html = ['<a href="http://sources.gentoo.org/viewcvs.py/*checkout*/'
58     'gentoo-x86/licenses/%s">%s</a>' % (piece, piece) for piece in pieces]
59 marduk 1.2 return '<br>\n'.join(html)
60 marduk 1.1
61 marduk 1.8 def package_to_html(pkginfo, db, full=False):
62 marduk 1.11 """This function needs a database (db) connection because it performs a
63 marduk 1.3 query_to_dict on the package"""
64 marduk 1.11
65 marduk 1.2 table_begin = '<table class="ebuild">'
66     name = '<tr><td class="fields">%s</td></tr>' % pkginfo['name']
67 marduk 1.8 if full:
68     image = ('<img class="pkgimg"alt="" src="%s/%s/%s.jpg" align="right">' %
69     (config.ICONS, pkginfo['category'], pkginfo['name'])
70     )
71     else:
72     image = ''
73 marduk 1.2 description = ('<tr><td class="item">'
74 marduk 1.11 '%s<b>Description: </b>%s</td></tr>'
75 marduk 1.8 % (image, escape(pkginfo['description']))
76     )
77 marduk 1.3 ebuilds = get_recent_releases(pkginfo, db)
78 marduk 1.2 releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases')
79 marduk 1.11 #bug_string = ('<br><h3>Related bugs:</h3>\n%s'
80 marduk 1.2 # % bugs_to_html(pkginfo['name']))
81     general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo)
82 marduk 1.11 #similar = '<tr><td>%s</td></tr>' % create_similar_pkgs_link(pkginfo)
83 marduk 1.2 table_end = '</table>'
84     rows = '\n\t'.join([name, description, releases, general])
85     return '\n\t'.join([table_begin, rows, table_end])
86    
87     def archs_to_html(ebuilds, heading = None):
88 marduk 1.3 """Create table for availability on each architecture"""
89 marduk 1.2 heading = heading or '&nbsp;'
90     table_begin = '<table class="releases">'
91     header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] +
92 marduk 1.7 ['<th class="arch">%s</th>' % i.replace('-',' ') for i in config.ARCHLIST] +
93 marduk 1.2 ['</tr>']
94     )
95     rows = []
96 marduk 1.7 ebuilds.sort(cmp_ebuilds)
97     ebuilds.reverse()
98 marduk 1.2 for ebuild in ebuilds:
99 marduk 1.16 archs = ebuild['arch'].split(',')
100 marduk 1.2 row_start = ('<tr>\n\t<th class="releases"><a href="%sebuilds/?%s-%s"'
101 marduk 1.11 ' title="%s">%s</a></th>\n' % (config.FEHOME,
102     ebuild['name'], ebuild['version'], ebuild['time'],
103 marduk 1.2 ebuild['version']))
104     row_data = []
105     for arch in config.ARCHLIST:
106     if arch in archs:
107     arch_string = '+'
108     elif '~%s' % arch in archs:
109     arch_string = '~'
110     else:
111     arch_string = '-'
112 marduk 1.8 if arch_string != '-' and ebuild['masked']:
113 marduk 1.2 arch_string = 'M' + arch_string
114     row_data.append('\t<td class="archcell" arch="%s">%s</td>'
115     % (arch_string, arch_string))
116     row_end = '</tr>'
117     rows.append('\n\t'.join([row_start] + row_data + [row_end]))
118     table_end = '</table>'
119     return '\n\t'.join([table_begin] + [header_row] + rows + [table_end])
120 marduk 1.11
121 marduk 1.8 def ebuild_to_html(ebinfo, new=0, show_bugs=0, full = False):
122 marduk 1.3 """Convert ebuild (dict) to html, if new, print out a "this is new" notice
123     if show_bugs, show bugs for this particular ebuild (requires access to
124     bugzilla"""
125 marduk 1.1 if new:
126     new_string = """ &nbsp;&nbsp;<span class="new">new!</span> """
127     else:
128     new_string = ""
129 marduk 1.11
130 marduk 1.2 table_begin = '<table class="ebuild">'
131     name_and_date = ('<tr><td class="fields">'
132 marduk 1.1 '<a href="%spackages/?category=%s;name=%s">%s</a> %s%s<br>'
133 marduk 1.2 '<span class="time">%s</span>'
134     '</td></tr>' % (config.FEHOME, quote(ebinfo['category']),
135     quote(ebinfo['name']),
136     ebinfo['name'],
137     ebinfo['version'],
138     new_string,
139 marduk 1.14 ebinfo['time'].strftime("%c %Z")))
140 marduk 1.11
141 marduk 1.8 if full:
142     image = ('<img class="pkgimg" alt="" src="%s/%s/%s.jpg" align="right">' %
143     (config.ICONS, ebinfo['category'], ebinfo['name'])
144     )
145     else:
146     image = ''
147 marduk 1.2 desc_and_changes = ('<tr><td class="item" valign="top">'
148 marduk 1.8 '<p><b>Description:</b> %s %s</p>'
149 marduk 1.2 '<p><b>Changes:</b><br>'
150     '%s</p></td></tr>' % (
151     escape(ebinfo['description']),
152 marduk 1.8 image,
153 marduk 1.2 changelog_to_html(ebinfo['changelog'])))
154    
155     archs = '<tr><td>%s</td></tr>' % archs_to_html([ebinfo])
156     general = '<tr><td>%s</td></tr>' % general_info_to_html(ebinfo)
157     table_end = '</table>'
158 marduk 1.11
159 marduk 1.8 bug_string = ''
160     if show_bugs:
161     bug_string = bugs_to_html(ebinfo['name'])
162     if bug_string:
163     bug_string = '<br><h3 class="bugs">Related bugs:</h3>%s' \
164     % bug_string
165 marduk 1.11
166     return '\n\t'.join([table_begin,
167     name_and_date,
168     desc_and_changes,
169 marduk 1.2 archs,
170 marduk 1.11 general,
171     table_end,
172 marduk 1.2 bug_string])
173 marduk 1.11
174 marduk 1.1 def general_info_to_html(pkg):
175     """This actually will (should) take either a package or ebuild dict
176     as an argument"""
177 marduk 1.11
178 marduk 1.8 import forums
179 marduk 1.11
180 marduk 1.16.2.2 changelogurl = ('http://sources.gentoo.org/viewcvs.py/*checkout*/'
181     'gentoo-x86/%s/%s/ChangeLog' % (pkg['category'],pkg['name']))
182 marduk 1.2 cat_header = '<th class="category">Category</th>'
183     license_header = '<th class="license">License</th>'
184     category = ('<td class="category">'
185 marduk 1.11 '<a href="%spackages/?category=%s">%s</a></td>' % (config.FEHOME,
186 marduk 1.2 pkg['category'], pkg['category']))
187 marduk 1.11 homepage = ('<td class="homepage" rowspan="2">%s</td>'
188 marduk 1.2 % homepage_to_html(pkg['homepage']))
189 marduk 1.11 license = ('<td class="license">%s</td>'
190 marduk 1.2 % license_to_html(pkg['license']))
191     changelog = ('<td class="changelog" rowspan="2">'
192 marduk 1.7 '<a href="%s">ChangeLog</a></td>' % changelogurl)
193     similar = ('<td class="similar" rowspan="2">'
194     '%s</td>' % create_similar_pkgs_link(pkg))
195 marduk 1.8 related_bugs = ('<td class="related_bugs" rowspan="2">'
196     '%s</td>' % create_related_bugs_link(pkg))
197     forums = ('<td class="forums" rowspan="2">'
198     '%s</td>' % forums.create_forums_link(pkg))
199 marduk 1.11
200 marduk 1.2 return '\n\t'.join(['<table class="general_info">',
201     '<tr>',
202     cat_header,
203     homepage,
204     license_header,
205     changelog,
206 marduk 1.7 similar,
207 marduk 1.8 related_bugs,
208     forums,
209 marduk 1.2 '</tr>',
210     '<tr>',
211     category,
212     license,
213     '</tr>',
214     '</table>'])
215 marduk 1.11
216 marduk 1.7 def create_similar_pkgs_link(pkg):
217     """Create a link to similar packages"""
218 marduk 1.11
219 marduk 1.16.2.1 return '<a href="/similar/?package=%(category)s/%(name)s">Similar</a>' % pkg
220 marduk 1.11
221 marduk 1.8 def create_related_bugs_link(pkg):
222     """Create a link to related bugs"""
223 marduk 1.11
224 marduk 1.8 url = ('http://bugs.gentoo.org/buglist.cgi?query_format='
225     '&amp;short_desc_type=allwords'
226     '&amp;short_desc=%s'
227     '&amp;bug_status=UNCONFIRMED'
228     '&amp;bug_status=NEW'
229     '&amp;bug_status=ASSIGNED'
230 marduk 1.11 '&amp;bug_status=REOPENED'
231 marduk 1.8 % escape(pkg['name']))
232 marduk 1.11
233 marduk 1.8 return '<a title="bugs.gentoo.org" href="%s">Bugs</a>' % url
234 marduk 1.11
235 marduk 1.2 def bugs_to_html(package):
236     """Given package name (no version #s), return html text of bugs as
237     reported by bugzilla"""
238     # Right now we have an issue with the bugzilla site. New interface
239     # needs to be written, Bail out.
240 marduk 1.8 #return ""
241 marduk 1.2 import urllib2
242     url = ('http://bugs.gentoo.org/buglist.cgi?query_format='
243 marduk 1.8 '&amp;short_desc_type=allwords'
244     '&amp;short_desc=%s'
245     '&amp;bug_status=UNCONFIRMED'
246     '&amp;bug_status=NEW'
247     '&amp;bug_status=ASSIGNED'
248     '&amp;bug_status=REOPENED'
249 marduk 1.11 '&amp;ctype=csv'
250 marduk 1.8 % package)
251 marduk 1.2 fp = urllib2.urlopen(url)
252     factory = bugs.BugFactory()
253     package_bugs = factory.fromCSV(fp)
254     if package_bugs:
255     writer = bugs.HTMLWriter(package_bugs, 'bugs.gentoo.org')
256     return str(writer)
257     else:
258 marduk 1.8 return ""
259 marduk 1.11
260 marduk 1.8 def get_most_recent(db, max=config.MAXPERPAGE, arch="", branch="", new = False):
261 marduk 1.1 c = db.cursor()
262     extra = ''
263     if arch:
264 marduk 1.16 stable_extra = ('FIND_IN_SET("%s", ebuild.arch) > 0 AND '
265     'FIND_IN_SET("%s", ebuild.prevarch) = 0 ' % (arch, arch))
266     testing_extra = ('FIND_IN_SET("~%s", ebuild.arch) > 0 AND '
267     'FIND_IN_SET("~%s", ebuild.prevarch) = 0 ' % (arch, arch))
268 marduk 1.1 if branch == 'stable':
269     extra = ' AND (%s) ' % stable_extra
270     elif branch == 'testing':
271     extra = ' AND (%s) ' % testing_extra
272     else:
273     extra = ' AND ((%s) OR (%s)) ' % (stable_extra, testing_extra)
274 marduk 1.11
275 marduk 1.8 if new:
276     extra = ('%s AND package.new=1 ' % extra)
277 marduk 1.11
278 marduk 1.16.2.1 query = """SELECT ebuild.category,ebuild.name,version,ebuild.when_found,description,
279 marduk 1.8 changelog,arch,homepage,license,is_masked FROM ebuild,package WHERE ebuild.name=\
280 marduk 1.16.2.1 package.name AND ebuild.category=package.category %s ORDER by ebuild.when_found DESC \
281 marduk 1.1 LIMIT %s""" % (extra,max)
282     c.execute(query)
283     results = c.fetchall()
284     return results
285 marduk 1.11
286 marduk 1.8 def get_most_recent_bumps(db, max=config.MAXPERPAGE):
287     """Return most recent version bumps (pkgs with no prevarch)"""
288     c = db.cursor()
289     query = ('SELECT ebuild.category, ebuild.name, version, when_found, '
290     'description, changelog, arch, homepage, license,is_masked FROM ebuild, package '
291     'WHERE ebuild.name=package.name AND ebuild.category=package.category '
292     'AND prevarch="" AND version NOT LIKE "%%-r_" AND version NOT LIKE '
293     '"%%-r__" AND NOT new ORDER by when_found '
294     'DESC LIMIT %s' % max)
295 marduk 1.11
296 marduk 1.8 c.execute(query)
297     results = c.fetchall()
298     return results
299 marduk 1.11
300 marduk 1.1 def query_to_dict(d):
301 marduk 1.3 """Convert a SQL query to a dict"""
302 marduk 1.1 einfo = {}
303 marduk 1.3 keys = ('category', 'name', 'version', 'time', 'description', 'changelog',
304 marduk 1.8 'arch', 'homepage', 'license', 'masked')
305 marduk 1.1 for i in range(len(keys)):
306     try:
307     einfo[keys[i]] = d[i]
308     except IndexError:
309     continue
310     return einfo
311    
312 marduk 1.3 def get_recent_releases(pkg, db, max=config.MAX_RECENT_RELEASES):
313 marduk 1.1 """Return MAX_RECENT_RELEASES most recent releases for pkg. Returns and
314     ebuild-type dict"""
315     c = db.cursor()
316 marduk 1.3 query = ('SELECT category,name,version,when_found,NULL,changelog,arch ,'
317 marduk 1.8 'NULL,NULL,is_masked FROM ebuild WHERE name="%s" AND category="%s" ORDER BY '
318 marduk 1.3 'version DESC LIMIT %s' % (pkg['name'],pkg['category'],max))
319 marduk 1.1 c.execute(query)
320     results = c.fetchall()
321     #print results
322     return [ query_to_dict(i) for i in results ]
323 marduk 1.7
324     def cmp_ebuilds(a, b):
325     """Compare two ebuilds"""
326 marduk 1.8 fields_a = pkgsplit('%s-%s' % (a['name'], a['version']))
327     fields_b = pkgsplit('%s-%s' % (b['name'], b['version']))
328     return pkgcmp(fields_a, fields_b)
329    
330 marduk 1.3 def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""):
331 marduk 1.1 """write out ebuild info to RSS file (fp)"""
332 marduk 1.11
333     # web link for RSS feed
334     if subtitle:
335     link = '%s/%s' % (config.FEHOME, subtitle.replace(' ','/',1))
336     else:
337     link = config.FEHOME
338    
339     pubDate = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
340 marduk 1.9 fp.write("""<?xml version="1.0" encoding="UTF-8"?>
341 marduk 1.11 <rss version="2.0">
342 marduk 1.1 <channel>
343 marduk 1.7 <title>packages.gentoo.org [ %s ]</title>
344 marduk 1.1 <link>%s</link>
345     <description>Latest ebuilds from the Gentoo Linux portage tree</description>
346     <webMaster>www@gentoo.org</webMaster>
347 marduk 1.11
348     <image>
349     <title>Online Package Database</title>
350     <url>%s</url>
351     <link>%s</link>
352     </image>
353    
354 marduk 1.1 <managingEditor>marduk@gentoo.org</managingEditor>
355 marduk 1.14 <pubDate>%s</pubDate>""" % (subtitle, link, config.RSS_IMAGE,
356 marduk 1.11 config.FEHOME, pubDate))
357 marduk 1.1
358     for ebuild in ebuilds:
359     if simple:
360     description = escape(ebuild['description'])
361     else:
362 marduk 1.8 description = ('\n'
363 marduk 1.11 '<![CDATA[\n'
364     '<link rel="stylesheet" type="text/css" href="%s"></link>\n'
365     '%s\n]]>' % (config.STYLESHEET, ebuild_to_html(ebuild, full=True))
366     )
367 marduk 1.1
368     fp.write("""<item>
369 marduk 1.12 <title>%s/%s %s</title>
370 marduk 1.1 <link>%sebuilds/?%s-%s</link>
371     <description>
372     %s
373     </description>
374     <pubDate>%s</pubDate>
375     </item>
376 marduk 1.12 """ % (ebuild['category'],
377     ebuild['name'],
378 marduk 1.1 ebuild['version'],
379     config.FEHOME,
380     ebuild['name'],
381     ebuild['version'],
382     description,
383 marduk 1.14 ebuild['time'].strftime("%a, %d %b %Y %H:%M:%S +0000"))
384 marduk 1.1 )
385 marduk 1.11
386     fp.write("\n\
387 marduk 1.13 <textInput>\n\
388 marduk 1.16.2.4 <title>Search</title>\n\
389 marduk 1.11 <link>%s/search/</link>\n\
390 marduk 1.16.2.4 <description>Search the Online Package Database</description>\n\
391 marduk 1.11 <name>sstring</name>\n\
392 marduk 1.13 </textInput>\n\
393 marduk 1.11 </channel>\n\
394     </rss>\n" % config.FEHOME)
395    
396 marduk 1.6 def main(argv=None):
397     if argv is None:
398     argv = sys.argv
399 marduk 1.1 try:
400 marduk 1.5 if argv[1] == '-g':
401 marduk 1.1 ebuilddb.main()
402     except IndexError:
403 marduk 1.3 pass
404 marduk 1.11
405 marduk 1.1 db = ebuilddb.db_connect()
406 marduk 1.3 branches = ('', 'stable', 'testing')
407 marduk 1.1 for arch in [''] + config.ARCHLIST:
408     for branch in branches:
409 marduk 1.11 fullpath = os.path.join(config.LOCALHOME, "archs", arch, branch,
410 marduk 1.3 config.INDEX)
411 marduk 1.1 index = open(fullpath,'w')
412 marduk 1.11
413     index.write("""<table border="0" cellpadding="0" cellspacing="5"
414 marduk 1.1 width="100%">\n""")
415     index.write("""<tr><td valign="top">\n""")
416 marduk 1.3 index.write('<!--#include file="archnav.html" -->\n\n</td></tr>\n'
417 marduk 1.11 '<tr><td>')
418 marduk 1.3 results = get_most_recent(db, arch=arch, branch=branch)
419 marduk 1.1 ebuilds = [ query_to_dict(i) for i in results ]
420     for ebuild in ebuilds:
421 marduk 1.3 new = is_new(db, ebuild)
422 marduk 1.1 pkgfilename = "%s/%s-%s.html" % (
423     config.EBUILD_FILES,ebuild['name'],ebuild['version'])
424 marduk 1.8 ebuild_html = ebuild_to_html(ebuild, new, show_bugs = False)
425 marduk 1.3 if arch == '' and branch == '':
426 marduk 1.1 pkgfile = open(pkgfilename,'w')
427     pkgfile.write(ebuild_html)
428     pkgfile.close()
429 marduk 1.3 ebuildfilename = "%s/%s/%s/%s-%s.ebuild" \
430     % (ebuilddb.config.PORTAGE_DIR,
431 marduk 1.1 ebuild['category'],ebuild['name'],ebuild['name'],
432     ebuild['version'])
433 marduk 1.11 os.system('touch -r %s %s || touch -d "today -1 year" %s'
434 marduk 1.2 % (ebuildfilename,pkgfilename,pkgfilename))
435 marduk 1.11
436 marduk 1.1 try:
437 marduk 1.2 index.write('%s\n\n' % (ebuild_html))
438 marduk 1.1 except IOError:
439 marduk 1.3 continue
440 marduk 1.1 index.write("""</table>\n""")
441     index.close()
442 marduk 1.11
443 marduk 1.3 subtitle = ' %s %s' % (arch, branch)
444     rss = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
445     config.RSS), 'w')
446     ebuilds_to_rss(rss, ebuilds, simple=False, subtitle=subtitle)
447 marduk 1.1 rss.close()
448 marduk 1.11
449 marduk 1.3 rss2 = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
450     config.RSS2), 'w')
451     ebuilds_to_rss(rss2, ebuilds, simple=True, subtitle=subtitle)
452 marduk 1.1 rss.close()
453 marduk 1.5
454     if __name__ == '__main__':
455     sys.exit(main())

  ViewVC Help
Powered by ViewVC 1.1.20