Port seeded-in-ubuntu to Python 3

This commit is contained in:
Stefano Rivera 2019-09-04 16:43:12 -03:00
parent 31d1ae269a
commit 673234e449
2 changed files with 18 additions and 18 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com> # Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
# #
@ -20,7 +20,7 @@ import json
import optparse import optparse
import os import os
import time import time
import urllib import urllib.request
from ubuntutools.lp.lpapicache import (Distribution, Launchpad, from ubuntutools.lp.lpapicache import (Distribution, Launchpad,
PackageNotFoundException) PackageNotFoundException)
@ -40,12 +40,12 @@ def load_index(url):
or time.time() - os.path.getmtime(fn) > 60 * 60 * 2): 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(url, fn) urllib.request.urlretrieve(url, fn)
try: try:
with gzip.open(fn, 'r') as f: with gzip.open(fn, 'r') as f:
return json.load(f) return json.load(f)
except Exception, e: except Exception as e:
Logger.error("Unable to parse seed data: %s. " Logger.error("Unable to parse seed data: %s. "
"Deleting cached data, please try again.", "Deleting cached data, please try again.",
str(e)) str(e))
@ -61,7 +61,7 @@ def resolve_binaries(sources):
for source in sources: for source in sources:
try: try:
spph = archive.getSourcePackage(source) spph = archive.getSourcePackage(source)
except PackageNotFoundException, e: except PackageNotFoundException as e:
Logger.error(str(e)) Logger.error(str(e))
continue continue
binaries[source] = sorted(set(bpph.getPackageName() binaries[source] = sorted(set(bpph.getPackageName()
@ -75,11 +75,11 @@ def present_on(appearences):
present = collections.defaultdict(set) present = collections.defaultdict(set)
for flavor, type_ in appearences: for flavor, type_ in appearences:
present[flavor].add(type_) present[flavor].add(type_)
for flavor, types in present.iteritems(): for flavor, types in present.items():
if len(types) > 1: if len(types) > 1:
types.discard('supported') types.discard('supported')
output = [' %s: %s' % (flavor, ', '.join(sorted(types))) output = [' %s: %s' % (flavor, ', '.join(sorted(types)))
for flavor, types in present.iteritems()] for flavor, types in present.items()]
output.sort() output.sort()
return '\n'.join(output) return '\n'.join(output)
@ -88,28 +88,28 @@ def output_binaries(index, binaries):
'''Print binaries found in index''' '''Print binaries found in index'''
for binary in binaries: for binary in binaries:
if binary in index: if binary in index:
print "%s is seeded in:" % binary print("%s is seeded in:" % binary)
print present_on(index[binary]) print(present_on(index[binary]))
else: else:
print "%s is not seeded (and may not exist)." % binary print("%s is not seeded (and may not exist)." % binary)
def output_by_source(index, by_source): def output_by_source(index, by_source):
'''Print binaries found in index. Grouped by source''' '''Print binaries found in index. Grouped by source'''
for source, binaries in by_source.iteritems(): for source, binaries in by_source.items():
seen = False seen = False
if not binaries: if not binaries:
print ("Status unknown: No binary packages built by the latest " print("Status unknown: No binary packages built by the latest "
"%s.\nTry again using -b and the expected binary packages." "%s.\nTry again using -b and the expected binary packages."
% source) % source)
continue continue
for binary in binaries: for binary in binaries:
if binary in index: if binary in index:
seen = True seen = True
print "%s (from %s) is seeded in:" % (binary, source) print("%s (from %s) is seeded in:" % (binary, source))
print present_on(index[binary]) print(present_on(index[binary]))
if not seen: if not seen:
print "%s's binaries are not seeded." % source print("%s's binaries are not seeded." % source)
def main(): def main():

View File

@ -37,6 +37,7 @@ if sys.version_info[0] >= 3:
'requestsync', 'requestsync',
'reverse-build-depends', 'reverse-build-depends',
'reverse-depends', 'reverse-depends',
'seeded-in-ubuntu',
'setup-packaging-environment', 'setup-packaging-environment',
] ]
data_files = [ data_files = [
@ -49,7 +50,6 @@ else:
scripts = [ scripts = [
'import-bug-from-debian', 'import-bug-from-debian',
'merge-changelog', 'merge-changelog',
'seeded-in-ubuntu',
'sponsor-patch', 'sponsor-patch',
'submittodebian', 'submittodebian',
'syncpackage', 'syncpackage',