# Copyright 2016 Lars Wirzenius # # This program is free software: you can redistribute it and/or 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 # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # =*= License: GPL-3+ =*= import glob import os import shutil import tempfile import icklib class PublishDebianPackages(icklib.BuildStep): def build(self): have_changes = self.run_state.changes_files have_targets = self.project.dput_targets have_unstable = self.project.dput_unstable need_to_run = have_changes and (have_targets or have_unstable) if not need_to_run: return self.run_state.progress['step'] = ( 'Publish built release packages to public APT repositories') self.run_state.logger.important( 'Publish built release packages to public APT repositories') with self.run_state.logger: tempdir = self._copy_packages() self._remove_dbgsym_packages_from_changes_files(tempdir) self._remove_buildinfo_from_changes_files(tempdir) self._debsign(tempdir) self._dput_targets(tempdir) self._dput_unstable(tempdir) shutil.rmtree(tempdir) def _copy_packages(self): tempdir = tempfile.mkdtemp() artifacts_dir = self.run_state.build_info.get_artifacts_directory() self.project.run_locally( ['rsync', '-a', artifacts_dir + '/.', tempdir + '/.'], 'rsync artifacts', '.') return tempdir def _remove_dbgsym_packages_from_changes_files(self, tempdir): for filename in self._changes_files(tempdir): with open(filename) as f: text = f.read() modified = ''.join( '{}\n'.format(line) for line in text.splitlines() if '-dbgsym' not in line) with open(filename, 'w') as f: f.write(modified) def _remove_buildinfo_from_changes_files(self, tempdir): for filename in self._changes_files(tempdir): with open(filename) as f: text = f.read() modified = ''.join( '{}\n'.format(line) for line in text.splitlines() if '.buildinfo' not in line) with open(filename, 'w') as f: f.write(modified) def _changes_files(self, tempdir): return glob.glob(os.path.join(tempdir, '*.changes')) def _debsign(self, tempdir): argv = ['debsign'] if self.project.package_signing_key is not None: argv += ['-k', self.project.package_signing_key] argv += self._changes_files(tempdir) self.project.run_locally(argv, 'debsign *.changes', tempdir) def _dput_targets(self, tempdir): files = self._changes_files(tempdir) self._dput_some_targets(tempdir, files, self.project.dput_targets) def _dput_unstable(self, tempdir): files = self._changes_files(tempdir) unstable = [f for f in files if self._is_source_for_unstable(f)] self._dput_some_targets(tempdir, unstable, self.project.dput_unstable) def _is_source_for_unstable(self, filename): with open(filename) as f: text = f.read() is_source = '\nArchitecture: source\n' in text is_for_unstable = '\nDistribution: unstable\n' in text return is_source and is_for_unstable def _dput_some_targets(self, tempdir, files, dput_targets): for dput_target in dput_targets: self.project.run_locally( ['dput', dput_target] + files, 'dput {} *.changes'.format(dput_target), tempdir)