#!/usr/bin/env python3 import sys sys.path.append("debian/lib/python") import os import os.path import re import shutil import subprocess import time from debian_linux.debian import Changelog, VersionLinux from debian_linux.patches import PatchSeries class Main(object): def __init__(self, input_files, override_version): self.log = sys.stdout.write self.input_files = input_files changelog = Changelog(version=VersionLinux)[0] source = changelog.source version = changelog.version if override_version: version = VersionLinux('%s-0' % override_version) self.version_dfsg = version.linux_dfsg if self.version_dfsg is None: self.version_dfsg = '0' self.log('Using source name %s, version %s, dfsg %s\n' % (source, version.upstream, self.version_dfsg)) self.orig = '%s-%s' % (source, version.upstream) self.orig_tar = '%s_%s.orig.tar.xz' % (source, version.upstream) self.tag = 'v' + version.linux_upstream_full def __call__(self): import tempfile self.dir = tempfile.mkdtemp(prefix='genorig', dir='debian') old_umask = os.umask(0o022) try: if os.path.isdir(self.input_files[0]): self.upstream_export(self.input_files[0]) else: self.upstream_extract(self.input_files[0]) if len(self.input_files) > 1: self.upstream_patch(self.input_files[1]) # debian_patch() will change file mtimes. Capture the # original release time so we can apply it to the final # tarball. Note this doesn't work in case we apply an # upstream patch, as that doesn't carry a release time. orig_date = time.strftime( "%a, %d %b %Y %H:%M:%S +0000", time.gmtime( os.stat(os.path.join(self.dir, self.orig, 'Makefile')) .st_mtime)) self.debian_patch() os.umask(old_umask) self.tar(orig_date) finally: os.umask(old_umask) shutil.rmtree(self.dir) def upstream_export(self, input_repo): self.log("Exporting %s from %s\n" % (self.tag, input_repo)) gpg_wrapper = os.path.join(os.getcwd(), "debian/bin/git-tag-gpg-wrapper") verify_proc = subprocess.Popen(['git', '-c', 'gpg.program=%s' % gpg_wrapper, 'tag', '-v', self.tag], cwd=input_repo) if verify_proc.wait(): raise RuntimeError("GPG tag verification failed") archive_proc = subprocess.Popen(['git', 'archive', '--format=tar', '--prefix=%s/' % self.orig, self.tag], cwd=input_repo, stdout=subprocess.PIPE) extract_proc = subprocess.Popen(['tar', '-xaf', '-'], cwd=self.dir, stdin=archive_proc.stdout) ret1 = archive_proc.wait() ret2 = extract_proc.wait() if ret1 or ret2: raise RuntimeError("Can't create archive") def upstream_extract(self, input_tar): self.log("Extracting tarball %s\n" % input_tar) match = re.match(r'(^|.*/)(?P