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

Diff of /src/packages/gentoo.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.3
1#!/usr/bin/python -OO 1#!/usr/bin/python -OO
2"""These functions mainly take ebuild info (grabbed from the database and 2"""These functions mainly take ebuild info (grabbed from the database and
3 convert it to HTML. See the "main" function at the bottom.""" 3 convert it to HTML. See the "main" function at the bottom."""
4 4
5__version__ = "$Revision: 1.2 $" 5__revision__ = "$Revision: 1.3 $"
6# $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $" 6# $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $
7 7
8import config 8import config
9import os 9import os
10import time 10import time
11import sys 11import sys
14import changelogs 14import changelogs
15from cgi import escape 15from cgi import escape
16from urllib import quote 16from urllib import quote
17 17
18# import portage, but temporarily redirect stderr 18# import portage, but temporarily redirect stderr
19try: 19if 'portage' not in dir():
20 portage
21except NameError:
22 null = open('/dev/null', 'w') 20 null = open('/dev/null', 'w')
23 tmp = sys.stderr 21 tmp = sys.stderr
24 sys.stderr = null 22 sys.stderr = null
25 sys.path = ["/usr/lib/portage/pym"]+sys.path 23 sys.path = ["/usr/lib/portage/pym"]+sys.path
26 import portage 24 import portage
27 sys.stderr = tmp 25 sys.stderr = tmp
26 sys.path = sys.path[1:]
28 27
29tree = portage.portdbapi('/usr/portage') 28tree = portage.portdbapi('/usr/portage')
30 29
31def is_masked(ebuild): 30def is_masked(ebuild):
32 """Return true if ebuild is masked""" 31 """Return true if ebuild is masked"""
33 32
34 return (not tree.visible(['%(category)s/%(name)s-%(version)s' % ebuild])) 33 return (not tree.visible(['%(category)s/%(name)s-%(version)s' % ebuild]))
35 34
36def is_new(db,ebuild): 35def is_new(db, ebuild):
37 """Check for newness. An ebuild is considered new if it is the 36 """Check for newness. An ebuild is considered new if it is the
38 only ebuild with that category/name in ebuild and it has no prevarch""" 37 only ebuild with that category/name in ebuild and it has no prevarch"""
39 38
40 c = db.cursor() 39 c = db.cursor()
41 query = ('SELECT prevarch FROM ebuild WHERE category="%s" AND name="%s"' 40 query = ('SELECT prevarch FROM ebuild WHERE category="%s" AND name="%s"'
57 html = changelogs.bugs_to_html(html) 56 html = changelogs.bugs_to_html(html)
58 return html 57 return html
59 58
60def homepage_to_html(homepage): 59def homepage_to_html(homepage):
61 """convert HOMEPAGE entry to HTML""" 60 """convert HOMEPAGE entry to HTML"""
62 if not homepage.strip(): return "?" 61 if not homepage.strip():
62 return "?"
63 homepage = homepage.replace('|',' ') 63 homepage = homepage.replace('|',' ')
64 pieces = homepage.split() 64 pieces = homepage.split()
65 count = len(pieces) 65 count = len(pieces)
66 if count == 1: 66 if count == 1:
67 return ('<a class="homepage" href="%s">' 67 return ('<a class="homepage" href="%s">'
71 page in enumerate(pieces)] 71 page in enumerate(pieces)]
72 return " ".join(['<span class="homepage">Homepages'] + html + 72 return " ".join(['<span class="homepage">Homepages'] + html +
73 ['</span>']) 73 ['</span>'])
74 74
75def license_to_html(license): 75def license_to_html(license):
76 """Create link to license[s]"""
76 if not license.strip(): return "?" 77 if not license.strip(): return "?"
77 license = license.replace('|',' ') 78 license = license.replace('|',' ')
78 pieces = license.split() 79 pieces = license.split()
79 html = ['<a href="http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/' 80 html = ['<a href="http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/'
80 'licenses/%s">%s</a>' % (piece, piece) for piece in pieces] 81 'licenses/%s">%s</a>' % (piece, piece) for piece in pieces]
81 return '<br>\n'.join(html) 82 return '<br>\n'.join(html)
82 83
83def package_to_html(pkginfo,db): 84def package_to_html(pkginfo, db):
84 """This function needs a database (db) connection because it performs a query_to_dict 85 """This function needs a database (db) connection because it performs a
85 on the package""" 86 query_to_dict on the package"""
86 87
87 table_begin = '<table class="ebuild">' 88 table_begin = '<table class="ebuild">'
88 name = '<tr><td class="fields">%s</td></tr>' % pkginfo['name'] 89 name = '<tr><td class="fields">%s</td></tr>' % pkginfo['name']
89 description = ('<tr><td class="item">' 90 description = ('<tr><td class="item">'
90 '<img align="right" alt="" src="%s/%s.png">' 91 '<img align="right" alt="" src="%s/%s.png">'
91 '<b>Description: </b>%s</td></tr>' % (config.ICONS, 92 '<b>Description: </b>%s</td></tr>' % (config.ICONS,
92 pkginfo['category'], escape(pkginfo['description']))) 93 pkginfo['category'], escape(pkginfo['description'])))
93 ebuilds = get_recent_releases(pkginfo,db) 94 ebuilds = get_recent_releases(pkginfo, db)
94 releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases') 95 releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases')
95 bug_string = ''
96 #bug_string = ('<br><h3>Related bugs:</h3>\n%s' 96 #bug_string = ('<br><h3>Related bugs:</h3>\n%s'
97 # % bugs_to_html(pkginfo['name'])) 97 # % bugs_to_html(pkginfo['name']))
98 general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo) 98 general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo)
99 table_end = '</table>' 99 table_end = '</table>'
100 rows = '\n\t'.join([name, description, releases, general]) 100 rows = '\n\t'.join([name, description, releases, general])
101 return '\n\t'.join([table_begin, rows, table_end]) 101 return '\n\t'.join([table_begin, rows, table_end])
102 102
103def archs_to_html(ebuilds, heading = None): 103def archs_to_html(ebuilds, heading = None):
104 """Create table for availability on each architecture"""
104 heading = heading or '&nbsp;' 105 heading = heading or '&nbsp;'
105 table_begin = '<table class="releases">' 106 table_begin = '<table class="releases">'
106 header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] + 107 header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] +
107 ['<th class="arch">%s</th>' % i for i in config.ARCHLIST] + 108 ['<th class="arch">%s</th>' % i for i in config.ARCHLIST] +
108 ['</tr>'] 109 ['</tr>']
131 rows.append('\n\t'.join([row_start] + row_data + [row_end])) 132 rows.append('\n\t'.join([row_start] + row_data + [row_end]))
132 table_end = '</table>' 133 table_end = '</table>'
133 return '\n\t'.join([table_begin] + [header_row] + rows + [table_end]) 134 return '\n\t'.join([table_begin] + [header_row] + rows + [table_end])
134 135
135def ebuild_to_html(ebinfo, new=0, show_bugs=0): 136def ebuild_to_html(ebinfo, new=0, show_bugs=0):
137 """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"""
136 if new: 140 if new:
137 new_string = """ &nbsp;&nbsp;<span class="new">new!</span> """ 141 new_string = """ &nbsp;&nbsp;<span class="new">new!</span> """
138 else: 142 else:
139 new_string = "" 143 new_string = ""
140 144
164 table_end = '</table>' 168 table_end = '</table>'
165 169
166 if 1 == 1: 170 if 1 == 1:
167 bug_string = '' 171 bug_string = ''
168 else: 172 else:
169 bug_string = '<br><h3>Related bugs:</h3>%s' % bugs_to_html(ebinfo['name']) 173 bug_string = '<br><h3>Related bugs:</h3>%s' \
174 % bugs_to_html(ebinfo['name'])
170 175
171 return '\n\t'.join([table_begin, 176 return '\n\t'.join([table_begin,
172 name_and_date, 177 name_and_date,
173 desc_and_changes, 178 desc_and_changes,
174 archs, 179 archs,
226 writer = bugs.HTMLWriter(package_bugs, 'bugs.gentoo.org') 231 writer = bugs.HTMLWriter(package_bugs, 'bugs.gentoo.org')
227 return str(writer) 232 return str(writer)
228 else: 233 else:
229 return "None" 234 return "None"
230 235
231def get_most_recent(db,max=config.MAXPERPAGE,arch="",branch=""): 236def get_most_recent(db, max=config.MAXPERPAGE, arch="", branch=""):
232 c = db.cursor() 237 c = db.cursor()
233 extra = '' 238 extra = ''
234 if arch: 239 if arch:
235 stable_extra = ('ebuild.arch REGEXP "^%s| %s" ' 240 stable_extra = ('ebuild.arch REGEXP "^%s| %s" '
236 ' AND ebuild.prevarch NOT REGEXP"^%s| %s"' 241 ' AND ebuild.prevarch NOT REGEXP"^%s| %s"'
251 c.execute(query) 256 c.execute(query)
252 results = c.fetchall() 257 results = c.fetchall()
253 return results 258 return results
254 259
255def query_to_dict(d): 260def query_to_dict(d):
261 """Convert a SQL query to a dict"""
256 einfo = {} 262 einfo = {}
257 keys = ('category','name','version','time','description','changelog', 263 keys = ('category', 'name', 'version', 'time', 'description', 'changelog',
258 'arch','homepage','license') 264 'arch', 'homepage', 'license')
259 for i in range(len(keys)): 265 for i in range(len(keys)):
260 try: 266 try:
261 einfo[keys[i]] = d[i] 267 einfo[keys[i]] = d[i]
262 except IndexError: 268 except IndexError:
263 continue 269 continue
264 return einfo 270 return einfo
265 271
266def get_recent_releases(pkg,db,max=config.MAX_RECENT_RELEASES): 272def get_recent_releases(pkg, db, max=config.MAX_RECENT_RELEASES):
267 """Return MAX_RECENT_RELEASES most recent releases for pkg. Returns and 273 """Return MAX_RECENT_RELEASES most recent releases for pkg. Returns and
268 ebuild-type dict""" 274 ebuild-type dict"""
269 c = db.cursor() 275 c = db.cursor()
270 query = """SELECT category,name,version,when_found,NULL,changelog,arch ,NULL,NULL 276 query = ('SELECT category,name,version,when_found,NULL,changelog,arch ,'
271 FROM ebuild WHERE name="%s" AND 277 'NULL,NULL FROM ebuild WHERE name="%s" AND category="%s" ORDER BY '
272 category="%s" ORDER BY version DESC LIMIT %s 278 'version DESC LIMIT %s' % (pkg['name'],pkg['category'],max))
273 """ % (pkg['name'],pkg['category'],max)
274 c.execute(query) 279 c.execute(query)
275 results = c.fetchall() 280 results = c.fetchall()
276 #print results 281 #print results
277 return [ query_to_dict(i) for i in results ] 282 return [ query_to_dict(i) for i in results ]
278 283
279def ebuilds_to_rss(fp,ebuilds,simple=False,subtitle=""): 284def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""):
280 """write out ebuild info to RSS file (fp)""" 285 """write out ebuild info to RSS file (fp)"""
281 fp.write("""<?xml version="1.0" encoding="utf-8"?> 286 fp.write("""<?xml version="1.0" encoding="utf-8"?>
282 <rss version="0.92"> 287 <rss version="0.92">
283 <channel> 288 <channel>
284 <title>Fresh ebuilds %s</title> 289 <title>Fresh ebuilds %s</title>
318if __name__ == '__main__': 323if __name__ == '__main__':
319 try: 324 try:
320 if sys.argv[1] == '-g': 325 if sys.argv[1] == '-g':
321 ebuilddb.main() 326 ebuilddb.main()
322 except IndexError: 327 except IndexError:
323 pass 328 pass
324 329
325 db = ebuilddb.db_connect() 330 db = ebuilddb.db_connect()
326 branches = ('','stable','testing') 331 branches = ('', 'stable', 'testing')
327 for arch in [''] + config.ARCHLIST: 332 for arch in [''] + config.ARCHLIST:
328 for branch in branches: 333 for branch in branches:
329 fullpath = os.path.join(config.LOCALHOME,"archs",arch,branch,config.INDEX) 334 fullpath = os.path.join(config.LOCALHOME, "archs", arch, branch,
335 config.INDEX)
330 index = open(fullpath,'w') 336 index = open(fullpath,'w')
331 if arch: 337 if arch:
332 sarch = arch 338 sarch = arch
333 else: 339 else:
334 sarch = 'all' 340 sarch = 'all'
338 sbranch = 'all' 344 sbranch = 'all'
339 345
340 index.write("""<table border="0" cellpadding="0" cellspacing="5" 346 index.write("""<table border="0" cellpadding="0" cellspacing="5"
341 width="100%">\n""") 347 width="100%">\n""")
342 index.write("""<tr><td valign="top">\n""") 348 index.write("""<tr><td valign="top">\n""")
343 index.write('<!--#include file="archnav.html" -->\n\n</td></tr>\n<tr><td>') 349 index.write('<!--#include file="archnav.html" -->\n\n</td></tr>\n'
350 '<tr><td>')
344 results = get_most_recent(db,arch=arch,branch=branch) 351 results = get_most_recent(db, arch=arch, branch=branch)
345 ebuilds = [ query_to_dict(i) for i in results ] 352 ebuilds = [ query_to_dict(i) for i in results ]
346 for ebuild in ebuilds: 353 for ebuild in ebuilds:
347 new = is_new(db,ebuild) 354 new = is_new(db, ebuild)
348 pkgfilename = "%s/%s-%s.html" % ( 355 pkgfilename = "%s/%s-%s.html" % (
349 config.EBUILD_FILES,ebuild['name'],ebuild['version']) 356 config.EBUILD_FILES,ebuild['name'],ebuild['version'])
350 ebuild_html = ebuild_to_html(ebuild,new) 357 ebuild_html = ebuild_to_html(ebuild, new)
351 if arch == '' and branch == '': # and not os.path.exists(pkgfilename): 358 if arch == '' and branch == '':
352 pkgfile = open(pkgfilename,'w') 359 pkgfile = open(pkgfilename,'w')
353 pkgfile.write(ebuild_html) 360 pkgfile.write(ebuild_html)
354 pkgfile.close() 361 pkgfile.close()
355 ebuildfilename = "%s/%s/%s/%s-%s.ebuild" % (ebuilddb.config.PORTAGE_DIR, 362 ebuildfilename = "%s/%s/%s/%s-%s.ebuild" \
363 % (ebuilddb.config.PORTAGE_DIR,
356 ebuild['category'],ebuild['name'],ebuild['name'], 364 ebuild['category'],ebuild['name'],ebuild['name'],
357 ebuild['version']) 365 ebuild['version'])
358 os.system('touch -r %s %s || touch -d "today -1 year" %s' 366 os.system('touch -r %s %s || touch -d "today -1 year" %s'
359 % (ebuildfilename,pkgfilename,pkgfilename)) 367 % (ebuildfilename,pkgfilename,pkgfilename))
360 368
361 try: 369 try:
362 index.write('%s\n\n' % (ebuild_html)) 370 index.write('%s\n\n' % (ebuild_html))
363 except IOError: 371 except IOError:
364 pass 372 continue
365 index.write("""</table>\n""") 373 index.write("""</table>\n""")
366 index.close() 374 index.close()
367 375
368 subtitle = ' %s %s' % (arch,branch) 376 subtitle = ' %s %s' % (arch, branch)
369 rss = open(os.path.join(config.LOCALHOME,"archs",arch,branch,config.RSS),'w') 377 rss = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
378 config.RSS), 'w')
370 ebuilds_to_rss(rss,ebuilds,simple=False,subtitle=subtitle) 379 ebuilds_to_rss(rss, ebuilds, simple=False, subtitle=subtitle)
371 rss.close() 380 rss.close()
372 381
373 rss2 = open(os.path.join(config.LOCALHOME,"archs",arch,branch,config.RSS2),'w') 382 rss2 = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
383 config.RSS2), 'w')
374 ebuilds_to_rss(rss2,ebuilds,simple=True,subtitle=subtitle) 384 ebuilds_to_rss(rss2, ebuilds, simple=True, subtitle=subtitle)
375 rss.close() 385 rss.close()

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.20