#!/usr/bin/python
# Copyright (c) 2009 Christoph Berg
apt-cache webservice
Find a package in a suite:
""" text_head = """Content-Type: text/plain; charset=utf-8\n""" def lookup(archive, suite, component, architecture, package): cur.execute("""SELECT control FROM packagelist l JOIN package p USING (package, version, pkg_architecture) WHERE (archive, suite, component) = (%s, %s, %s) AND %s IN (architecture, pkg_architecture) AND l.package = %s""", [archive, suite, component, architecture, package]) item = cur.fetchone() if item: print item[0] def package(package, version, architecture): cur.execute("""SELECT control FROM package WHERE (package, version) = (%s, %s) AND pkg_architecture IN (%s, 'all')""", [package, version, architecture]) item = cur.fetchone() if item: print item[0] def dropdown(kind, table): cur.execute("""SELECT DISTINCT %(kind)s FROM %(table)s ORDER BY %(kind)s""" % dict(kind=kind, table=table)) list = [ "" % thing[0] for thing in cur.fetchall() ] return "".join(list) pg = psycopg2.connect('dbname=qa') cur = pg.cursor() cur.execute("SET search_path TO apt") request = cgi.parse() if request.has_key('package') and request.has_key('version'): if not request.has_key('architecture'): request['architecture'] = ['source'] print text_head package(request['package'][0], request['version'][0], request['architecture'][0]) elif request.has_key('archive') and request.has_key('suite') and \ request.has_key('component') and request.has_key('package'): if not request.has_key('architecture'): request['architecture'] = ['source'] print text_head lookup(request['archive'][0], request['suite'][0], request['component'][0], request['architecture'][0], request['package'][0]) else: cur.execute("SELECT architecture FROM architecture ORDER BY architecture") dict = { 'archive': dropdown('archive', 'suite'), 'suite': dropdown('suite', 'suite'), 'component': dropdown('component', 'suite'), 'architecture': dropdown('architecture', 'architecture') } print form % dict