From 781d077af8ba5daa2b23b874b85721c5fe976284 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Mon, 22 Nov 2010 13:25:55 +0200 Subject: [PATCH 01/13] Check for builder in sbin paths even if they aren't in PATH --- pbuilder-dist | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pbuilder-dist b/pbuilder-dist index 52fc179..665e297 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -77,11 +77,9 @@ class pbuilder_dist: self.builder = builder # Ensure that the used builder is installed - for file in os.environ['PATH'].split(':'): - if os.path.exists(os.path.join(file, builder)): - builder = '' - break - if builder: + 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 'Error: Could not find "%s".' % builder sys.exit(1) From 2f4abf3d7145f5154652e3e5c70eff44b0b9bf59 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Mon, 22 Nov 2010 13:33:19 +0200 Subject: [PATCH 02/13] Print errors to stderr --- pbuilder-dist | 61 ++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/pbuilder-dist b/pbuilder-dist index 665e297..ef38a61 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -28,7 +28,7 @@ # configurations. For example, a symlink called pbuilder-hardy will assume # that the target distribution is always meant to be Ubuntu Hardy. -import sys +from sys import exit, argv, stderr import os import ubuntutools.misc @@ -80,8 +80,8 @@ class pbuilder_dist: 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 'Error: Could not find "%s".' % builder - sys.exit(1) + print >> stderr, 'Error: Could not find "%s".' % builder + exit(1) ############################################################## @@ -117,21 +117,22 @@ class pbuilder_dist: """ if not distro.isalpha(): - print 'Error: «%s» is an invalid distribution codename.' % distro - sys.exit(1) + print >> stderr, ('Error: "%s" is an invalid distribution codename.' + % distro) + exit(1) if not os.path.isfile(os.path.join('/usr/share/debootstrap/scripts/', distro)): if os.path.isdir('/usr/share/debootstrap/scripts/'): # Debian experimental doesn't have a debootstrap file but # should work nevertheless. 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) if answer not in ('y', 'Y'): - sys.exit(0) + exit(0) else: - print 'Please install package "debootstrap".' - sys.exit(1) + print >> stderr, 'Please install package "debootstrap".' + exit(1) self.target_distro = distro @@ -152,12 +153,12 @@ class pbuilder_dist: self.operation = 'build' return [operation] else: - print 'Error: Could not find file «%s».' % operation - sys.exit(1) + print >> stderr, 'Error: Could not find file "%s".' % operation + exit(1) else: - print 'Error: «%s» is not a recognized argument.' % operation - print 'Please use one of those: ' + ', '.join(arguments) + '.' - sys.exit(1) + print >> stderr, 'Error: "%s" is not a recognized argument.' % operation + print >> stderr, 'Please use one of these: %s.' % ', '.join(arguments) + exit(1) else: self.operation = operation return [] @@ -191,8 +192,8 @@ class pbuilder_dist: elif self.builder == 'cowbuilder': base = '--basepath "%s-base.cow"' % prefix else: - print 'Error: Unrecognized builder "%s".' % self.builder - sys.exit(1) + print >> stderr, 'Error: Unrecognized builder "%s".' % self.builder + exit(1) arguments = [ '--%s' % self.operation, @@ -291,7 +292,7 @@ def help(exit_code = 0): print 'See man pbuilder-dist for more information.' - sys.exit(exit_code) + exit(exit_code) def main(): """ 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('-') # Copy arguments into another list for save manipulation - args = sys.argv[1:] + args = argv[1:] if '-' in script_name and (parts[0] != 'pbuilder' and \ parts[0] != 'cowbuilder') or len(parts) > 3: - print 'Error: «%s» is not a valid name for a «pbuilder-dist» executable.' % script_name - sys.exit(1) + print >> stderr, 'Error: "%s" is not a valid name for a "pbuilder-dist" executable.' % script_name + exit(1) if len(args) < 1: - print 'Insufficient number of arguments.' + print >> stderr, 'Insufficient number of arguments.' help(1) if args[0] in ('-h', '--help', 'help'): @@ -347,27 +348,27 @@ def main(): ("sparc64", "sparc")]: 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 - if 'mainonly' in sys.argv: + if 'mainonly' in argv: args.remove('mainonly') else: args.remove('--main-only') if len(args) < 1: - print 'Insufficient number of arguments.' + print >> stderr, 'Insufficient number of arguments.' help(1) # Parse the operation args = app.set_operation(args.pop(0)) + 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.' - sys.exit(1) + print >> stderr, 'Error: You have to specify a .dsc file if you want to build.' + exit(1) # Execute the pbuilder command if not '--debug-echo' in args: - sys.exit(os.system(app.get_command(args))) + exit(os.system(app.get_command(args))) else: print app.get_command((args)).replace( ' --debug-echo', '') @@ -377,5 +378,5 @@ if __name__ == '__main__': try: main() except KeyboardInterrupt: - print 'Manually aborted.' - sys.exit(1) + print >> stderr, 'Manually aborted.' + exit(1) From 7126a9e8948c80678ac936244b14d9a312b83293 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Mon, 22 Nov 2010 14:26:10 +0200 Subject: [PATCH 03/13] * pbuilder-dist: - Refactor to use subprocess.popen instead of os.system (LP: #398974) --- debian/changelog | 2 ++ pbuilder-dist | 86 ++++++++++++++++++++++-------------------------- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/debian/changelog b/debian/changelog index bc439a4..17c73cc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,8 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low - Add --sort-binary-packages and --keep-first (LP: #681119) * grab-merge, syncpackage: Export DEB_VENDOR=Ubuntu when unpacking source packages. 3.0 (quilt) has optional per-vendor patch series. + * pbuilder-dist: + - Refactor to use subprocess.popen instead of os.system (LP: #398974) [ Benjamin Drung ] * wrap-and-sort: Remove duplicate items from sorted lists. diff --git a/pbuilder-dist b/pbuilder-dist index ef38a61..5037264 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -2,7 +2,8 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2007-2010 Siegfried-A. Gevatter -# With some changes by Iain Lane +# With some changes by Iain Lane , +# Stefano Rivera # Based upon pbuilder-dist-simple by Jamin Collins and Jordan Mantha. # # ################################################################## @@ -28,8 +29,9 @@ # configurations. For example, a symlink called pbuilder-hardy will assume # that the target distribution is always meant to be Ubuntu Hardy. -from sys import exit, argv, stderr import os +import subprocess +from sys import exit, argv, stderr import ubuntutools.misc @@ -102,10 +104,6 @@ class pbuilder_dist: ############################################################## - def __getitem__(self, name): - - return getattr(self, name) - def set_target_distro(self, distro): """ pbuilder_dist.set_target_distro(distro) -> None @@ -175,7 +173,7 @@ class pbuilder_dist: self.chroot_string = self.target_distro self.build_architecture = self.system_architecture else: - self.chroot_string = '%(target_distro)s-%(build_architecture)s' % self + self.chroot_string = self.target_distro + '-' + self.build_architecture prefix = os.path.join(self.base, self.chroot_string) result = '%s_result/' % prefix @@ -198,73 +196,69 @@ class pbuilder_dist: arguments = [ '--%s' % self.operation, base, - '--distribution "%(target_distro)s"' % self, - '--buildresult "%s"' % result, - '--aptcache "/var/cache/apt/archives/"', + '--distribution', self.target_distro, + '--buildresult', result, + '--aptcache', '/var/cache/apt/archives/', '--override-config', - ] + ] if self.logfile: - arguments.append('--logfile %s' % self.logfile) + arguments += ['--logfile', self.logfile] if os.path.exists('/var/cache/archive/'): - arguments.append('--bindmounts "/var/cache/archive/"') + arguments += ['--bindmounts', '/var/cache/archive/'] - localrepo = '/var/cache/archive/%(target_distro)s' % self + localrepo = '/var/cache/archive/' + self.target_distro if os.path.exists(localrepo): - arguments.append('--othermirror ' +\ - '"deb file:///var/cache/archive/ %(target_distro)s/"' % self) + arguments += [ + '--othermirror ', + 'deb file:///var/cache/archive/ %s/' % self.target_distro, + ] if self.target_distro in debian_distros: - arguments.append('--mirror "ftp://ftp.debian.org/debian"') + arguments += ['--mirror', 'http://ftp.debian.org/debian'] # work around bug #599695 - arguments.append('--debootstrapopts --keyring=/usr/share/keyrings/debian-archive-keyring.gpg') + arguments += [ + '--debootstrapopts', + '--keyring=/usr/share/keyrings/debian-archive-keyring.gpg', + ] components = 'main' if self.extra_components: components += ' contrib non-free' else: - if self.build_architecture in ('amd64','i386'): - arguments.append('--mirror "http://archive.ubuntu.com/ubuntu/"') + if self.build_architecture in ('amd64', 'i386'): + arguments += ['--mirror', 'http://archive.ubuntu.com/ubuntu/'] elif self.build_architecture == 'powerpc' and self.target_distro == 'dapper': - arguments.append('--mirror "http://archive.ubuntu.com/ubuntu/"') + arguments += ['--mirror', 'http://archive.ubuntu.com/ubuntu/'] else: - arguments.append('--mirror "http://ports.ubuntu.com/ubuntu-ports/"') + arguments += ['--mirror', + 'http://ports.ubuntu.com/ubuntu-ports/'] components = 'main restricted' if self.extra_components: components += ' universe multiverse' - arguments.append('--components "%s"' % components) + arguments += ['--components', components] if self.build_architecture != self.system_architecture: - arguments.append('--debootstrapopts --arch="%(build_architecture)s"' % self) + arguments += ['--debootstrapopts', + '--arch=' + self.build_architecture] - apt_conf_dir = os.path.join(self.base, 'etc/%(target_distro)s/apt.conf' % self) + apt_conf_dir = os.path.join(self.base, 'etc/%s/apt.conf' % self.target_distro) if os.path.exists(apt_conf_dir): - arguments.append('--aptconfdir "%s"' % apt_conf_dir) + arguments += ['--aptconfdir', apt_conf_dir] # Append remaining arguments if remaining_arguments: arguments.extend(remaining_arguments) - def quote(argument): - """ quote(argument) -> string - - Try to guess any missing quotes around the arguments so that - their meaning doesn't get lost (see LP: #398989). - - """ - - if argument.startswith('--'): - if '=' in argument: - return '%s="%s"' % tuple(argument.split('=', 1)) - return argument - return '"%s"' % argument - # Export the distribution and architecture information to the # environment so that it is accessible to ~/.pbuilderrc (LP: #628933). - return '%s ARCH="%s" DIST="%s" /usr/sbin/%s %s' % (self.auth, - self.build_architecture, self.target_distro, self.builder, - ' '.join(map(quote, arguments))) + return [ + self.auth, + 'ARCH=' + self.build_architecture, + 'DIST=' + self.target_distro, + self.builder, + ] + arguments def ask(question): """ ask(question) -> string @@ -368,10 +362,10 @@ def main(): # Execute the pbuilder command if not '--debug-echo' in args: - exit(os.system(app.get_command(args))) + p = subprocess.Popen(app.get_command(args)) + exit(p.wait()) else: - print app.get_command((args)).replace( - ' --debug-echo', '') + print app.get_command([arg for arg in args if arg != '--debug-echo']) if __name__ == '__main__': From 04eb3ada8bf2496578242bc842aeaa95fc850865 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Mon, 22 Nov 2010 14:29:52 +0200 Subject: [PATCH 04/13] Catch OSErrors when creating directories (LP: #671067) --- debian/changelog | 1 + pbuilder-dist | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 17c73cc..e99c8d1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -15,6 +15,7 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low packages. 3.0 (quilt) has optional per-vendor patch series. * pbuilder-dist: - Refactor to use subprocess.popen instead of os.system (LP: #398974) + - Catch OSErrors when creating directories (LP: #671067) [ Benjamin Drung ] * wrap-and-sort: Remove duplicate items from sorted lists. diff --git a/pbuilder-dist b/pbuilder-dist index 5037264..348b6ea 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -89,8 +89,13 @@ class pbuilder_dist: self.base = os.path.expanduser(os.environ.get('PBUILDFOLDER', '~/pbuilder/')) - if not os.path.exists(self.base): - os.makedirs(self.base) + if not os.path.isdir(self.base): + try: + os.makedirs(self.base) + except os.OSError: + print >> stderr, ('Error: Cannot create base directory "%s"' + % self.base) + exit(1) if 'PBUILDAUTH' in os.environ: self.auth = os.environ['PBUILDAUTH'] @@ -182,8 +187,12 @@ class pbuilder_dist: self.logfile = os.path.normpath('%s/last_operation.log' % result) if not os.path.isdir(result): - # Create the results directory, if it doesn't exist. - os.makedirs(result) + try: + os.makedirs(result) + except os.OSError: + print >> stderr, ('Error: Cannot create results directory "%s"' + % result) + exit(1) if self.builder == 'pbuilder': base = '--basetgz "%s-base.tgz"' % prefix From b78b21f43e4db49bbd380cb4a3e5a19e96a0b2bb Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 23 Nov 2010 08:54:42 +0200 Subject: [PATCH 05/13] Whitespace -> PEP-8 --- pbuilder-dist | 684 +++++++++++++++++++++++++------------------------- 1 file changed, 348 insertions(+), 336 deletions(-) diff --git a/pbuilder-dist b/pbuilder-dist index 348b6ea..98c6091 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -12,12 +12,12 @@ # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # See file /usr/share/common-licenses/GPL for more details. # # ################################################################## @@ -35,351 +35,363 @@ from sys import exit, argv, stderr import ubuntutools.misc -debian_distros = ['etch', 'lenny', 'squeeze', 'sid', 'stable', \ - 'testing', 'unstable', 'experimental'] +debian_distros = ['etch', 'lenny', 'squeeze', 'sid', 'stable', 'testing', + 'unstable', 'experimental'] class pbuilder_dist: - - def __init__(self, builder): - - # Base directory where pbuilder will put all the files it creates. - self.base = None - - # Name of the operation which pbuilder should perform. - self.operation = None - - # Wheter additional components should be used or not. That is, - # 'universe' and 'multiverse' for Ubuntu chroots and 'contrib' - # and 'non-free' for Debian. - self.extra_components = True - - # File where the log of the last operation will be saved. - self.logfile = None - - # System architecture - self.system_architecture = None - - # Build architecture - self.build_architecture = None - - # System's distribution - self.system_distro = None - - # Target distribution - self.target_distro = None - - # This is an identificative string which will either take the form - # 'distribution' or 'distribution-architecture'. - self.chroot_string = None - - # Authentication method - self.auth = 'sudo' - - # Builder - self.builder = builder - - # Ensure that the used builder is installed - 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 >> stderr, 'Error: Could not find "%s".' % builder - exit(1) - - ############################################################## - - self.base = os.path.expanduser(os.environ.get('PBUILDFOLDER', '~/pbuilder/')) - if not os.path.isdir(self.base): - try: - os.makedirs(self.base) - except os.OSError: - print >> stderr, ('Error: Cannot create base directory "%s"' - % self.base) - exit(1) - - if 'PBUILDAUTH' in os.environ: - self.auth = os.environ['PBUILDAUTH'] - - self.system_architecture = ubuntutools.misc.host_architecture() - self.system_distro = ubuntutools.misc.system_distribution() - if not self.system_architecture or not self.system_distro: - exit(1) - - self.target_distro = self.system_distro - - ############################################################## - - def set_target_distro(self, distro): - """ pbuilder_dist.set_target_distro(distro) -> None - - Check if the given target distribution name is correct, if it - isn't know to the system ask the user for confirmation before - proceeding, and finally either save the value into the appropiate - variable or finalize pbuilder-dist's execution. - - """ - - if not distro.isalpha(): - print >> stderr, ('Error: "%s" is an invalid distribution codename.' - % distro) - exit(1) - - if not os.path.isfile(os.path.join('/usr/share/debootstrap/scripts/', distro)): - if os.path.isdir('/usr/share/debootstrap/scripts/'): - # Debian experimental doesn't have a debootstrap file but - # should work nevertheless. - if distro not in debian_distros: - answer = ask('Warning: Unknown distribution "%s". Do you ' \ - 'want to continue [y/N]? ' % distro) - if answer not in ('y', 'Y'): - exit(0) - else: - print >> stderr, 'Please install package "debootstrap".' - exit(1) - - self.target_distro = distro - - def set_operation(self, operation): - """ pbuilder_dist.set_operation -> None - - Check if the given string is a valid pbuilder operation and - depending on this either save it into the appropiate variable - or finalize pbuilder-dist's execution. - - """ - - arguments = ('create', 'update', 'build', 'clean', 'login', 'execute') - - if operation not in arguments: - if operation.endswith('.dsc'): - if os.path.isfile(operation): - self.operation = 'build' - return [operation] - else: - print >> stderr, 'Error: Could not find file "%s".' % operation - exit(1) - else: - print >> stderr, 'Error: "%s" is not a recognized argument.' % operation - print >> stderr, 'Please use one of these: %s.' % ', '.join(arguments) - exit(1) - else: - self.operation = operation - return [] - - def get_command(self, remaining_arguments = None): - """ pbuilder_dist.get_command -> string - - Generate the pbuilder command which matches the given configuration - and return it as a string. - - """ - - if not self.build_architecture: - self.chroot_string = self.target_distro - self.build_architecture = self.system_architecture - else: - self.chroot_string = self.target_distro + '-' + self.build_architecture - - prefix = os.path.join(self.base, self.chroot_string) - result = '%s_result/' % prefix - - if not self.logfile and self.operation != 'login': - self.logfile = os.path.normpath('%s/last_operation.log' % result) - - if not os.path.isdir(result): - try: - os.makedirs(result) - except os.OSError: - print >> stderr, ('Error: Cannot create results directory "%s"' - % result) - exit(1) - - if self.builder == 'pbuilder': - base = '--basetgz "%s-base.tgz"' % prefix - elif self.builder == 'cowbuilder': - base = '--basepath "%s-base.cow"' % prefix - else: - print >> stderr, 'Error: Unrecognized builder "%s".' % self.builder - exit(1) - - arguments = [ - '--%s' % self.operation, - base, - '--distribution', self.target_distro, - '--buildresult', result, - '--aptcache', '/var/cache/apt/archives/', - '--override-config', - ] + def __init__(self, builder): - if self.logfile: - arguments += ['--logfile', self.logfile] - - if os.path.exists('/var/cache/archive/'): - arguments += ['--bindmounts', '/var/cache/archive/'] + # Base directory where pbuilder will put all the files it creates. + self.base = None - localrepo = '/var/cache/archive/' + self.target_distro - if os.path.exists(localrepo): - arguments += [ - '--othermirror ', - 'deb file:///var/cache/archive/ %s/' % self.target_distro, - ] - - if self.target_distro in debian_distros: - arguments += ['--mirror', 'http://ftp.debian.org/debian'] - # work around bug #599695 - arguments += [ - '--debootstrapopts', - '--keyring=/usr/share/keyrings/debian-archive-keyring.gpg', - ] - components = 'main' - if self.extra_components: - components += ' contrib non-free' - else: - if self.build_architecture in ('amd64', 'i386'): - arguments += ['--mirror', 'http://archive.ubuntu.com/ubuntu/'] - elif self.build_architecture == 'powerpc' and self.target_distro == 'dapper': - arguments += ['--mirror', 'http://archive.ubuntu.com/ubuntu/'] - else: - arguments += ['--mirror', - 'http://ports.ubuntu.com/ubuntu-ports/'] - components = 'main restricted' - if self.extra_components: - components += ' universe multiverse' + # Name of the operation which pbuilder should perform. + self.operation = None - arguments += ['--components', components] - - if self.build_architecture != self.system_architecture: - arguments += ['--debootstrapopts', - '--arch=' + self.build_architecture] - - apt_conf_dir = os.path.join(self.base, 'etc/%s/apt.conf' % self.target_distro) - if os.path.exists(apt_conf_dir): - arguments += ['--aptconfdir', apt_conf_dir] - - # Append remaining arguments - if remaining_arguments: - arguments.extend(remaining_arguments) - - # Export the distribution and architecture information to the - # environment so that it is accessible to ~/.pbuilderrc (LP: #628933). - return [ - self.auth, - 'ARCH=' + self.build_architecture, - 'DIST=' + self.target_distro, - self.builder, - ] + arguments + # Wheter additional components should be used or not. That is, + # 'universe' and 'multiverse' for Ubuntu chroots and 'contrib' + # and 'non-free' for Debian. + self.extra_components = True + + # File where the log of the last operation will be saved. + self.logfile = None + + # System architecture + self.system_architecture = None + + # Build architecture + self.build_architecture = None + + # System's distribution + self.system_distro = None + + # Target distribution + self.target_distro = None + + # This is an identificative string which will either take the form + # 'distribution' or 'distribution-architecture'. + self.chroot_string = None + + # Authentication method + self.auth = 'sudo' + + # Builder + self.builder = builder + + # Ensure that the used builder is installed + 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 >> stderr, 'Error: Could not find "%s".' % builder + exit(1) + + ############################################################## + + self.base = os.path.expanduser(os.environ.get('PBUILDFOLDER', + '~/pbuilder/')) + + if not os.path.isdir(self.base): + try: + os.makedirs(self.base) + except os.OSError: + print >> stderr, ('Error: Cannot create base directory "%s"' + % self.base) + exit(1) + + if 'PBUILDAUTH' in os.environ: + self.auth = os.environ['PBUILDAUTH'] + + self.system_architecture = ubuntutools.misc.host_architecture() + self.system_distro = ubuntutools.misc.system_distribution() + if not self.system_architecture or not self.system_distro: + exit(1) + + self.target_distro = self.system_distro + + ############################################################## + + def set_target_distro(self, distro): + """ pbuilder_dist.set_target_distro(distro) -> None + + Check if the given target distribution name is correct, if it + isn't know to the system ask the user for confirmation before + proceeding, and finally either save the value into the appropiate + variable or finalize pbuilder-dist's execution. + + """ + + if not distro.isalpha(): + print >> stderr, ('Error: "%s" is an invalid distribution codename.' + % distro) + exit(1) + + if not os.path.isfile(os.path.join('/usr/share/debootstrap/scripts/', + distro)): + if os.path.isdir('/usr/share/debootstrap/scripts/'): + # Debian experimental doesn't have a debootstrap file but + # should work nevertheless. + if distro not in debian_distros: + answer = ask(('Warning: Unknown distribution "%s". Do you ' + 'want to continue [y/N]? ') % distro) + if answer not in ('y', 'Y'): + exit(0) + else: + print >> stderr, 'Please install package "debootstrap".' + exit(1) + + self.target_distro = distro + + def set_operation(self, operation): + """ pbuilder_dist.set_operation -> None + + Check if the given string is a valid pbuilder operation and + depending on this either save it into the appropiate variable + or finalize pbuilder-dist's execution. + + """ + + arguments = ('create', 'update', 'build', 'clean', 'login', 'execute') + + if operation not in arguments: + if operation.endswith('.dsc'): + if os.path.isfile(operation): + self.operation = 'build' + return [operation] + else: + print >> stderr, ('Error: Could not find file "%s".' + % operation) + exit(1) + else: + print >> stderr, ( + 'Error: "%s" is not a recognized argument.\n' + 'Please use one of these: %s.' + ) % (operation, ', '.join(arguments)) + exit(1) + else: + self.operation = operation + return [] + + def get_command(self, remaining_arguments = None): + """ pbuilder_dist.get_command -> string + + Generate the pbuilder command which matches the given configuration + and return it as a string. + + """ + + if not self.build_architecture: + self.chroot_string = self.target_distro + self.build_architecture = self.system_architecture + else: + self.chroot_string = (self.target_distro + '-' + + self.build_architecture) + + prefix = os.path.join(self.base, self.chroot_string) + result = '%s_result/' % prefix + + if not self.logfile and self.operation != 'login': + self.logfile = os.path.normpath('%s/last_operation.log' % result) + + if not os.path.isdir(result): + try: + os.makedirs(result) + except os.OSError: + print >> stderr, ('Error: Cannot create results directory "%s"' + % result) + exit(1) + + if self.builder == 'pbuilder': + base = '--basetgz "%s-base.tgz"' % prefix + elif self.builder == 'cowbuilder': + base = '--basepath "%s-base.cow"' % prefix + else: + print >> stderr, 'Error: Unrecognized builder "%s".' % self.builder + exit(1) + + arguments = [ + '--%s' % self.operation, + base, + '--distribution', self.target_distro, + '--buildresult', result, + '--aptcache', '/var/cache/apt/archives/', + '--override-config', + ] + + if self.logfile: + arguments += ['--logfile', self.logfile] + + if os.path.exists('/var/cache/archive/'): + arguments += ['--bindmounts', '/var/cache/archive/'] + + localrepo = '/var/cache/archive/' + self.target_distro + if os.path.exists(localrepo): + arguments += [ + '--othermirror ', + 'deb file:///var/cache/archive/ %s/' % self.target_distro, + ] + + if self.target_distro in debian_distros: + arguments += ['--mirror', 'http://ftp.debian.org/debian'] + # work around bug #599695 + arguments += [ + '--debootstrapopts', + '--keyring=/usr/share/keyrings/debian-archive-keyring.gpg', + ] + components = 'main' + if self.extra_components: + components += ' contrib non-free' + else: + if self.build_architecture in ('amd64', 'i386'): + arguments += ['--mirror', 'http://archive.ubuntu.com/ubuntu/'] + elif (self.build_architecture == 'powerpc' + and self.target_distro == 'dapper'): + arguments += ['--mirror', 'http://archive.ubuntu.com/ubuntu/'] + else: + arguments += ['--mirror', + 'http://ports.ubuntu.com/ubuntu-ports/'] + components = 'main restricted' + if self.extra_components: + components += ' universe multiverse' + + arguments += ['--components', components] + + if self.build_architecture != self.system_architecture: + arguments += ['--debootstrapopts', + '--arch=' + self.build_architecture] + + apt_conf_dir = os.path.join(self.base, + 'etc/%s/apt.conf' % self.target_distro) + if os.path.exists(apt_conf_dir): + arguments += ['--aptconfdir', apt_conf_dir] + + # Append remaining arguments + if remaining_arguments: + arguments.extend(remaining_arguments) + + # Export the distribution and architecture information to the + # environment so that it is accessible to ~/.pbuilderrc (LP: #628933). + return [ + self.auth, + 'ARCH=' + self.build_architecture, + 'DIST=' + self.target_distro, + self.builder, + ] + arguments def ask(question): - """ ask(question) -> string - - Ask the given question and return the answer. Also catch - KeyboardInterrupt (Ctrl+C) and EOFError (Ctrl+D) exceptions and - immediately return None if one of those is found. - - """ - - try: - answer = raw_input(question) - except (KeyboardInterrupt, EOFError): - print - answer = None - - return answer + """ ask(question) -> string + + Ask the given question and return the answer. Also catch + KeyboardInterrupt (Ctrl+C) and EOFError (Ctrl+D) exceptions and + immediately return None if one of those is found. + + """ + + try: + answer = raw_input(question) + except (KeyboardInterrupt, EOFError): + print + answer = None + + return answer def help(exit_code = 0): - """ help() -> None - - Print a help message for pbuilder-dist, and exit with the given code. - - """ - - print 'See man pbuilder-dist for more information.' - - exit(exit_code) + """ help() -> None + + Print a help message for pbuilder-dist, and exit with the given code. + + """ + + print 'See man pbuilder-dist for more information.' + + exit(exit_code) def main(): - """ main() -> None - - This is pbuilder-dist's main function. It creates a pbuilder_dist - object, modifies all necessary settings taking data from the - executable's name and command line options and finally either ends - the script and runs pbuilder itself or exists with an error message. - - """ - - script_name = os.path.basename(argv[0]) - parts = script_name.split('-') - - # Copy arguments into another list for save manipulation - args = argv[1:] - - if '-' in script_name and (parts[0] != 'pbuilder' and \ - parts[0] != 'cowbuilder') or len(parts) > 3: - print >> stderr, 'Error: "%s" is not a valid name for a "pbuilder-dist" executable.' % script_name - exit(1) - - if len(args) < 1: - print >> stderr, 'Insufficient number of arguments.' - help(1) - - if args[0] in ('-h', '--help', 'help'): - help(0) - - app = pbuilder_dist(parts[0]) - - if len(parts) > 1 and parts[1] != 'dist' and '.' not in parts[1]: - app.set_target_distro(parts[1]) - else: - app.set_target_distro(args.pop(0)) - - if len(parts) > 2: - requested_arch = parts[2] - elif len(args) > 0 and args[0] in ("alpha", "amd64", "arm", "armeb", - "armel", "i386", "lpia", "m68k", "mips", "mipsel", "powerpc", "ppc64", - "sh4", "sh4eb", "sparc", "sparc64"): - requested_arch = args.pop(0) - else: - requested_arch = None - - if requested_arch: - app.build_architecture = requested_arch - # For some foreign architectures we need to use qemu - if requested_arch != app.system_architecture and (app.system_architecture, - requested_arch) not in [("amd64", "i386"), ("amd64", "lpia"), - ("arm", "armel"), ("armel", "arm"), ("i386", "lpia"), ("lpia", "i386"), - ("powerpc", "ppc64"), ("ppc64", "powerpc"), ("sparc", "sparc64"), - ("sparc64", "sparc")]: - args.append('--debootstrap qemu-debootstrap') - - if 'mainonly' in argv or '--main-only' in argv: - app.extra_components = False - if 'mainonly' in argv: - args.remove('mainonly') - else: - args.remove('--main-only') - - if len(args) < 1: - print >> stderr, 'Insufficient number of arguments.' - help(1) - - # Parse the operation - args = app.set_operation(args.pop(0)) + args - - if app.operation == 'build' and not '.dsc' in ' '.join(args): - print >> stderr, 'Error: You have to specify a .dsc file if you want to build.' - exit(1) - - # Execute the pbuilder command - if not '--debug-echo' in args: - p = subprocess.Popen(app.get_command(args)) - exit(p.wait()) - else: - print app.get_command([arg for arg in args if arg != '--debug-echo']) + """ main() -> None + + This is pbuilder-dist's main function. It creates a pbuilder_dist + object, modifies all necessary settings taking data from the + executable's name and command line options and finally either ends + the script and runs pbuilder itself or exists with an error message. + + """ + + script_name = os.path.basename(argv[0]) + parts = script_name.split('-') + + # Copy arguments into another list for save manipulation + args = argv[1:] + + if ('-' in script_name and parts[0] not in ('pbuilder', 'cowbuilder') + or len(parts) > 3): + print >> stderr, ('Error: "%s" is not a valid name for a ' + '"pbuilder-dist" executable.') % script_name + exit(1) + + if len(args) < 1: + print >> stderr, 'Insufficient number of arguments.' + help(1) + + if args[0] in ('-h', '--help', 'help'): + help(0) + + app = pbuilder_dist(parts[0]) + + if len(parts) > 1 and parts[1] != 'dist' and '.' not in parts[1]: + app.set_target_distro(parts[1]) + else: + app.set_target_distro(args.pop(0)) + + if len(parts) > 2: + requested_arch = parts[2] + elif len(args) > 0 and args[0] in ( + 'alpha', 'amd64', 'arm', 'armeb', 'armel', 'i386', 'lpia', 'm68k', + 'mips', 'mipsel', 'powerpc', 'ppc64', 'sh4', 'sh4eb', 'sparc', + 'sparc64'): + requested_arch = args.pop(0) + else: + requested_arch = None + + if requested_arch: + app.build_architecture = requested_arch + # For some foreign architectures we need to use qemu + if (requested_arch != app.system_architecture + and (app.system_architecture, requested_arch) not in [ + ('amd64', 'i386'), ('amd64', 'lpia'), ('arm', 'armel'), + ('armel', 'arm'), ('i386', 'lpia'), ('lpia', 'i386'), + ('powerpc', 'ppc64'), ('ppc64', 'powerpc'), + ('sparc', 'sparc64'), ('sparc64', 'sparc')]): + args.append('--debootstrap qemu-debootstrap') + + if 'mainonly' in argv or '--main-only' in argv: + app.extra_components = False + if 'mainonly' in argv: + args.remove('mainonly') + else: + args.remove('--main-only') + + if len(args) < 1: + print >> stderr, 'Insufficient number of arguments.' + help(1) + + # Parse the operation + args = app.set_operation(args.pop(0)) + args + + if app.operation == 'build' and not '.dsc' in ' '.join(args): + print >> stderr, ('Error: You have to specify a .dsc file if you want ' + 'to build.') + exit(1) + + # Execute the pbuilder command + if not '--debug-echo' in args: + p = subprocess.Popen(app.get_command(args))) + exit(p.wait()) + else: + print app.get_command([arg for arg in args if arg != '--debug-echo']) if __name__ == '__main__': - - try: - main() - except KeyboardInterrupt: - print >> stderr, 'Manually aborted.' - exit(1) + + try: + main() + except KeyboardInterrupt: + print >> stderr, 'Manually aborted.' + exit(1) From afb27f1e1be73661af9fae356ad038c40a5db090 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 23 Nov 2010 08:56:23 +0200 Subject: [PATCH 06/13] Minor tweaks --- pbuilder-dist | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pbuilder-dist b/pbuilder-dist index 98c6091..00e5d49 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -376,20 +376,18 @@ def main(): # Parse the operation args = app.set_operation(args.pop(0)) + args - if app.operation == 'build' and not '.dsc' in ' '.join(args): + if app.operation == 'build' and '.dsc' not in ' '.join(args): print >> stderr, ('Error: You have to specify a .dsc file if you want ' 'to build.') exit(1) # Execute the pbuilder command if not '--debug-echo' in args: - p = subprocess.Popen(app.get_command(args))) - exit(p.wait()) + exit(subprocess.call(app.get_command(args))) else: print app.get_command([arg for arg in args if arg != '--debug-echo']) if __name__ == '__main__': - try: main() except KeyboardInterrupt: From 43781fb79ac7643a96c49cb3bdd259a078c9e718 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 23 Nov 2010 09:00:16 +0200 Subject: [PATCH 07/13] Compress Vertical Whitespace --- pbuilder-dist | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/pbuilder-dist b/pbuilder-dist index 00e5d49..b9df1a2 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -18,7 +18,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# See file /usr/share/common-licenses/GPL for more details. +# See file /usr/share/common-licenses/GPL-2 for more details. # # ################################################################## # @@ -39,9 +39,7 @@ debian_distros = ['etch', 'lenny', 'squeeze', 'sid', 'stable', 'testing', 'unstable', 'experimental'] class pbuilder_dist: - def __init__(self, builder): - # Base directory where pbuilder will put all the files it creates. self.base = None @@ -108,8 +106,6 @@ class pbuilder_dist: self.target_distro = self.system_distro - ############################################################## - def set_target_distro(self, distro): """ pbuilder_dist.set_target_distro(distro) -> None @@ -117,9 +113,7 @@ class pbuilder_dist: isn't know to the system ask the user for confirmation before proceeding, and finally either save the value into the appropiate variable or finalize pbuilder-dist's execution. - """ - if not distro.isalpha(): print >> stderr, ('Error: "%s" is an invalid distribution codename.' % distro) @@ -147,9 +141,7 @@ class pbuilder_dist: Check if the given string is a valid pbuilder operation and depending on this either save it into the appropiate variable or finalize pbuilder-dist's execution. - """ - arguments = ('create', 'update', 'build', 'clean', 'login', 'execute') if operation not in arguments: @@ -176,9 +168,7 @@ class pbuilder_dist: Generate the pbuilder command which matches the given configuration and return it as a string. - """ - if not self.build_architecture: self.chroot_string = self.target_distro self.build_architecture = self.system_architecture @@ -277,15 +267,14 @@ class pbuilder_dist: self.builder, ] + arguments + def ask(question): """ ask(question) -> string Ask the given question and return the answer. Also catch KeyboardInterrupt (Ctrl+C) and EOFError (Ctrl+D) exceptions and immediately return None if one of those is found. - """ - try: answer = raw_input(question) except (KeyboardInterrupt, EOFError): @@ -298,9 +287,7 @@ def help(exit_code = 0): """ help() -> None Print a help message for pbuilder-dist, and exit with the given code. - """ - print 'See man pbuilder-dist for more information.' exit(exit_code) @@ -312,9 +299,7 @@ def main(): object, modifies all necessary settings taking data from the executable's name and command line options and finally either ends the script and runs pbuilder itself or exists with an error message. - """ - script_name = os.path.basename(argv[0]) parts = script_name.split('-') From b2a400fe501d803d5fe03b24a8569f8edf1e26e4 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 2 Dec 2010 00:56:56 +0200 Subject: [PATCH 08/13] Pass --basetgz foo as separate arguments --- pbuilder-dist | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pbuilder-dist b/pbuilder-dist index b9df1a2..2ca9446 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -190,23 +190,23 @@ class pbuilder_dist: % result) exit(1) - if self.builder == 'pbuilder': - base = '--basetgz "%s-base.tgz"' % prefix - elif self.builder == 'cowbuilder': - base = '--basepath "%s-base.cow"' % prefix - else: - print >> stderr, 'Error: Unrecognized builder "%s".' % self.builder - exit(1) - arguments = [ '--%s' % self.operation, - base, '--distribution', self.target_distro, '--buildresult', result, '--aptcache', '/var/cache/apt/archives/', '--override-config', ] + if self.builder == 'pbuilder': + arguments += ['--basetgz', prefix + '-base.tgz'] + elif self.builder == 'cowbuilder': + arguments += ['--basepath', prefix + '-base.cow'] + else: + print >> stderr, 'Error: Unrecognized builder "%s".' % self.builder + exit(1) + + if self.logfile: arguments += ['--logfile', self.logfile] From 27365f9dd41dec70d3a76bf590720afe3d01780e Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 2 Dec 2010 09:30:21 +0200 Subject: [PATCH 09/13] Set HOME so pbuilder reads .pbuilderrc --- debian/changelog | 3 ++- pbuilder-dist | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index e99c8d1..e1bbac5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,6 +16,7 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low * pbuilder-dist: - Refactor to use subprocess.popen instead of os.system (LP: #398974) - Catch OSErrors when creating directories (LP: #671067) + - Set HOME so pbuilder reads .pbuilderrc [ Benjamin Drung ] * wrap-and-sort: Remove duplicate items from sorted lists. @@ -30,7 +31,7 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low * submittodebian: Encourage sending multiple independent pieces of the Ubuntu patch in separate bug reports. - -- Daniel Holbach Tue, 30 Nov 2010 11:55:24 +0100 + -- Stefano Rivera Thu, 02 Dec 2010 09:29:56 +0200 ubuntu-dev-tools (0.106) experimental; urgency=low diff --git a/pbuilder-dist b/pbuilder-dist index 2ca9446..eba60dc 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -262,6 +262,7 @@ class pbuilder_dist: # environment so that it is accessible to ~/.pbuilderrc (LP: #628933). return [ self.auth, + 'HOME=' + os.path.expanduser('~'), 'ARCH=' + self.build_architecture, 'DIST=' + self.target_distro, self.builder, From 516b264a8f2d206004769dd44bfecec326e3e127 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 2 Dec 2010 09:33:54 +0200 Subject: [PATCH 10/13] Strip trailing whitespace --- ubuntutools/misc.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/ubuntutools/misc.py b/ubuntutools/misc.py index 1480483..c59a10d 100644 --- a/ubuntutools/misc.py +++ b/ubuntutools/misc.py @@ -10,7 +10,7 @@ # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 3 # of the License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -28,11 +28,10 @@ from ubuntutools.lp.udtexceptions import PocketDoesNotExistError def system_distribution(): """ system_distro() -> string - + Detect the system's distribution and return it as a string. If the name of the distribution can't be determined, print an error message and return None. - """ # We try to avoid calling the "lsb_release" as looking up the value # directly is faster. However, Debian doesn't have /etc/lsb-release @@ -52,45 +51,43 @@ def system_distribution(): def host_architecture(): """ host_architecture -> string - + Detect the host's architecture and return it as a string. If the architecture can't be determined, print an error message and return None. - """ - + arch = Popen(['dpkg', '--print-architecture'], stdout=PIPE, \ stderr=PIPE).communicate()[0].split() - + if not arch or 'not found' in arch[0]: print 'Error: Not running on a Debian based system; could not ' \ 'detect its architecture.' return None - + return arch[0] def readlist(filename, uniq=True): """ readlist(filename, uniq) -> list - + Read a list of words from the indicated file. If 'uniq' is True, filter out duplicated words. - """ - + if not os.path.isfile(filename): print 'File "%s" does not exist.' % filename return False - + content = open(filename).read().replace('\n', ' ').replace(',', ' ') - + if not content.strip(): print 'File "%s" is empty.' % filename return False - + items = [item for item in content.split() if item] - + if uniq: items = list(set(items)) - + return items def splitReleasePocket(release): From f347770b46f3859b1b9d607222eea0cfc7be9caa Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 2 Dec 2010 09:34:09 +0200 Subject: [PATCH 11/13] Use dpkg-vendor in ubuntutools.misc.system_distribution(), cache result. --- debian/changelog | 1 + ubuntutools/misc.py | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/debian/changelog b/debian/changelog index e1bbac5..d7d7470 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,7 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low - Refactor to use subprocess.popen instead of os.system (LP: #398974) - Catch OSErrors when creating directories (LP: #671067) - Set HOME so pbuilder reads .pbuilderrc + * Use dpkg-vendor in ubuntutools.misc.system_distribution(), cache result. [ Benjamin Drung ] * wrap-and-sort: Remove duplicate items from sorted lists. diff --git a/ubuntutools/misc.py b/ubuntutools/misc.py index c59a10d..d61c85e 100644 --- a/ubuntutools/misc.py +++ b/ubuntutools/misc.py @@ -26,6 +26,7 @@ from subprocess import Popen, PIPE from ubuntutools.lp.udtexceptions import PocketDoesNotExistError +_system_distribution = None def system_distribution(): """ system_distro() -> string @@ -33,21 +34,22 @@ def system_distribution(): name of the distribution can't be determined, print an error message and return None. """ - # We try to avoid calling the "lsb_release" as looking up the value - # directly is faster. However, Debian doesn't have /etc/lsb-release - # so we need to fallback to the former there. - if os.path.isfile('/etc/lsb-release'): - for line in open('/etc/lsb-release'): - line = line.strip() - if line.startswith('DISTRIB_CODENAME'): - return line[17:] - else: - import commands - output = commands.getoutput('lsb_release -cs') - if output: - return output - print 'Error: Could not determine what distribution you are running.' - return None + global _system_distribution + if _system_distribution is None: + try: + if os.path.isfile('/usr/bin/dpkg-vendor'): + p = Popen(('dpkg-vendor', '--query', 'vendor'), stdout=PIPE) + else: + p = Popen(('lsb_release', '-cs'), stdout=PIPE) + output = p.communicate()[0] + except OSError: + print 'Error: Could not determine what distribution you are running.' + return None + if p.returncode != 0: + print 'Error determininng system distribution' + return None + _system_distribution = output.strip() + return _system_distribution def host_architecture(): """ host_architecture -> string From 67734216abb3c0499344d3dcef8feb7082b7ef1b Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 2 Dec 2010 09:37:44 +0200 Subject: [PATCH 12/13] Add bidirectional workarounds for LP: #599695 (pbuilder uses the host apt keyring). Complain if the target's keyring isn't installed. --- debian/changelog | 4 +++- pbuilder-dist | 27 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/debian/changelog b/debian/changelog index d7d7470..15b700b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,8 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low - Refactor to use subprocess.popen instead of os.system (LP: #398974) - Catch OSErrors when creating directories (LP: #671067) - Set HOME so pbuilder reads .pbuilderrc + - Add bidirectional workarounds for LP: #599695 (pbuilder uses the host + apt keyring). Complain if the target's keyring isn't installed. * Use dpkg-vendor in ubuntutools.misc.system_distribution(), cache result. [ Benjamin Drung ] @@ -32,7 +34,7 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low * submittodebian: Encourage sending multiple independent pieces of the Ubuntu patch in separate bug reports. - -- Stefano Rivera Thu, 02 Dec 2010 09:29:56 +0200 + -- Stefano Rivera Thu, 02 Dec 2010 09:36:48 +0200 ubuntu-dev-tools (0.106) experimental; urgency=low diff --git a/pbuilder-dist b/pbuilder-dist index eba60dc..37f4291 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -222,11 +222,6 @@ class pbuilder_dist: if self.target_distro in debian_distros: arguments += ['--mirror', 'http://ftp.debian.org/debian'] - # work around bug #599695 - arguments += [ - '--debootstrapopts', - '--keyring=/usr/share/keyrings/debian-archive-keyring.gpg', - ] components = 'main' if self.extra_components: components += ' contrib non-free' @@ -243,6 +238,28 @@ class pbuilder_dist: if self.extra_components: components += ' universe multiverse' + # Work around LP:#599695 + if (ubuntutools.misc.system_distribution() == 'Debian' + and self.target_distro not in debian_distros): + if not os.path.exists( + '/usr/share/keyrings/ubuntu-archive-keyring.gpg'): + print >> stderr, 'Error: ubuntu-keyring not installed' + exit(1) + arguments += [ + '--debootstrapopts', + '--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg', + ] + elif (ubuntutools.misc.system_distribution() == 'Ubuntu' + and self.target_distro in debian_distros): + if not os.path.exists( + '/usr/share/keyrings/debian-archive-keyring.gpg'): + print >> stderr, 'Error: debian-archive-keyring not installed' + exit(1) + arguments += [ + '--debootstrapopts', + '--keyring=/usr/share/keyrings/debian-archive-keyring.gpg', + ] + arguments += ['--components', components] if self.build_architecture != self.system_architecture: From cbbd22fa5b9e3997b952b7edcea4ff0e3e473cff Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 2 Dec 2010 10:25:31 +0200 Subject: [PATCH 13/13] Pass --debootstrap qemu-debootstrap as separate arguments --- pbuilder-dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pbuilder-dist b/pbuilder-dist index 37f4291..f5aba05 100755 --- a/pbuilder-dist +++ b/pbuilder-dist @@ -363,7 +363,7 @@ def main(): ('armel', 'arm'), ('i386', 'lpia'), ('lpia', 'i386'), ('powerpc', 'ppc64'), ('ppc64', 'powerpc'), ('sparc', 'sparc64'), ('sparc64', 'sparc')]): - args.append('--debootstrap qemu-debootstrap') + args += ['--debootstrap', 'qemu-debootstrap'] if 'mainonly' in argv or '--main-only' in argv: app.extra_components = False