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

Contents of /src/packages/gentoo.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16.2.5 - (show annotations) (download) (as text)
Mon Mar 26 18:00:10 2007 UTC (7 years, 6 months ago) by marduk
Branch: v1_3
Changes since 1.16.2.4: +3 -4 lines
File MIME type: text/x-python
Remove unused import (string). module name re-assigned as variable (forums)
in general_info_to_html()

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

  ViewVC Help
Powered by ViewVC 1.1.20