backportpackage: Factor out subprocess.call error handling into a helper

This commit is contained in:
Evan Broder 2010-12-12 18:24:28 -08:00
parent 462cd8f4ca
commit 1a2677b8ef

View File

@ -33,6 +33,11 @@ def error(msg, *args, **kwargs):
logging.error(msg, *args, **kwargs) logging.error(msg, *args, **kwargs)
sys.exit(1) sys.exit(1)
def check_call(cmd, *args, **kwargs):
ret = subprocess.call(cmd, *args, **kwargs)
if ret != 0:
error('%s returned %d' % (cmd, ret))
def parse(args): def parse(args):
usage = 'Usage: %prog [options]' usage = 'Usage: %prog [options]'
p = optparse.OptionParser(usage) p = optparse.OptionParser(usage)
@ -130,13 +135,11 @@ def fetch_package(workdir, opts):
for f in srcpkg.sourceFileUrls(): for f in srcpkg.sourceFileUrls():
if f.endswith('.dsc'): if f.endswith('.dsc'):
if 0 != subprocess.call(['dget', check_call(['dget',
'--download-only', '--download-only',
'--allow-unauthenticated', '--allow-unauthenticated',
f], f],
cwd=workdir): cwd=workdir)
error('Error went wrong fetching the source package')
return os.path.join(workdir, os.path.basename(f)) return os.path.join(workdir, os.path.basename(f))
else: else:
error('Package %s contains no .dsc file' % opts.package) error('Package %s contains no .dsc file' % opts.package)
@ -166,12 +169,11 @@ def main(args):
for dest_release in dest_releases: for dest_release in dest_releases:
srcdir = os.path.join(tmpdir, package) srcdir = os.path.join(tmpdir, package)
if 0 != subprocess.call(['dpkg-source', check_call(['dpkg-source',
'-x', '-x',
dscfile, dscfile,
package], package],
cwd=tmpdir): cwd=tmpdir)
error('Something went wrong unpacking package %s' % package)
bp_version = v + ('~%s1' % dest_release) bp_version = v + ('~%s1' % dest_release)
bp_dist = dest_release bp_dist = dest_release
@ -179,17 +181,15 @@ def main(args):
bp_version += '~ppa1' bp_version += '~ppa1'
elif upload == 'ubuntu': elif upload == 'ubuntu':
bp_dist += '-backports' bp_dist += '-backports'
if 0 != subprocess.call(['dch', check_call(['dch',
'--force-bad-version', '--force-bad-version',
'--preserve', '--preserve',
'--newversion', bp_version, '--newversion', bp_version,
'--distribution', dest_release, '--distribution', dest_release,
'No-change backport to %s' % dest_release], 'No-change backport to %s' % dest_release],
cwd=srcdir): cwd=srcdir)
error('Something went wrong updating the package changelog') check_call(['debuild', '-S', '-sa'],
if 0 != subprocess.call(['debuild', '-S', '-sa'], cwd=srcdir)
cwd=srcdir):
error('Something went wrong while building the source package')
if ':' in bp_version: if ':' in bp_version:
bp_version = bp_version[bp_version.find(':')+1:] bp_version = bp_version[bp_version.find(':')+1:]
@ -198,11 +198,10 @@ def main(args):
while True: while True:
answer = raw_input('Do you still want to upload this to %s? [Y/n] ' % upload).strip().lower() answer = raw_input('Do you still want to upload this to %s? [Y/n] ' % upload).strip().lower()
if answer in ('', 'y', 'yes'): if answer in ('', 'y', 'yes'):
if 0 != subprocess.call(['dput', check_call(['dput',
upload, upload,
'%s_%s_source.changes' % (package, bp_version)], '%s_%s_source.changes' % (package, bp_version)],
cwd=tmpdir): cwd=tmpdir)
error('Something went wrong uploading the package %s to %s' % package, upload)
break break
elif answer in ('n', 'no'): elif answer in ('n', 'no'):