| 1 |
marduk |
1.5 |
#!/usr/bin/python -O
|
| 2 |
marduk |
1.1 |
|
| 3 |
|
|
import cgi
|
| 4 |
|
|
from urllib import quote
|
| 5 |
|
|
import os
|
| 6 |
|
|
import sys
|
| 7 |
|
|
import config
|
| 8 |
|
|
import gentoo
|
| 9 |
|
|
import ebuilddb
|
| 10 |
|
|
from MySQLdb import escape_string
|
| 11 |
|
|
|
| 12 |
marduk |
1.3 |
sys.stdout.write('Content-type: text/html; charset=iso-8859-1\n\n')
|
| 13 |
marduk |
1.1 |
|
| 14 |
marduk |
1.4 |
def cmp_results(a, b):
|
| 15 |
|
|
"""Compare results a and b"""
|
| 16 |
|
|
category_a = a[0]
|
| 17 |
|
|
category_b = b[0]
|
| 18 |
|
|
|
| 19 |
|
|
order = cmp(category_a, category_b)
|
| 20 |
|
|
if order != 0:
|
| 21 |
|
|
return order
|
| 22 |
|
|
|
| 23 |
|
|
|
| 24 |
marduk |
1.1 |
def query_to_dict(q):
|
| 25 |
marduk |
1.2 |
pkginfo = {}
|
| 26 |
|
|
keys = ('category','name','homepage','description','license')
|
| 27 |
|
|
for i in range(len(keys)):
|
| 28 |
|
|
try:
|
| 29 |
|
|
pkginfo[keys[i]] = q[i]
|
| 30 |
|
|
except IndexError:
|
| 31 |
|
|
continue
|
| 32 |
|
|
return pkginfo
|
| 33 |
marduk |
1.1 |
|
| 34 |
|
|
|
| 35 |
|
|
form = cgi.FieldStorage()
|
| 36 |
|
|
name = form.getvalue("name","")
|
| 37 |
|
|
category = form.getvalue("category","")
|
| 38 |
|
|
offset = form.getvalue("offset","0")
|
| 39 |
|
|
|
| 40 |
|
|
query = ('SELECT category,name,homepage,description,license '
|
| 41 |
marduk |
1.2 |
'FROM package WHERE category="%s"' % escape_string(category))
|
| 42 |
|
|
|
| 43 |
marduk |
1.1 |
if name:
|
| 44 |
marduk |
1.2 |
query = ('%s AND name="%s"' %(query,escape_string(name)))
|
| 45 |
marduk |
1.1 |
|
| 46 |
marduk |
1.5 |
# first get row count
|
| 47 |
|
|
db = ebuilddb.db_connect()
|
| 48 |
|
|
c = db.cursor()
|
| 49 |
|
|
c.execute(query)
|
| 50 |
|
|
total_rows = c.rowcount
|
| 51 |
|
|
|
| 52 |
marduk |
1.1 |
query = ('%s LIMIT %s,%s' % (query,offset,config.MAX_CATEGORIES))
|
| 53 |
|
|
|
| 54 |
|
|
c.execute(query)
|
| 55 |
|
|
results = c.fetchall()
|
| 56 |
|
|
|
| 57 |
|
|
#print query
|
| 58 |
|
|
if results:
|
| 59 |
marduk |
1.2 |
if name:
|
| 60 |
|
|
for result in results:
|
| 61 |
|
|
#print result
|
| 62 |
|
|
pkg = query_to_dict(result)
|
| 63 |
|
|
sys.stdout.write('%s<br>\n<br>\n'
|
| 64 |
marduk |
1.5 |
% gentoo.package_to_html(pkg,db, full=True))
|
| 65 |
marduk |
1.2 |
else:
|
| 66 |
|
|
sys.stdout.write('<table class="centerpage">\n')
|
| 67 |
|
|
sys.stdout.write('<tr><th class="category">'
|
| 68 |
|
|
'%s</th></tr>\n<tr><td>' % category)
|
| 69 |
|
|
for result in results:
|
| 70 |
|
|
pkg = query_to_dict(result)
|
| 71 |
|
|
sys.stdout.write(gentoo.package_to_html(pkg, db))
|
| 72 |
|
|
sys.stdout.write('</td></tr></table>\n')
|
| 73 |
|
|
if offset !="0":
|
| 74 |
|
|
sys.stdout.write('<a href="?category=%s;name=%s'
|
| 75 |
|
|
';offset=%s">[Previous]</a> '
|
| 76 |
|
|
% (category,name,int(offset) - config.MAX_CATEGORIES))
|
| 77 |
marduk |
1.5 |
if int(offset) + len(results) < total_rows:
|
| 78 |
marduk |
1.2 |
sys.stdout.write('<a href="?category=%s;name=%s;offset=%s">[Next]</a> '
|
| 79 |
|
|
% (category,name,int(offset) + config.MAX_CATEGORIES))
|
| 80 |
marduk |
1.1 |
|
| 81 |
|
|
else:
|
| 82 |
marduk |
1.2 |
sys.stdout.write('<div class="centerpage">\n'
|
| 83 |
|
|
'<table width="100%%" border="0" align="center"'
|
| 84 |
|
|
' cellspacing="0"><tr><td colspan="3" class="fields">'
|
| 85 |
|
|
'Sorry, dude. I could not find that package.<br></td></tr>\n'
|
| 86 |
|
|
'<tr><td class="item" colspan="3">'
|
| 87 |
|
|
'<img '
|
| 88 |
|
|
'src="%s?category=404"'
|
| 89 |
|
|
'align="right" alt=""> <p>Information on the package you requested'
|
| 90 |
|
|
' could not be found. Be sure to check the'
|
| 91 |
|
|
' <a HREF="%s">'
|
| 92 |
marduk |
1.4 |
'packages.gentoo.org main page</a>.</p></td></tr></table>\n'
|
| 93 |
marduk |
1.2 |
'</div>' % (config.ICONS,config.FEHOME))
|