From 1521a20369668d1742a3f408e02fb9be845584d9 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 21 Aug 2011 20:23:58 +0100 Subject: Combine separate --basetgz, --arch, --upload-target into one --basetgz list. Get rid of now-useless subcommands at the same time. After this change, I can now just plonk a project.meta file in a project, and then run "unperish clean deb lintian" and be happy, happy, happy. --- unperish | 117 +++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 49 deletions(-) diff --git a/unperish b/unperish index 522e96e..fcd57be 100755 --- a/unperish +++ b/unperish @@ -41,11 +41,12 @@ class Unperish(cliapp.Application): self.settings.string(['build-area'], 'where should results go? (%default)', default='../build-area') - self.settings.string(['basetgz'], 'pbuilder basetgz (%default)', - default='/var/cache/pbuilder/base.tgz') - self.settings.string(['upload-target'], - 'generate debian/changelog entry for uploading ' - 'to given target') + self.settings.string_list(['basetgz'], + 'list of pbuilder basetgz tarballs to use, ' + 'optionally prefix with upload target and ' + 'architechture, separated by colons ' + '(%default)', + default=['/var/cache/pbuilder/base.tgz']) self.settings.string(['dsc'], 'Debian source package (for dget command)', metavar='URL') @@ -55,7 +56,6 @@ class Unperish(cliapp.Application): self.settings.string(['debian-source'], 'Debian source package name (typically detected ' 'from debian/control)') - self.settings.string(['arch'], 'architecture for Debian packages') self.settings.string(['web-directory'], 'put files to go on the web in DIR', metavar='DIR') @@ -84,22 +84,10 @@ class Unperish(cliapp.Application): for arg in args: self.run_subcommand(arg) - def run_subcommand(self, subcommand): - if subcommand not in self.already: + def run_subcommand(self, subcommand, force=False): + if force or subcommand not in self.already: self.already.add(subcommand) - try: - with open(self.join(self.dirname, 'debian', 'control')) as f: - self.debian_control = debian.deb822.Deb822(f) - except IOError: - pass - - try: - with open(self.join(self.dirname, 'debian', 'changelog')) as f: - self.debian_changelog = debian.changelog.Changelog(f) - except IOError: - pass - if subcommand in self.subcommands: method = self.subcommands[subcommand] if self.settings['verbose']: @@ -146,6 +134,16 @@ class Unperish(cliapp.Application): def upstream_tarball(self): return '%s-%s.tar.gz' % (self.upstream_name, self.upstream_version) + @property + def debian_control(self): + with open(self.join(self.dirname, 'debian', 'control')) as f: + return debian.deb822.Deb822(f) + + @property + def debian_changelog(self): + with open(self.join(self.dirname, 'debian', 'changelog')) as f: + return debian.changelog.Changelog(f) + @property def debian_source_package(self): if self.settings['debian-source']: @@ -177,16 +175,12 @@ class Unperish(cliapp.Application): @property def arch(self): - if self.settings['arch']: - return self.settings['arch'] - else: - return self.runcmd(['dpkg', '--print-architecture']).strip() + return self.runcmd(['dpkg', '--print-architecture']).strip() - @property - def changes(self): + def changes(self, arch): return '%s_%s_%s.changes' % (self.debian_source_package, self.debian_version, - self.arch) + arch) def already_exists(self, filename): '''Does a file already exist?''' @@ -223,12 +217,6 @@ class Unperish(cliapp.Application): if not self.already_exists(origtar): self.runcmd(['bzr', 'export', origtar]) - def cmd_dch(self, args): - '''Add a debian/changelog entry for new upload target.''' - self.run_subcommand('export') - if self.settings['upload-target']: - self.add_debian_changelog_entry() - def cmd_dsc(self, args): '''Create Debian source package (.dsc) in build area.''' self.run_subcommand('export') @@ -239,20 +227,28 @@ class Unperish(cliapp.Application): def cmd_deb(self, args): '''Build Debian binary packages (.deb) in build area.''' - self.run_subcommand('dsc') - if not self.already_exists(self.join(self.changes)): - argv = ['sudo', - 'pbuilder', - '--build', - '--basetgz', self.settings['basetgz'], - '--buildresult', self.settings['build-area'], - '--logfile', self.join('pbuilder.log')] - if self.include_source(): - argv.extend(['--debbuildopts', '-sa']) - if self.settings['binary-arch']: - argv.append('--binary-arch') - argv.append(self.join(self.dsc)) - self.runcmd(argv, cwd=self.settings['build-area']) + + self.run_subcommand('export') + for spec in self.settings['basetgz']: + target, arch, path = self.parse_basetgz(spec) + print 'deb:', target, arch, path + + if target: + self.add_debian_changelog_entry(target) + self.run_subcommand('dsc', force=True) + if not self.already_exists(self.join(self.changes(arch))): + argv = ['sudo', + 'pbuilder', + '--build', + '--basetgz', path, + '--buildresult', self.settings['build-area'], + '--logfile', self.join('pbuilder.log')] + if self.include_source(): + argv.extend(['--debbuildopts', '-sa']) + if self.settings['binary-arch']: + argv.append('--binary-arch') + argv.append(self.join(self.dsc)) + self.runcmd(argv, cwd=self.settings['build-area']) def include_source(self): '''Should the upload include full source?''' @@ -264,6 +260,29 @@ class Unperish(cliapp.Application): pat = r'-1$|[a-z]1$|^[^-]*$' return re.search(pat, self.debian_version) is not None + def parse_basetgz(self, spec): + parts = spec.split(':', 3) + n = len(parts) + + if n == 1 or '/' in parts[0]: + target = None + arch = self.arch + path = parts[0] + elif n == 2: + target = parts[0] + arch = self.arch + path = parts[1] + elif n == 3 and '/' in parts[1]: + target = parts[0] + arch = self.arch + path = ':'.join(parts[1:]) + else: + target = parts[0] + arch = parts[1] + path = parts[2] + + return target, arch, path + def cmd_lintian(self, args): '''Run lintian on .changes/.deb/.dsc files.''' @@ -329,12 +348,12 @@ class Unperish(cliapp.Application): else: os.remove(pathname) - def add_debian_changelog_entry(self): - target = self.settings['upload-target'] + def add_debian_changelog_entry(self, target): self.runcmd(['dch', '--force-distribution', '--local', target, '--distribution', target, + '--preserve', 'Build for %s.' % target], cwd=self.join(self.dirname)) -- cgit v1.2.1