Port ubuntu-build to Python 3

This commit is contained in:
Stefano Rivera 2019-09-04 17:20:40 -03:00
parent 2c8c4d7268
commit 6c375255c4
2 changed files with 40 additions and 39 deletions

View File

@ -42,6 +42,7 @@ if sys.version_info[0] >= 3:
'sponsor-patch', 'sponsor-patch',
'submittodebian', 'submittodebian',
'syncpackage', 'syncpackage',
'ubuntu-build',
] ]
data_files = [ data_files = [
('share/bash-completion/completions', glob.glob("bash_completion/*")), ('share/bash-completion/completions', glob.glob("bash_completion/*")),
@ -53,7 +54,6 @@ else:
scripts = [ scripts = [
'import-bug-from-debian', 'import-bug-from-debian',
'merge-changelog', 'merge-changelog',
'ubuntu-build',
'ubuntu-iso', 'ubuntu-iso',
'ubuntu-upload-permission', 'ubuntu-upload-permission',
'update-maintainer', 'update-maintainer',

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# ubuntu-build - command line interface for Launchpad buildd operations. # ubuntu-build - command line interface for Launchpad buildd operations.
# #
@ -108,15 +108,15 @@ def main():
# Check our operation. # Check our operation.
if op not in ("rescore", "retry", "status"): if op not in ("rescore", "retry", "status"):
print >> sys.stderr, "Invalid operation: %s." % op print("Invalid operation: %s." % op, file=sys.stderr)
sys.exit(1) sys.exit(1)
# If the user has specified an architecture to build, we only wish to # If the user has specified an architecture to build, we only wish to
# rebuild it and nothing else. # rebuild it and nothing else.
if options.architecture: if options.architecture:
if options.architecture[0] not in valid_archs: if options.architecture[0] not in valid_archs:
print >> sys.stderr, ("Invalid architecture specified: %s." print("Invalid architecture specified: %s."
% options.architecture[0]) % options.architecture[0], file=sys.stderr)
sys.exit(1) sys.exit(1)
else: else:
one_arch = True one_arch = True
@ -126,8 +126,8 @@ def main():
# split release and pocket # split release and pocket
try: try:
(release, pocket) = split_release_pocket(release) (release, pocket) = split_release_pocket(release)
except PocketDoesNotExistError, error: except PocketDoesNotExistError as error:
print 'E: %s' % error print('E: %s' % error)
sys.exit(1) sys.exit(1)
# Get the ubuntu archive # Get the ubuntu archive
@ -140,8 +140,8 @@ def main():
try: try:
sources = ubuntu_archive.getSourcePackage(package, release, pocket) sources = ubuntu_archive.getSourcePackage(package, release, pocket)
distroseries = Distribution('ubuntu').getSeries(release) distroseries = Distribution('ubuntu').getSeries(release)
except (SeriesNotFoundException, PackageNotFoundException), error: except (SeriesNotFoundException, PackageNotFoundException) as error:
print error print(error)
sys.exit(1) sys.exit(1)
# Get list of builds for that package. # Get list of builds for that package.
builds = sources.getBuilds() builds = sources.getBuilds()
@ -163,16 +163,16 @@ def main():
pocket=pocket) pocket=pocket)
if op in ('rescore', 'retry') and not necessary_privs: if op in ('rescore', 'retry') and not necessary_privs:
print >> sys.stderr, ("You cannot perform the %s operation on a %s " print(("You cannot perform the %s operation on a %s package as "
"package as you do not have the permissions " "you do not have the permissions to do this action.")
"to do this action." % (op, component)) % (op, component), file=sys.stderr)
sys.exit(1) sys.exit(1)
# Output details. # Output details.
print("The source version for '%s' in %s (%s) is at %s." % print("The source version for '%s' in %s (%s) is at %s."
(package, release.capitalize(), component, version)) % (package, release.capitalize(), component, version))
print "Current build status for this package:" print("Current build status for this package:")
# Output list of arches for package and their status. # Output list of arches for package and their status.
done = False done = False
@ -182,28 +182,29 @@ def main():
continue continue
done = True done = True
print "%s: %s." % (build.arch_tag, build.buildstate) print("%s: %s." % (build.arch_tag, build.buildstate))
if op == 'rescore': if op == 'rescore':
if build.can_be_rescored: if build.can_be_rescored:
# FIXME: make priority an option # FIXME: make priority an option
priority = 5000 priority = 5000
print 'Rescoring build %s to %d...' % (build.arch_tag, priority) print('Rescoring build %s to %d...'
% (build.arch_tag, priority))
build.rescore(score=priority) build.rescore(score=priority)
else: else:
print 'Cannot rescore build on %s.' % build.arch_tag print('Cannot rescore build on %s.' % build.arch_tag)
if op == 'retry': if op == 'retry':
if build.can_be_retried: if build.can_be_retried:
print 'Retrying build on %s...' % build.arch_tag print('Retrying build on %s...' % build.arch_tag)
build.retry() build.retry()
else: else:
print 'Cannot retry build on %s.' % build.arch_tag print('Cannot retry build on %s.' % build.arch_tag)
# We are done # We are done
if done: if done:
sys.exit(0) sys.exit(0)
print("No builds for '%s' found in the %s release - it may have been " print(("No builds for '%s' found in the %s release - it may have been "
"built in a former release." % (package, release.capitalize())) "built in a former release.") % (package, release.capitalize()))
sys.exit(0) sys.exit(0)
# Batch mode # Batch mode
@ -223,15 +224,15 @@ def main():
+ '-proposed') + '-proposed')
try: try:
(release, pocket) = split_release_pocket(release) (release, pocket) = split_release_pocket(release)
except PocketDoesNotExistError, error: except PocketDoesNotExistError as error:
print 'E: %s' % error print('E: %s' % error)
sys.exit(1) sys.exit(1)
ubuntu_archive = Distribution('ubuntu').getArchive() ubuntu_archive = Distribution('ubuntu').getArchive()
try: try:
distroseries = Distribution('ubuntu').getSeries(release) distroseries = Distribution('ubuntu').getSeries(release)
except SeriesNotFoundException, error: except SeriesNotFoundException as error:
print error print(error)
sys.exit(1) sys.exit(1)
me = PersonTeam.me me = PersonTeam.me
@ -240,14 +241,14 @@ def main():
and me.isLpTeamMember('launchpad-buildd-admins')) and me.isLpTeamMember('launchpad-buildd-admins'))
or False) or False)
if options.priority and not can_rescore: if options.priority and not can_rescore:
print >> sys.stderr, ("You don't have the permissions to rescore " print("You don't have the permissions to rescore builds. "
"builds. Ignoring your rescore request.") "Ignoring your rescore request.", file=sys.stderr)
for pkg in args: for pkg in args:
try: try:
pkg = ubuntu_archive.getSourcePackage(pkg, release, pocket) pkg = ubuntu_archive.getSourcePackage(pkg, release, pocket)
except PackageNotFoundException, error: except PackageNotFoundException as error:
print error print(error)
continue continue
# Check permissions (part 2): check upload permissions for the source # Check permissions (part 2): check upload permissions for the source
@ -257,20 +258,20 @@ def main():
pkg.getPackageName(), pkg.getPackageName(),
pkg.getComponent()) pkg.getComponent())
if options.retry and not can_retry: if options.retry and not can_retry:
print >> sys.stderr, ("You don't have the permissions to retry the " print(("You don't have the permissions to retry the build of "
"build of '%s'. Ignoring your request." "'%s'. Ignoring your request.")
% pkg.getPackageName()) % pkg.getPackageName(), file=sys.stderr)
print "The source version for '%s' in '%s' (%s) is: %s" % ( print("The source version for '%s' in '%s' (%s) is: %s"
pkg.getPackageName(), release, pocket, pkg.getVersion()) % (pkg.getPackageName(), release, pocket, pkg.getVersion()))
print pkg.getBuildStates(archs) print(pkg.getBuildStates(archs))
if can_retry: if can_retry:
print pkg.retryBuilds(archs) print(pkg.retryBuilds(archs))
if options.priority and can_rescore: if options.priority and can_rescore:
print pkg.rescoreBuilds(archs, options.priority) print(pkg.rescoreBuilds(archs, options.priority))
print '' print()
if __name__ == '__main__': if __name__ == '__main__':