From f4793f0df0cf358008f9008f0577ca2172e2272d Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 6 Dec 2011 00:24:11 +0200 Subject: [PATCH] Tighter output --- ubuntu-safe-to-upload | 100 ++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 32 deletions(-) diff --git a/ubuntu-safe-to-upload b/ubuntu-safe-to-upload index 96de298..6b3b24f 100755 --- a/ubuntu-safe-to-upload +++ b/ubuntu-safe-to-upload @@ -14,6 +14,7 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +import collections import gzip import json import optparse @@ -25,27 +26,80 @@ from devscripts.logger import Logger from ubuntutools.lp.lpapicache import Distribution, PackageNotFoundException -DATA_URL = ('http://people.ubuntuwire.org/~stefanor/ubuntu-image-contents/' - 'image_contents.json.gz') +DATA_URL = ('http://people.ubuntuwire.org/~stefanor/ubuntu-seeded-packages/' + 'seeded.json.gz') -def load_index(): +def load_index(url): '''Download a new copy of the image contents index, if necessary, and read it. ''' cachedir = os.path.expanduser('~/.cache/ubuntu-dev-tools') - fn = os.path.join(cachedir, 'image_contents.json.gz') + fn = os.path.join(cachedir, 'seeded.json.gz') if (not os.path.isfile(fn) - or time.time() - os.path.getmtime(fn) > 60 * 60 * 24): + or time.time() - os.path.getmtime(fn) > 60 * 60 * 2): if not os.path.isdir(cachedir): os.makedirs(cachedir) - urllib.urlretrieve(DATA_URL, fn) + urllib.urlretrieve(url, fn) with gzip.open(fn, 'r') as f: return json.load(f) +def resolve_binaries(sources): + '''Return a dict of source:binaries for all binary packages built by + sources + ''' + archive = Distribution('ubuntu').getArchive() + binaries = {} + for source in sources: + try: + spph = archive.getSourcePackage(source) + except PackageNotFoundException, e: + Logger.error(str(e)) + continue + binaries[source] = sorted(set(bpph.getPackageName() + for bpph in spph.getBinaries())) + + return binaries + + +def present_on(appearences): + '''Format a list of (flavor, type) tuples into a human-readable string''' + present = collections.defaultdict(set) + for flavor, type_ in appearences: + present[flavor].add(type_) + for flavor, types in present.iteritems(): + if len(types) > 1: + types.discard('supported') + return ', '.join('%s [%s]' % (flavor, ' '.join(sorted(types))) + for flavor, types in present.iteritems()) + + +def output_binaries(index, binaries): + '''Print binaries found in index''' + for binary in binaries: + if binary in index: + present = present_on(index[binary]) + print "%s is seeded in: %s" % (binary, present) + else: + print "%s is not seeded" % binary + + +def output_by_source(index, by_source): + '''Print binaries found in index. Grouped by source''' + for source, binaries in by_source.iteritems(): + seen = False + for binary in binaries: + if binary in index: + seen = True + present = present_on(index[binary]) + print "%s: %s is seeded in: %s" % (source, binary, present) + if not seen: + print "%s's binaries are not seeded" % source + + def main(): '''Query which images the specified packages are on''' parser = optparse.OptionParser('%prog [options] package...') @@ -53,39 +107,21 @@ def main(): default=False, action='store_true', help="Binary packages are being specified, " "not source packages (fast)") + parser.add_option('-u', '--service-url', metavar='URL', + default=DATA_URL, + help='Reverse Dependencies webservice URL. ' + 'Default: UbuntuWire') options, args = parser.parse_args() if len(args) < 1: parser.error("At least one package must be specified") - index = load_index() + index = load_index(options.service_url) if options.binary: - for binary in args: - if binary in index: - for flavor, type_ in index[binary]: - print "%s is present on %s %s" % (binary, flavor, type_) - else: - print "%s is not present on any current images" % binary + output_binaries(index, args) else: - archive = Distribution('ubuntu').getArchive() - for source in args: - try: - spph = archive.getSourcePackage(source) - except PackageNotFoundException, e: - Logger.error(str(e)) - continue - binaries = frozenset(bpph.getPackageName() - for bpph in spph.getBinaries()) - present = False - for binary in binaries: - if binary in index: - present = True - for flavor, type_ in index[binary]: - print ("src:%s: %s is present on %s %s" - % (source, binary, flavor, type_)) - if not present: - print ("No binaries from %s are present on any current images" - % source) + binaries = resolve_binaries(args) + output_by_source(index, binaries) if __name__ == '__main__':