Some error handling (and other bits)

This commit is contained in:
Stefano Rivera 2011-12-04 00:09:51 +02:00
parent 30cb57b32c
commit 09a870fa43

View File

@ -21,13 +21,18 @@ import os
import time import time
import urllib import urllib
from ubuntutools.lp.lpapicache import Distribution from devscripts.logger import Logger
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-image-contents/'
'image_contents.json.gz') 'image_contents.json.gz')
def load_index(): def load_index():
'''Download a new copy of the image contents index, if necessary,
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, 'image_contents.json.gz')
@ -42,6 +47,7 @@ def load_index():
def main(): def main():
'''Query which images the specified packages are on'''
parser = optparse.OptionParser('%prog [options] package...') parser = optparse.OptionParser('%prog [options] package...')
parser.add_option('-b', '--binary', parser.add_option('-b', '--binary',
default=False, action='store_true', default=False, action='store_true',
@ -63,7 +69,11 @@ def main():
else: else:
archive = Distribution('ubuntu').getArchive() archive = Distribution('ubuntu').getArchive()
for source in args: for source in args:
try:
spph = archive.getSourcePackage(source) spph = archive.getSourcePackage(source)
except PackageNotFoundException, e:
Logger.error(str(e))
continue
binaries = frozenset(bpph.getPackageName() binaries = frozenset(bpph.getPackageName()
for bpph in spph.getBinaries()) for bpph in spph.getBinaries())
present = False present = False
@ -71,7 +81,7 @@ def main():
if binary in index: if binary in index:
present = True present = True
for flavor, type_ in index[binary]: for flavor, type_ in index[binary]:
print ("%s: %s is present on %s %s" print ("src:%s: %s is present on %s %s"
% (source, binary, flavor, type_)) % (source, binary, flavor, type_))
if not present: if not present:
print ("No binaries from %s are present on any current images" print ("No binaries from %s are present on any current images"