2011-12-03 17:02:47 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
|
|
|
|
#
|
|
|
|
# Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
|
|
# copyright notice and this permission notice appear in all copies.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
2011-12-06 00:24:11 +02:00
|
|
|
import collections
|
2011-12-03 17:02:47 +02:00
|
|
|
import gzip
|
|
|
|
import json
|
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import urllib
|
|
|
|
|
2011-12-04 00:09:51 +02:00
|
|
|
from devscripts.logger import Logger
|
|
|
|
|
|
|
|
from ubuntutools.lp.lpapicache import Distribution, PackageNotFoundException
|
2011-12-03 17:02:47 +02:00
|
|
|
|
2011-12-08 00:01:56 +02:00
|
|
|
DATA_URL = 'http://qa.ubuntuwire.org/ubuntu-seeded-packages/seeded.json.gz'
|
2011-12-03 17:02:47 +02:00
|
|
|
|
|
|
|
|
2011-12-06 00:24:11 +02:00
|
|
|
def load_index(url):
|
2011-12-04 00:09:51 +02:00
|
|
|
'''Download a new copy of the image contents index, if necessary,
|
|
|
|
and read it.
|
|
|
|
'''
|
2011-12-03 17:02:47 +02:00
|
|
|
cachedir = os.path.expanduser('~/.cache/ubuntu-dev-tools')
|
2011-12-06 00:24:11 +02:00
|
|
|
fn = os.path.join(cachedir, 'seeded.json.gz')
|
2011-12-03 17:02:47 +02:00
|
|
|
|
|
|
|
if (not os.path.isfile(fn)
|
2011-12-06 00:24:11 +02:00
|
|
|
or time.time() - os.path.getmtime(fn) > 60 * 60 * 2):
|
2011-12-03 17:02:47 +02:00
|
|
|
if not os.path.isdir(cachedir):
|
|
|
|
os.makedirs(cachedir)
|
2011-12-06 00:24:11 +02:00
|
|
|
urllib.urlretrieve(url, fn)
|
2011-12-03 17:02:47 +02:00
|
|
|
|
|
|
|
with gzip.open(fn, 'r') as f:
|
|
|
|
return json.load(f)
|
|
|
|
|
|
|
|
|
2011-12-06 00:24:11 +02:00
|
|
|
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')
|
2011-12-08 00:27:58 +02:00
|
|
|
output = [' %s: %s' % (flavor, ', '.join(sorted(types)))
|
|
|
|
for flavor, types in present.iteritems()]
|
|
|
|
output.sort()
|
|
|
|
return '\n'.join(output)
|
2011-12-06 00:24:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
def output_binaries(index, binaries):
|
|
|
|
'''Print binaries found in index'''
|
|
|
|
for binary in binaries:
|
|
|
|
if binary in index:
|
2011-12-08 00:27:58 +02:00
|
|
|
print "%s is seeded in:" % binary
|
|
|
|
print present_on(index[binary])
|
2011-12-06 00:24:11 +02:00
|
|
|
else:
|
2011-12-08 00:27:58 +02:00
|
|
|
print "%s is not seeded." % binary
|
2011-12-06 00:24:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2011-12-08 00:29:20 +02:00
|
|
|
print "%s (from %s) is seeded in:" % (binary, source)
|
2011-12-08 00:27:58 +02:00
|
|
|
print present_on(index[binary])
|
2011-12-06 00:24:11 +02:00
|
|
|
if not seen:
|
2011-12-08 00:27:58 +02:00
|
|
|
print "%s's binaries are not seeded." % source
|
2011-12-06 00:24:11 +02:00
|
|
|
|
|
|
|
|
2011-12-03 17:02:47 +02:00
|
|
|
def main():
|
2011-12-04 00:09:51 +02:00
|
|
|
'''Query which images the specified packages are on'''
|
2011-12-03 17:02:47 +02:00
|
|
|
parser = optparse.OptionParser('%prog [options] package...')
|
|
|
|
parser.add_option('-b', '--binary',
|
|
|
|
default=False, action='store_true',
|
|
|
|
help="Binary packages are being specified, "
|
|
|
|
"not source packages (fast)")
|
2011-12-06 00:29:32 +02:00
|
|
|
parser.add_option('-u', '--data-url', metavar='URL',
|
2011-12-06 00:24:11 +02:00
|
|
|
default=DATA_URL,
|
2011-12-06 00:29:32 +02:00
|
|
|
help='URL for the seeded packages index. '
|
2011-12-06 00:24:11 +02:00
|
|
|
'Default: UbuntuWire')
|
2011-12-03 17:02:47 +02:00
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if len(args) < 1:
|
|
|
|
parser.error("At least one package must be specified")
|
|
|
|
|
2011-12-07 01:29:16 +02:00
|
|
|
index = load_index(options.data_url)
|
2011-12-03 17:02:47 +02:00
|
|
|
if options.binary:
|
2011-12-06 00:24:11 +02:00
|
|
|
output_binaries(index, args)
|
2011-12-03 17:02:47 +02:00
|
|
|
else:
|
2011-12-06 00:24:11 +02:00
|
|
|
binaries = resolve_binaries(args)
|
|
|
|
output_by_source(index, binaries)
|
2011-12-03 17:02:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|