#!/usr/bin/env python2
# Really simple madison-like reporting tool that uses source_map data for
# reporting.  Note that it only reports the highest version's entry for
# a given source pkg's release.
#
# Copyright 2008-2010, Canonical Ltd.
# Author: Kees Cook <kees@ubuntu.com>
# Author: Jamie Strandboge <jamie@ubuntu.com>
import sys
import cve_lib
import optparse

parser = optparse.OptionParser()
parser.add_option("--release", help="Limit to comma-separates list of releases", metavar="NAME", action='store', default=None)
(opt, args) = parser.parse_args()

import source_map
info = source_map.load()

releases = None
if opt.release:
    releases = opt.release.split(',')

for source in args:
    answer = source_map.madison(info, source, releases)

    for name in sorted(answer.keys()):
        rel, component = name.split('/',1)
        pocket=''
        if '-' in rel:
            rel, pocket = rel.split('-',1)
        for pkg in sorted(answer[name].keys()):
            suffix=""
            if component in ['main','restricted'] and not cve_lib.is_supported(info, pkg, rel):
                suffix = "[unsupported]"
            print '%s | %s | %s%s' % (pkg, answer[name][pkg], name, suffix)
