mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-16 01:21:07 +00:00
Tighter output
This commit is contained in:
parent
7d5efa8a76
commit
f4793f0df0
@ -14,6 +14,7 @@
|
|||||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
import collections
|
||||||
import gzip
|
import gzip
|
||||||
import json
|
import json
|
||||||
import optparse
|
import optparse
|
||||||
@ -25,27 +26,80 @@ from devscripts.logger import Logger
|
|||||||
|
|
||||||
from ubuntutools.lp.lpapicache import Distribution, PackageNotFoundException
|
from ubuntutools.lp.lpapicache import Distribution, PackageNotFoundException
|
||||||
|
|
||||||
DATA_URL = ('http://people.ubuntuwire.org/~stefanor/ubuntu-image-contents/'
|
DATA_URL = ('http://people.ubuntuwire.org/~stefanor/ubuntu-seeded-packages/'
|
||||||
'image_contents.json.gz')
|
'seeded.json.gz')
|
||||||
|
|
||||||
|
|
||||||
def load_index():
|
def load_index(url):
|
||||||
'''Download a new copy of the image contents index, if necessary,
|
'''Download a new copy of the image contents index, if necessary,
|
||||||
and read it.
|
and read it.
|
||||||
'''
|
'''
|
||||||
cachedir = os.path.expanduser('~/.cache/ubuntu-dev-tools')
|
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)
|
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):
|
if not os.path.isdir(cachedir):
|
||||||
os.makedirs(cachedir)
|
os.makedirs(cachedir)
|
||||||
urllib.urlretrieve(DATA_URL, fn)
|
urllib.urlretrieve(url, fn)
|
||||||
|
|
||||||
with gzip.open(fn, 'r') as f:
|
with gzip.open(fn, 'r') as f:
|
||||||
return json.load(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():
|
def main():
|
||||||
'''Query which images the specified packages are on'''
|
'''Query which images the specified packages are on'''
|
||||||
parser = optparse.OptionParser('%prog [options] package...')
|
parser = optparse.OptionParser('%prog [options] package...')
|
||||||
@ -53,39 +107,21 @@ def main():
|
|||||||
default=False, action='store_true',
|
default=False, action='store_true',
|
||||||
help="Binary packages are being specified, "
|
help="Binary packages are being specified, "
|
||||||
"not source packages (fast)")
|
"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()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
parser.error("At least one package must be specified")
|
parser.error("At least one package must be specified")
|
||||||
|
|
||||||
index = load_index()
|
index = load_index(options.service_url)
|
||||||
if options.binary:
|
if options.binary:
|
||||||
for binary in args:
|
output_binaries(index, 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
|
|
||||||
else:
|
else:
|
||||||
archive = Distribution('ubuntu').getArchive()
|
binaries = resolve_binaries(args)
|
||||||
for source in args:
|
output_by_source(index, binaries)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user