#!/usr/bin/python -OO
"""These functions mainly take ebuild info (grabbed from the database and
convert it to HTML. See the "main" function at the bottom."""
__revision__ = "$Revision: 1.3 $"
# $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $
import config
import os
import time
import sys
import ebuilddb
import bugs
import changelogs
from cgi import escape
from urllib import quote
# import portage, but temporarily redirect stderr
if 'portage' not in dir():
null = open('/dev/null', 'w')
tmp = sys.stderr
sys.stderr = null
sys.path = ["/usr/lib/portage/pym"]+sys.path
import portage
sys.stderr = tmp
sys.path = sys.path[1:]
tree = portage.portdbapi('/usr/portage')
def is_masked(ebuild):
"""Return true if ebuild is masked"""
return (not tree.visible(['%(category)s/%(name)s-%(version)s' % ebuild]))
def is_new(db, ebuild):
"""Check for newness. An ebuild is considered new if it is the
only ebuild with that category/name in ebuild and it has no prevarch"""
c = db.cursor()
query = ('SELECT prevarch FROM ebuild WHERE category="%s" AND name="%s"'
% (ebuild['category'], ebuild['name']))
c.execute(query)
results = c.fetchall()
if len(results) == 1 and results[0][0] is None:
return 1
return 0
def changelog_to_html(changelog):
"""HTML-ize a changelog entry"""
html = ""
for char in changelog:
if char == '\n':
html = "%s " % html
else:
html = "%s%s" % (html, escape(char))
html = changelogs.bugs_to_html(html)
return html
def homepage_to_html(homepage):
"""convert HOMEPAGE entry to HTML"""
if not homepage.strip():
return "?"
homepage = homepage.replace('|',' ')
pieces = homepage.split()
count = len(pieces)
if count == 1:
return (''
'Homepage' % pieces[0])
html = ['[%s]' % (page, index + 1) for index,
page in enumerate(pieces)]
return " ".join(['Homepages'] + html +
[''])
def license_to_html(license):
"""Create link to license[s]"""
if not license.strip(): return "?"
license = license.replace('|',' ')
pieces = license.split()
html = ['%s' % (piece, piece) for piece in pieces]
return ' \n'.join(html)
def package_to_html(pkginfo, db):
"""This function needs a database (db) connection because it performs a
query_to_dict on the package"""
table_begin = '
'
return '\n\t'.join([table_begin] + [header_row] + rows + [table_end])
def ebuild_to_html(ebinfo, new=0, show_bugs=0):
"""Convert ebuild (dict) to html, if new, print out a "this is new" notice
if show_bugs, show bugs for this particular ebuild (requires access to
bugzilla"""
if new:
new_string = """ new! """
else:
new_string = ""
table_begin = '
%s' \
% bugs_to_html(ebinfo['name'])
return '\n\t'.join([table_begin,
name_and_date,
desc_and_changes,
archs,
general,
table_end,
bug_string])
def general_info_to_html(pkg):
"""This actually will (should) take either a package or ebuild dict
as an argument"""
changelogurl = ('http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/'
'%s/%s/ChangeLog' % (pkg['category'],pkg['name']))
cat_header = '