#!/usr/bin/python -O import cgi from urllib import quote import os import sys import config import gentoo import ebuilddb from MySQLdb import escape_string sys.stdout.write('Content-type: text/html; charset=iso-8859-1\n\n') def cmp_results(a, b): """Compare results a and b""" category_a = a[0] category_b = b[0] order = cmp(category_a, category_b) if order != 0: return order def query_to_dict(q): pkginfo = {} keys = ('category','name','homepage','description','license') for i in range(len(keys)): try: pkginfo[keys[i]] = q[i] except IndexError: continue return pkginfo form = cgi.FieldStorage() name = form.getvalue("name","") category = form.getvalue("category","") offset = form.getvalue("offset","0") query = ('SELECT category,name,homepage,description,license ' 'FROM package WHERE category="%s"' % escape_string(category)) if name: query = ('%s AND name="%s"' %(query,escape_string(name))) # first get row count db = ebuilddb.db_connect() c = db.cursor() c.execute(query) total_rows = c.rowcount query = ('%s LIMIT %s,%s' % (query,offset,config.MAX_CATEGORIES)) c.execute(query) results = c.fetchall() #print query if results: if name: for result in results: #print result pkg = query_to_dict(result) sys.stdout.write('%s
\n
\n' % gentoo.package_to_html(pkg,db, full=True)) else: sys.stdout.write('\n') sys.stdout.write('\n
' '%s
' % category) for result in results: pkg = query_to_dict(result) sys.stdout.write(gentoo.package_to_html(pkg, db)) sys.stdout.write('
\n') if offset !="0": sys.stdout.write('[Previous] ' % (category,name,int(offset) - config.MAX_CATEGORIES)) if int(offset) + len(results) < total_rows: sys.stdout.write('[Next] ' % (category,name,int(offset) + config.MAX_CATEGORIES)) else: sys.stdout.write('
\n' '\n' '
' 'Sorry, dude. I could not find that package.
' '

Information on the package you requested' ' could not be found. Be sure to check the' ' ' 'packages.gentoo.org main page.

\n' '
' % (config.ICONS,config.FEHOME))