| 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.2 $"
|
| 6 |
# $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $
|
| 7 |
|
| 8 |
import config
|
| 9 |
import os
|
| 10 |
import time
|
| 11 |
import string
|
| 12 |
import sys
|
| 13 |
import ebuilddb
|
| 14 |
import bugs
|
| 15 |
import changelogs
|
| 16 |
from cgi import escape
|
| 17 |
from urllib import quote
|
| 18 |
from portage_versions import pkgcmp, pkgsplit
|
| 19 |
|
| 20 |
def is_new(db, ebuild):
|
| 21 |
"""Check for newness."""
|
| 22 |
|
| 23 |
c = db.cursor()
|
| 24 |
query = ('SELECT new FROM package WHERE category="%s" AND name="%s"'
|
| 25 |
% (ebuild['category'], ebuild['name']))
|
| 26 |
c.execute(query)
|
| 27 |
results = c.fetchall()
|
| 28 |
if len(results) == 1 and results[0][0]:
|
| 29 |
return 1
|
| 30 |
return 0
|
| 31 |
|
| 32 |
changelog_to_html = changelogs.bugs_to_html
|
| 33 |
|
| 34 |
def homepage_to_html(homepage):
|
| 35 |
"""convert HOMEPAGE entry to HTML"""
|
| 36 |
if not homepage.strip():
|
| 37 |
return "?"
|
| 38 |
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 |
|
| 45 |
html = ['[<a href="%s">%s</a>]' % (page, index + 1) for index,
|
| 46 |
page in enumerate(pieces)]
|
| 47 |
return " ".join(['<span class="homepage">Homepages'] + html +
|
| 48 |
['</span>'])
|
| 49 |
|
| 50 |
def license_to_html(license):
|
| 51 |
"""Create link to license[s]"""
|
| 52 |
if not license.strip(): return "?"
|
| 53 |
license = license.replace('|',' ')
|
| 54 |
license = license.replace('(', '')
|
| 55 |
license = license.replace(')', '')
|
| 56 |
pieces = license.split()
|
| 57 |
html = ['<a href="http://sources.gentoo.org/viewcvs.py/*checkout*/'
|
| 58 |
'gentoo-x86/licenses/%s">%s</a>' % (piece, piece) for piece in pieces]
|
| 59 |
return '<br>\n'.join(html)
|
| 60 |
|
| 61 |
def package_to_html(pkginfo, db, full=False):
|
| 62 |
"""This function needs a database (db) connection because it performs a
|
| 63 |
query_to_dict on the package"""
|
| 64 |
|
| 65 |
table_begin = '<table class="ebuild">'
|
| 66 |
name = '<tr><td class="fields">%s</td></tr>' % pkginfo['name']
|
| 67 |
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 |
description = ('<tr><td class="item">'
|
| 74 |
'%s<b>Description: </b>%s</td></tr>'
|
| 75 |
% (image, escape(pkginfo['description']))
|
| 76 |
)
|
| 77 |
ebuilds = get_recent_releases(pkginfo, db)
|
| 78 |
releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases')
|
| 79 |
#bug_string = ('<br><h3>Related bugs:</h3>\n%s'
|
| 80 |
# % bugs_to_html(pkginfo['name']))
|
| 81 |
general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo)
|
| 82 |
#similar = '<tr><td>%s</td></tr>' % create_similar_pkgs_link(pkginfo)
|
| 83 |
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 |
"""Create table for availability on each architecture"""
|
| 89 |
heading = heading or ' '
|
| 90 |
table_begin = '<table class="releases">'
|
| 91 |
header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] +
|
| 92 |
['<th class="arch">%s</th>' % i.replace('-',' ') for i in config.ARCHLIST] +
|
| 93 |
['</tr>']
|
| 94 |
)
|
| 95 |
rows = []
|
| 96 |
ebuilds.sort(cmp_ebuilds)
|
| 97 |
ebuilds.reverse()
|
| 98 |
for ebuild in ebuilds:
|
| 99 |
archs = ebuild['arch'].split(',')
|
| 100 |
row_start = ('<tr>\n\t<th class="releases"><a href="%sebuilds/?%s-%s"'
|
| 101 |
' title="%s">%s</a></th>\n' % (config.FEHOME,
|
| 102 |
ebuild['name'], ebuild['version'], ebuild['time'],
|
| 103 |
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 |
if arch_string != '-' and ebuild['masked']:
|
| 113 |
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 |
|
| 121 |
def ebuild_to_html(ebinfo, new=0, show_bugs=0, full = False):
|
| 122 |
"""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 |
if new:
|
| 126 |
new_string = """ <span class="new">new!</span> """
|
| 127 |
else:
|
| 128 |
new_string = ""
|
| 129 |
|
| 130 |
table_begin = '<table class="ebuild">'
|
| 131 |
name_and_date = ('<tr><td class="fields">'
|
| 132 |
'<a href="%spackages/?category=%s;name=%s">%s</a> %s%s<br>'
|
| 133 |
'<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 |
ebinfo['time'].strftime("%c %Z")))
|
| 140 |
|
| 141 |
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 |
desc_and_changes = ('<tr><td class="item" valign="top">'
|
| 148 |
'<p><b>Description:</b> %s %s</p>'
|
| 149 |
'<p><b>Changes:</b><br>'
|
| 150 |
'%s</p></td></tr>' % (
|
| 151 |
escape(ebinfo['description']),
|
| 152 |
image,
|
| 153 |
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 |
|
| 159 |
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 |
|
| 166 |
return '\n\t'.join([table_begin,
|
| 167 |
name_and_date,
|
| 168 |
desc_and_changes,
|
| 169 |
archs,
|
| 170 |
general,
|
| 171 |
table_end,
|
| 172 |
bug_string])
|
| 173 |
|
| 174 |
def general_info_to_html(pkg):
|
| 175 |
"""This actually will (should) take either a package or ebuild dict
|
| 176 |
as an argument"""
|
| 177 |
|
| 178 |
import forums
|
| 179 |
|
| 180 |
changelogurl = ('http://sources.gentoo.org/viewcvs.py/*checkout*/'
|
| 181 |
'gentoo-x86/%s/%s/ChangeLog' % (pkg['category'],pkg['name']))
|
| 182 |
cat_header = '<th class="category">Category</th>'
|
| 183 |
license_header = '<th class="license">License</th>'
|
| 184 |
category = ('<td class="category">'
|
| 185 |
'<a href="%spackages/?category=%s">%s</a></td>' % (config.FEHOME,
|
| 186 |
pkg['category'], pkg['category']))
|
| 187 |
homepage = ('<td class="homepage" rowspan="2">%s</td>'
|
| 188 |
% homepage_to_html(pkg['homepage']))
|
| 189 |
license = ('<td class="license">%s</td>'
|
| 190 |
% license_to_html(pkg['license']))
|
| 191 |
changelog = ('<td class="changelog" rowspan="2">'
|
| 192 |
'<a href="%s">ChangeLog</a></td>' % changelogurl)
|
| 193 |
similar = ('<td class="similar" rowspan="2">'
|
| 194 |
'%s</td>' % create_similar_pkgs_link(pkg))
|
| 195 |
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 |
|
| 200 |
return '\n\t'.join(['<table class="general_info">',
|
| 201 |
'<tr>',
|
| 202 |
cat_header,
|
| 203 |
homepage,
|
| 204 |
license_header,
|
| 205 |
changelog,
|
| 206 |
similar,
|
| 207 |
related_bugs,
|
| 208 |
forums,
|
| 209 |
'</tr>',
|
| 210 |
'<tr>',
|
| 211 |
category,
|
| 212 |
license,
|
| 213 |
'</tr>',
|
| 214 |
'</table>'])
|
| 215 |
|
| 216 |
def create_similar_pkgs_link(pkg):
|
| 217 |
"""Create a link to similar packages"""
|
| 218 |
|
| 219 |
return '<a href="/similar/?package=%(category)s/%(name)s">Similar</a>' % pkg
|
| 220 |
|
| 221 |
def create_related_bugs_link(pkg):
|
| 222 |
"""Create a link to related bugs"""
|
| 223 |
|
| 224 |
url = ('http://bugs.gentoo.org/buglist.cgi?query_format='
|
| 225 |
'&short_desc_type=allwords'
|
| 226 |
'&short_desc=%s'
|
| 227 |
'&bug_status=UNCONFIRMED'
|
| 228 |
'&bug_status=NEW'
|
| 229 |
'&bug_status=ASSIGNED'
|
| 230 |
'&bug_status=REOPENED'
|
| 231 |
% escape(pkg['name']))
|
| 232 |
|
| 233 |
return '<a title="bugs.gentoo.org" href="%s">Bugs</a>' % url
|
| 234 |
|
| 235 |
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 |
#return ""
|
| 241 |
import urllib2
|
| 242 |
url = ('http://bugs.gentoo.org/buglist.cgi?query_format='
|
| 243 |
'&short_desc_type=allwords'
|
| 244 |
'&short_desc=%s'
|
| 245 |
'&bug_status=UNCONFIRMED'
|
| 246 |
'&bug_status=NEW'
|
| 247 |
'&bug_status=ASSIGNED'
|
| 248 |
'&bug_status=REOPENED'
|
| 249 |
'&ctype=csv'
|
| 250 |
% package)
|
| 251 |
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 |
return ""
|
| 259 |
|
| 260 |
def get_most_recent(db, max=config.MAXPERPAGE, arch="", branch="", new = False):
|
| 261 |
c = db.cursor()
|
| 262 |
extra = ''
|
| 263 |
if arch:
|
| 264 |
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 |
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 |
|
| 275 |
if new:
|
| 276 |
extra = ('%s AND package.new=1 ' % extra)
|
| 277 |
|
| 278 |
query = """SELECT ebuild.category,ebuild.name,version,ebuild.when_found,description,
|
| 279 |
changelog,arch,homepage,license,is_masked FROM ebuild,package WHERE ebuild.name=\
|
| 280 |
package.name AND ebuild.category=package.category %s ORDER by ebuild.when_found DESC \
|
| 281 |
LIMIT %s""" % (extra,max)
|
| 282 |
c.execute(query)
|
| 283 |
results = c.fetchall()
|
| 284 |
return results
|
| 285 |
|
| 286 |
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 |
|
| 296 |
c.execute(query)
|
| 297 |
results = c.fetchall()
|
| 298 |
return results
|
| 299 |
|
| 300 |
def query_to_dict(d):
|
| 301 |
"""Convert a SQL query to a dict"""
|
| 302 |
einfo = {}
|
| 303 |
keys = ('category', 'name', 'version', 'time', 'description', 'changelog',
|
| 304 |
'arch', 'homepage', 'license', 'masked')
|
| 305 |
for i in range(len(keys)):
|
| 306 |
try:
|
| 307 |
einfo[keys[i]] = d[i]
|
| 308 |
except IndexError:
|
| 309 |
continue
|
| 310 |
return einfo
|
| 311 |
|
| 312 |
def get_recent_releases(pkg, db, max=config.MAX_RECENT_RELEASES):
|
| 313 |
"""Return MAX_RECENT_RELEASES most recent releases for pkg. Returns and
|
| 314 |
ebuild-type dict"""
|
| 315 |
c = db.cursor()
|
| 316 |
query = ('SELECT category,name,version,when_found,NULL,changelog,arch ,'
|
| 317 |
'NULL,NULL,is_masked FROM ebuild WHERE name="%s" AND category="%s" ORDER BY '
|
| 318 |
'version DESC LIMIT %s' % (pkg['name'],pkg['category'],max))
|
| 319 |
c.execute(query)
|
| 320 |
results = c.fetchall()
|
| 321 |
#print results
|
| 322 |
return [ query_to_dict(i) for i in results ]
|
| 323 |
|
| 324 |
def cmp_ebuilds(a, b):
|
| 325 |
"""Compare two ebuilds"""
|
| 326 |
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 |
def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""):
|
| 331 |
"""write out ebuild info to RSS file (fp)"""
|
| 332 |
|
| 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 |
fp.write("""<?xml version="1.0" encoding="UTF-8"?>
|
| 341 |
<rss version="2.0">
|
| 342 |
<channel>
|
| 343 |
<title>packages.gentoo.org [ %s ]</title>
|
| 344 |
<link>%s</link>
|
| 345 |
<description>Latest ebuilds from the Gentoo Linux portage tree</description>
|
| 346 |
<webMaster>www@gentoo.org</webMaster>
|
| 347 |
|
| 348 |
<image>
|
| 349 |
<title>Online Package Database</title>
|
| 350 |
<url>%s</url>
|
| 351 |
<link>%s</link>
|
| 352 |
</image>
|
| 353 |
|
| 354 |
<managingEditor>marduk@gentoo.org</managingEditor>
|
| 355 |
<pubDate>%s</pubDate>""" % (subtitle, link, config.RSS_IMAGE,
|
| 356 |
config.FEHOME, pubDate))
|
| 357 |
|
| 358 |
for ebuild in ebuilds:
|
| 359 |
if simple:
|
| 360 |
description = escape(ebuild['description'])
|
| 361 |
else:
|
| 362 |
description = ('\n'
|
| 363 |
'<![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 |
|
| 368 |
fp.write("""<item>
|
| 369 |
<title>%s/%s %s</title>
|
| 370 |
<link>%sebuilds/?%s-%s</link>
|
| 371 |
<description>
|
| 372 |
%s
|
| 373 |
</description>
|
| 374 |
<pubDate>%s</pubDate>
|
| 375 |
</item>
|
| 376 |
""" % (ebuild['category'],
|
| 377 |
ebuild['name'],
|
| 378 |
ebuild['version'],
|
| 379 |
config.FEHOME,
|
| 380 |
ebuild['name'],
|
| 381 |
ebuild['version'],
|
| 382 |
description,
|
| 383 |
ebuild['time'].strftime("%a, %d %b %Y %H:%M:%S +0000"))
|
| 384 |
)
|
| 385 |
|
| 386 |
fp.write("\n\
|
| 387 |
<textInput>\n\
|
| 388 |
<title>Search the Online Package Database</title>\n\
|
| 389 |
<link>%s/search/</link>\n\
|
| 390 |
<description>emerge -Ss</description>\n\
|
| 391 |
<name>sstring</name>\n\
|
| 392 |
</textInput>\n\
|
| 393 |
</channel>\n\
|
| 394 |
</rss>\n" % config.FEHOME)
|
| 395 |
|
| 396 |
def main(argv=None):
|
| 397 |
if argv is None:
|
| 398 |
argv = sys.argv
|
| 399 |
try:
|
| 400 |
if argv[1] == '-g':
|
| 401 |
ebuilddb.main()
|
| 402 |
except IndexError:
|
| 403 |
pass
|
| 404 |
|
| 405 |
db = ebuilddb.db_connect()
|
| 406 |
branches = ('', 'stable', 'testing')
|
| 407 |
for arch in [''] + config.ARCHLIST:
|
| 408 |
for branch in branches:
|
| 409 |
fullpath = os.path.join(config.LOCALHOME, "archs", arch, branch,
|
| 410 |
config.INDEX)
|
| 411 |
index = open(fullpath,'w')
|
| 412 |
|
| 413 |
index.write("""<table border="0" cellpadding="0" cellspacing="5"
|
| 414 |
width="100%">\n""")
|
| 415 |
index.write("""<tr><td valign="top">\n""")
|
| 416 |
index.write('<!--#include file="archnav.html" -->\n\n</td></tr>\n'
|
| 417 |
'<tr><td>')
|
| 418 |
results = get_most_recent(db, arch=arch, branch=branch)
|
| 419 |
ebuilds = [ query_to_dict(i) for i in results ]
|
| 420 |
for ebuild in ebuilds:
|
| 421 |
new = is_new(db, ebuild)
|
| 422 |
pkgfilename = "%s/%s-%s.html" % (
|
| 423 |
config.EBUILD_FILES,ebuild['name'],ebuild['version'])
|
| 424 |
ebuild_html = ebuild_to_html(ebuild, new, show_bugs = False)
|
| 425 |
if arch == '' and branch == '':
|
| 426 |
pkgfile = open(pkgfilename,'w')
|
| 427 |
pkgfile.write(ebuild_html)
|
| 428 |
pkgfile.close()
|
| 429 |
ebuildfilename = "%s/%s/%s/%s-%s.ebuild" \
|
| 430 |
% (ebuilddb.config.PORTAGE_DIR,
|
| 431 |
ebuild['category'],ebuild['name'],ebuild['name'],
|
| 432 |
ebuild['version'])
|
| 433 |
os.system('touch -r %s %s || touch -d "today -1 year" %s'
|
| 434 |
% (ebuildfilename,pkgfilename,pkgfilename))
|
| 435 |
|
| 436 |
try:
|
| 437 |
index.write('%s\n\n' % (ebuild_html))
|
| 438 |
except IOError:
|
| 439 |
continue
|
| 440 |
index.write("""</table>\n""")
|
| 441 |
index.close()
|
| 442 |
|
| 443 |
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 |
rss.close()
|
| 448 |
|
| 449 |
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 |
rss.close()
|
| 453 |
|
| 454 |
if __name__ == '__main__':
|
| 455 |
sys.exit(main())
|