Initial pkg-on-images tool

This commit is contained in:
Stefano Rivera 2011-12-03 17:02:47 +02:00
parent 2e8f16c972
commit 30cb57b32c

82
pkg-on-images Executable file
View File

@ -0,0 +1,82 @@
#!/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.
import gzip
import json
import optparse
import os
import time
import urllib
from ubuntutools.lp.lpapicache import Distribution
DATA_URL = ('http://people.ubuntuwire.org/~stefanor/ubuntu-image-contents/'
'image_contents.json.gz')
def load_index():
cachedir = os.path.expanduser('~/.cache/ubuntu-dev-tools')
fn = os.path.join(cachedir, 'image_contents.json.gz')
if (not os.path.isfile(fn)
or time.time() - os.path.getmtime(fn) > 60 * 60 * 24):
if not os.path.isdir(cachedir):
os.makedirs(cachedir)
urllib.urlretrieve(DATA_URL, fn)
with gzip.open(fn, 'r') as f:
return json.load(f)
def main():
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)")
options, args = parser.parse_args()
if len(args) < 1:
parser.error("At least one package must be specified")
index = load_index()
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
else:
archive = Distribution('ubuntu').getArchive()
for source in args:
spph = archive.getSourcePackage(source)
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 ("%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__':
main()