#!/usr/bin/python # Copyright (c) 2009 Christoph Berg # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import cgi, psycopg2 form = """Content-Type: text/html; charset=utf-8 apt-cache webservice

apt-cache webservice

Find a package in a suite:

Package:

Find a specific version of a package:

Package: Version:

""" 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