Package: debram
Version: 1.0.3-0.1
Severity: wishlist
Tags: patch
Hi there,
I've quickly hacked a minimal http frontend to debram, so that one can
navigate the catalogue with a web browser. Perhaps it could be included in
doc/examples?
Cheers,
Serafeim
#!/usr/bin/env python
############################################################################
# Copyright (C) 2008 Serafeim Zanikolas <[EMAIL PROTECTED]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from commands import getstatusoutput
import re, sys
class Handler(BaseHTTPRequestHandler):
sectid_re = re.compile("([^0-9])([0-9]{4}) ")
pkgname_re = re.compile(u"\n\n(.*) ([^ ]*)\n")
def do_GET(self):
try:
try:
query_type, arg = self.path.split(":")
except ValueError:
query_type, arg = "/sec", ""
if query_type == "/sec":
status, reply = getstatusoutput("debram -L %s" % arg)
reply = Handler.pkgname_re.sub(\
r"<br/><br/>\1<a href='/pkg:\2'> \2</a><br/>", reply)
reply = Handler.sectid_re.sub(r"\1<a href='/sec:\2'>\2</a> ",\
reply)
elif query_type == "/pkg":
status, reply = getstatusoutput("apt-cache show %s" % arg)
reply = reply.replace("\n", "<br/>")
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(reply)
except:
self.send_error(400,'Bad request: %s' % self.path)
def main():
port = 11080
try:
port = int(sys.argv[1])
except IndexError:
pass
except ValueError:
print "A quick hack for browsing the ramified catalogue of Debian packages."
print "syntax: debram-httpd.py [port] (port defaults to %d)" % port
sys.exit(1)
try:
listener = HTTPServer(('', port), Handler)
listener.serve_forever()
except KeyboardInterrupt:
listener.socket.close()
if __name__ == '__main__':
main()