From 3db76b355a29501d070ae3242e2f9b4250c3e3c7 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 22 Jan 2011 11:21:52 +0200 Subject: [PATCH] pbuilder-dist: Use ubuntutools.logger. --- debian/changelog | 3 ++- debian/copyright | 2 +- pbuilder-dist | 61 +++++++++++++++++++++--------------------------- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/debian/changelog b/debian/changelog index f7376b0..6641242 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,8 +7,9 @@ ubuntu-dev-tools (0.113) UNRELEASED; urgency=low [ Stefano Rivera ] * backportpackage: dput correct changes filename (regression in 0.112) (LP: #706010) + * pbuilder-dist: Use ubuntutools.logger. - -- Benjamin Drung Sat, 22 Jan 2011 02:09:02 +0100 + -- Stefano Rivera Sat, 22 Jan 2011 11:21:33 +0200 ubuntu-dev-tools (0.112) unstable; urgency=low diff --git a/debian/copyright b/debian/copyright index 48a6d9a..d61234a 100644 --- a/debian/copyright +++ b/debian/copyright @@ -70,7 +70,7 @@ Copyright: 2007-2010, Canonical Ltd. 2006-2007, Pete Savage 2009, Ryan Kavanagh 2007, Siegfried-Angel Gevatter Pujals - 2010, Stefano Rivera + 2010-2011, Stefano Rivera 2008, Terence Simpson License: GPL-2+ This program is free software; you can redistribute it and/or modify diff --git a/pbuilder-dist b/pbuilder-dist index 8566569..40694be 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -1,9 +1,9 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- # -# Copyright (C) 2007-2010 Siegfried-A. Gevatter -# With some changes by Iain Lane , -# Stefano Rivera +# Copyright (C) 2007-2010, Siegfried-A. Gevatter , +# 2010-2011, Stefano Rivera +# With some changes by Iain Lane # Based upon pbuilder-dist-simple by Jamin Collins and Jordan Mantha. # # ################################################################## @@ -34,6 +34,7 @@ import subprocess import sys from ubuntutools.distro_info import DebianDistroInfo +from ubuntutools.logger import Logger import ubuntutools.misc class PbuilderDist: @@ -82,7 +83,7 @@ class PbuilderDist: paths = set(os.environ['PATH'].split(':')) paths |= set(('/sbin', '/usr/sbin', '/usr/local/sbin')) if not any(os.path.exists(os.path.join(p, builder)) for p in paths): - print >> sys.stderr, 'Error: Could not find "%s".' % builder + Logger.error('Could not find "%s".', builder) sys.exit(1) ############################################################## @@ -91,20 +92,18 @@ class PbuilderDist: '~/pbuilder/')) if 'SUDO_USER' in os.environ: - print >> sys.stderr, ("Warning: pbuilder-dist running under sudo. " - "This is probably not what you want. " - "pbuilder-dist will use sudo itself, " - "when necessary.") + Logger.warn('Running under sudo. ' + 'This is probably not what you want. ' + 'pbuilder-dist will use sudo itself, when necessary.') if os.stat(os.environ['HOME']).st_uid != os.getuid(): - print >> sys.stderr, "Error: You don't own $HOME" + Logger.error("Error: You don't own $HOME") sys.exit(1) if not os.path.isdir(self.base): try: os.makedirs(self.base) except OSError: - print >> sys.stderr, ('Error: Cannot create base directory "%s"' - % self.base) + Logger.error('Cannot create base directory "%s"', self.base) sys.exit(1) if 'PBUILDAUTH' in os.environ: @@ -126,8 +125,7 @@ class PbuilderDist: variable or finalize pbuilder-dist's execution. """ if not distro.isalpha(): - print >> sys.stderr, ('Error: "%s" is an invalid distribution ' - 'codename.' % distro) + Logger.error('"%s" is an invalid distribution codename.', distro) sys.exit(1) if not os.path.isfile(os.path.join('/usr/share/debootstrap/scripts/', @@ -141,7 +139,7 @@ class PbuilderDist: if answer not in ('y', 'Y'): sys.exit(0) else: - print >> sys.stderr, 'Please install package "debootstrap".' + Logger.error('Please install package "debootstrap".') sys.exit(1) self.target_distro = distro @@ -161,13 +159,12 @@ class PbuilderDist: self.operation = 'build' return [operation] else: - print >> sys.stderr, ('Error: Could not find file "%s".' - % operation) + Logger.error('Could not find file "%s".', operation) sys.exit(1) else: - print >> sys.stderr, ('Error: "%s" is not a recognized ' - 'argument.\nPlease use one of these: ' - '%s.') % (operation, ', '.join(arguments)) + Logger.error('"%s" is not a recognized argument.\n' + 'Please use one of these: %s.', + operation, ', '.join(arguments)) sys.exit(1) else: self.operation = operation @@ -202,8 +199,7 @@ class PbuilderDist: try: os.makedirs(result) except OSError: - print >> sys.stderr, ('Error: Cannot create results directory ' - '"%s"' % result) + Logger.error('Cannot create results directory "%s"', result) sys.exit(1) arguments = [ @@ -219,10 +215,7 @@ class PbuilderDist: elif self.builder == 'cowbuilder': arguments += ['--basepath', prefix + '-base.cow'] else: - print >> sys.stderr, 'Error: Unrecognized builder "%s".' % \ - self.builder - sys.exit(1) - + Logger.error('Unrecognized builder "%s".', self.builder) if self.logfile: arguments += ['--logfile', self.logfile] @@ -260,7 +253,7 @@ class PbuilderDist: and self.target_distro not in self._debian_distros): if not os.path.exists( '/usr/share/keyrings/ubuntu-archive-keyring.gpg'): - print >> sys.stderr, 'Error: ubuntu-keyring not installed' + Logger.error('ubuntu-keyring not installed') sys.exit(1) arguments += [ '--debootstrapopts', @@ -270,8 +263,7 @@ class PbuilderDist: and self.target_distro in self._debian_distros): if not os.path.exists( '/usr/share/keyrings/debian-archive-keyring.gpg'): - print >> sys.stderr, ('Error: debian-archive-keyring not ' - 'installed') + Logger.error('debian-archive-keyring not installed') sys.exit(1) arguments += [ '--debootstrapopts', @@ -344,12 +336,12 @@ def main(): if ('-' in script_name and parts[0] not in ('pbuilder', 'cowbuilder') or len(parts) > 3): - print >> sys.stderr, ('Error: "%s" is not a valid name for a ' - '"pbuilder-dist" executable.') % script_name + Logger.error('"%s" is not a valid name for a "pbuilder-dist" ' + 'executable.', script_name) sys.exit(1) if len(args) < 1: - print >> sys.stderr, 'Insufficient number of arguments.' + Logger.error('Insufficient number of arguments.') show_help(1) if args[0] in ('-h', '--help', 'help'): @@ -391,15 +383,14 @@ def main(): args.remove('--main-only') if len(args) < 1: - print >> sys.stderr, 'Insufficient number of arguments.' + Logger.error('Insufficient number of arguments.') show_help(1) # Parse the operation args = app.set_operation(args.pop(0)) + args if app.operation == 'build' and '.dsc' not in ' '.join(args): - print >> sys.stderr, ('Error: You have to specify a .dsc file ' - 'if you want to build.') + Logger.error('You have to specify a .dsc file if you want to build.') sys.exit(1) # Execute the pbuilder command @@ -412,5 +403,5 @@ if __name__ == '__main__': try: main() except KeyboardInterrupt: - print >> sys.stderr, 'Manually aborted.' + Logger.error('Manually aborted.') sys.exit(1)