#!/usr/bin/python

#
#      popbugs - List the status of a giver set of BTS reports
#      Copyright (C) 2003  Petter Reinholdtsen <pere@hungry.com>
#
#      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
#

import sys
import debianbts

def debug(s):
    if 0:
        print s

def html_header():
    print "<html lang=\"en\">"
    print "  <head>"
    print "    <title>Debian Bug reports related to Skolelinux</title>"
    print "  </head>"
    print "  <body>"
    print "    <h1>Debian Bug reports related to Skolelinux</h1>"
    print "    <ul>"

def html_footer():
    print "    </ul>"
    print "  </body>"
    print "</html>"

def html_entry(bugnumber, title, info):
    url="http://bugs.debian.org/"
    print "      <li><a href=\"%s%s\">%s</a></li>\n" % (url, bugnumber, title)

if len(sys.argv) > 1:
    buglist = sys.argv[1]

bugs = []
bugfp = open(buglist,'r')
for line in bugfp.readlines():
    if len(line) == 0 or line.find(':') != -1 or line.find('#') != -1:
        continue
    line = line.rstrip()
    bugs.append(line)
    debug("Loading %s" % line)
bugfp.close()

# Why is this broken? [pere 2003-09-28]
#bugs.sort(lambda a,b: -cmp(a[1],b[1]))

html_header()
for (bugnumber) in bugs:
    debug("%s..." % bugnumber)
    (title, info) = debianbts.get_report(bugnumber, ldap_ok = 0)
    html_entry(bugnumber, title, info)
html_footer()
