mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-24 09:21:08 +00:00
Print errors to stderr
This commit is contained in:
parent
781d077af8
commit
2f4abf3d71
@ -28,7 +28,7 @@
|
|||||||
# configurations. For example, a symlink called pbuilder-hardy will assume
|
# configurations. For example, a symlink called pbuilder-hardy will assume
|
||||||
# that the target distribution is always meant to be Ubuntu Hardy.
|
# that the target distribution is always meant to be Ubuntu Hardy.
|
||||||
|
|
||||||
import sys
|
from sys import exit, argv, stderr
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import ubuntutools.misc
|
import ubuntutools.misc
|
||||||
@ -80,8 +80,8 @@ class pbuilder_dist:
|
|||||||
paths = set(os.environ['PATH'].split(':'))
|
paths = set(os.environ['PATH'].split(':'))
|
||||||
paths |= set(('/sbin', '/usr/sbin', '/usr/local/sbin'))
|
paths |= set(('/sbin', '/usr/sbin', '/usr/local/sbin'))
|
||||||
if not any(os.path.exists(os.path.join(p, builder)) for p in paths):
|
if not any(os.path.exists(os.path.join(p, builder)) for p in paths):
|
||||||
print 'Error: Could not find "%s".' % builder
|
print >> stderr, 'Error: Could not find "%s".' % builder
|
||||||
sys.exit(1)
|
exit(1)
|
||||||
|
|
||||||
##############################################################
|
##############################################################
|
||||||
|
|
||||||
@ -117,21 +117,22 @@ class pbuilder_dist:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if not distro.isalpha():
|
if not distro.isalpha():
|
||||||
print 'Error: «%s» is an invalid distribution codename.' % distro
|
print >> stderr, ('Error: "%s" is an invalid distribution codename.'
|
||||||
sys.exit(1)
|
% distro)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
if not os.path.isfile(os.path.join('/usr/share/debootstrap/scripts/', distro)):
|
if not os.path.isfile(os.path.join('/usr/share/debootstrap/scripts/', distro)):
|
||||||
if os.path.isdir('/usr/share/debootstrap/scripts/'):
|
if os.path.isdir('/usr/share/debootstrap/scripts/'):
|
||||||
# Debian experimental doesn't have a debootstrap file but
|
# Debian experimental doesn't have a debootstrap file but
|
||||||
# should work nevertheless.
|
# should work nevertheless.
|
||||||
if distro not in debian_distros:
|
if distro not in debian_distros:
|
||||||
answer = ask('Warning: Unknown distribution «%s». Do you ' \
|
answer = ask('Warning: Unknown distribution "%s". Do you ' \
|
||||||
'want to continue [y/N]? ' % distro)
|
'want to continue [y/N]? ' % distro)
|
||||||
if answer not in ('y', 'Y'):
|
if answer not in ('y', 'Y'):
|
||||||
sys.exit(0)
|
exit(0)
|
||||||
else:
|
else:
|
||||||
print 'Please install package "debootstrap".'
|
print >> stderr, 'Please install package "debootstrap".'
|
||||||
sys.exit(1)
|
exit(1)
|
||||||
|
|
||||||
self.target_distro = distro
|
self.target_distro = distro
|
||||||
|
|
||||||
@ -152,12 +153,12 @@ class pbuilder_dist:
|
|||||||
self.operation = 'build'
|
self.operation = 'build'
|
||||||
return [operation]
|
return [operation]
|
||||||
else:
|
else:
|
||||||
print 'Error: Could not find file «%s».' % operation
|
print >> stderr, 'Error: Could not find file "%s".' % operation
|
||||||
sys.exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
print 'Error: «%s» is not a recognized argument.' % operation
|
print >> stderr, 'Error: "%s" is not a recognized argument.' % operation
|
||||||
print 'Please use one of those: ' + ', '.join(arguments) + '.'
|
print >> stderr, 'Please use one of these: %s.' % ', '.join(arguments)
|
||||||
sys.exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
self.operation = operation
|
self.operation = operation
|
||||||
return []
|
return []
|
||||||
@ -191,8 +192,8 @@ class pbuilder_dist:
|
|||||||
elif self.builder == 'cowbuilder':
|
elif self.builder == 'cowbuilder':
|
||||||
base = '--basepath "%s-base.cow"' % prefix
|
base = '--basepath "%s-base.cow"' % prefix
|
||||||
else:
|
else:
|
||||||
print 'Error: Unrecognized builder "%s".' % self.builder
|
print >> stderr, 'Error: Unrecognized builder "%s".' % self.builder
|
||||||
sys.exit(1)
|
exit(1)
|
||||||
|
|
||||||
arguments = [
|
arguments = [
|
||||||
'--%s' % self.operation,
|
'--%s' % self.operation,
|
||||||
@ -291,7 +292,7 @@ def help(exit_code = 0):
|
|||||||
|
|
||||||
print 'See man pbuilder-dist for more information.'
|
print 'See man pbuilder-dist for more information.'
|
||||||
|
|
||||||
sys.exit(exit_code)
|
exit(exit_code)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" main() -> None
|
""" main() -> None
|
||||||
@ -303,19 +304,19 @@ def main():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
script_name = os.path.basename(sys.argv[0])
|
script_name = os.path.basename(argv[0])
|
||||||
parts = script_name.split('-')
|
parts = script_name.split('-')
|
||||||
|
|
||||||
# Copy arguments into another list for save manipulation
|
# Copy arguments into another list for save manipulation
|
||||||
args = sys.argv[1:]
|
args = argv[1:]
|
||||||
|
|
||||||
if '-' in script_name and (parts[0] != 'pbuilder' and \
|
if '-' in script_name and (parts[0] != 'pbuilder' and \
|
||||||
parts[0] != 'cowbuilder') or len(parts) > 3:
|
parts[0] != 'cowbuilder') or len(parts) > 3:
|
||||||
print 'Error: «%s» is not a valid name for a «pbuilder-dist» executable.' % script_name
|
print >> stderr, 'Error: "%s" is not a valid name for a "pbuilder-dist" executable.' % script_name
|
||||||
sys.exit(1)
|
exit(1)
|
||||||
|
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
print 'Insufficient number of arguments.'
|
print >> stderr, 'Insufficient number of arguments.'
|
||||||
help(1)
|
help(1)
|
||||||
|
|
||||||
if args[0] in ('-h', '--help', 'help'):
|
if args[0] in ('-h', '--help', 'help'):
|
||||||
@ -347,27 +348,27 @@ def main():
|
|||||||
("sparc64", "sparc")]:
|
("sparc64", "sparc")]:
|
||||||
args.append('--debootstrap qemu-debootstrap')
|
args.append('--debootstrap qemu-debootstrap')
|
||||||
|
|
||||||
if 'mainonly' in sys.argv or '--main-only' in sys.argv:
|
if 'mainonly' in argv or '--main-only' in argv:
|
||||||
app.extra_components = False
|
app.extra_components = False
|
||||||
if 'mainonly' in sys.argv:
|
if 'mainonly' in argv:
|
||||||
args.remove('mainonly')
|
args.remove('mainonly')
|
||||||
else:
|
else:
|
||||||
args.remove('--main-only')
|
args.remove('--main-only')
|
||||||
|
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
print 'Insufficient number of arguments.'
|
print >> stderr, 'Insufficient number of arguments.'
|
||||||
help(1)
|
help(1)
|
||||||
|
|
||||||
# Parse the operation
|
# Parse the operation
|
||||||
args = app.set_operation(args.pop(0)) + args
|
args = app.set_operation(args.pop(0)) + args
|
||||||
|
|
||||||
if app.operation == 'build' and not '.dsc' in ' '.join(args):
|
if app.operation == 'build' and not '.dsc' in ' '.join(args):
|
||||||
print 'Error: You have to specify a .dsc file if you want to build.'
|
print >> stderr, 'Error: You have to specify a .dsc file if you want to build.'
|
||||||
sys.exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Execute the pbuilder command
|
# Execute the pbuilder command
|
||||||
if not '--debug-echo' in args:
|
if not '--debug-echo' in args:
|
||||||
sys.exit(os.system(app.get_command(args)))
|
exit(os.system(app.get_command(args)))
|
||||||
else:
|
else:
|
||||||
print app.get_command((args)).replace(
|
print app.get_command((args)).replace(
|
||||||
' --debug-echo', '')
|
' --debug-echo', '')
|
||||||
@ -377,5 +378,5 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print 'Manually aborted.'
|
print >> stderr, 'Manually aborted.'
|
||||||
sys.exit(1)
|
exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user