def link_upstream_tarball(releaseType): #Find out the tarball link name upstream_name = os.path.basename( os.getcwd() ) #paragraphs = deb822.Packages.iter_paragraphs(open('./debian/copyright', 'r')); #upstream_name = next(paragraphs)['Upstream-Name'] changelog = Changelog() changelog.parse_changelog(open('./debian/changelog', 'r')) src_package_name = changelog.get_package() upstream_version = changelog.get_version().upstream_version #Handle packages with updated tarballs #e.g. 5.0.0a version instead of 5.0.0 last_char = upstream_version[-1] if last_char.isalpha(): real_upstream_version = upstream_version.rstrip(last_char) else: real_upstream_version = upstream_version link_name = '../' + src_package_name + '_' + upstream_version + '.orig.tar.xz' #Find out the tarball link target path cwd = os.path.dirname(os.path.realpath(__file__)) config_tarball_loc = json.load(open(cwd + "/../conf/tarball-locations.json")) config_versions = json.load(open(cwd + "/../conf/versions.json")) link_target = os.path.expanduser(config_tarball_loc[releaseType]) link_target += '/' + config_versions[releaseType] + '/' link_target += upstream_name + '-' + real_upstream_version + ".tar.xz" #Create the link try: os.symlink(link_target,link_name) except: pass
def __init__(self, buildable, *, binary_version_suffix='', link_builds=(), orig_dirs=('..', ), output_dir=None, output_parent, vendor): self.buildable = buildable self._product_prefix = None self._source_version = None self.arch_wildcards = set() self.archs = [] self.autopkgtest_failures = [] self.binary_packages = [] self.binary_version_suffix = binary_version_suffix self.changes_produced = {} self.dirname = None self.dsc = None self.dsc_name = None self.indep = False self.indep_together_with = None self.link_builds = link_builds self.logs = {} self.merged_changes = OrderedDict() self.nominal_suite = None self.orig_dirs = orig_dirs self.output_dir = output_dir self.piuparts_failures = [] self.source_from_archive = False self.source_package = None self.source_together_with = None self.sourceful_changes_name = None self.suite = None self.vendor = vendor if os.path.exists(self.buildable): if os.path.isdir(self.buildable): changelog = os.path.join(self.buildable, 'debian', 'changelog') changelog = Changelog(open(changelog)) self.source_package = changelog.get_package() self.nominal_suite = changelog.distributions self._source_version = Version(changelog.version) control = os.path.join(self.buildable, 'debian', 'control') if len(changelog.distributions.split()) != 1: raise ArgumentError( 'Cannot build for multiple distributions at once') for paragraph in Deb822.iter_paragraphs(open(control)): self.arch_wildcards |= set( paragraph.get('architecture', '').split()) binary = paragraph.get('package') if binary is not None: self.binary_packages.append(binary) elif self.buildable.endswith('.changes'): self.dirname = os.path.dirname(self.buildable) or os.curdir self.sourceful_changes_name = self.buildable sourceful_changes = Changes(open(self.buildable)) if 'source' not in sourceful_changes['architecture'].split(): raise ArgumentError( 'Changes file {!r} must be sourceful'.format( self.buildable)) self.nominal_suite = sourceful_changes['distribution'] for f in sourceful_changes['files']: if f['name'].endswith('.dsc'): if self.dsc_name is not None: raise ArgumentError( 'Changes file {!r} contained more than one ' '.dsc file'.format(self.buildable)) self.dsc_name = os.path.join(self.dirname, f['name']) if self.dsc_name is None: raise ArgumentError( 'Changes file {!r} did not contain a .dsc file'.format( self.buildable)) self.dsc = Dsc(open(self.dsc_name)) elif self.buildable.endswith('.dsc'): self.dirname = os.path.dirname(self.buildable) or os.curdir self.dsc_name = self.buildable self.dsc = Dsc(open(self.dsc_name)) else: raise ArgumentError( 'buildable must be .changes, .dsc or directory, not ' '{!r}'.format(self.buildable)) else: self.source_from_archive = True if '_' in self.buildable: source, version = self.buildable.split('_', 1) else: source = self.buildable version = None self.source_package = source if version is not None: self._source_version = Version(version) if self.dsc is not None: self.source_package = self.dsc['source'] self._source_version = Version(self.dsc['version']) self.arch_wildcards = set(self.dsc['architecture'].split()) self.binary_packages = [ p.strip() for p in self.dsc['binary'].split(',') ] if self._source_version is not None: self._binary_version = Version( str(self._source_version) + self.binary_version_suffix) timestamp = time.strftime('%Y%m%dt%H%M%S', time.gmtime()) if self.output_dir is None: if self._binary_version is None: dirname = '{}_{}'.format(self.source_package, timestamp) else: dirname = '{}_{}_{}'.format(self.source_package, self._binary_version, timestamp) self.output_dir = os.path.join(output_parent, dirname) # For convenience, create a symbolic link for the latest build of # each source package: hello_latest -> hello_2.10-1_20170319t102623 unversioned_symlink = os.path.join(output_parent, self.source_package + '_latest') with suppress(FileNotFoundError): os.unlink(unversioned_symlink) os.symlink(dirname, unversioned_symlink) # If we know the version, also create a symbolic link for the # latest build of each source/version pair: # hello_2.10-1 -> hello_2.10-1_20170319t102623 if self._binary_version is not None: versioned_symlink = os.path.join( output_parent, '{}_{}'.format(self.source_package, self._binary_version)) with suppress(FileNotFoundError): os.unlink(versioned_symlink) os.symlink(dirname, versioned_symlink) # It's OK if the output directory exists but is empty. with suppress(FileNotFoundError): os.rmdir(self.output_dir) # Otherwise, if someone already created this, we'll just crash out. os.mkdir(self.output_dir) if self.dsc is not None: abs_file = os.path.abspath(self.dsc_name) abs_dir, base = os.path.split(abs_file) os.symlink(abs_file, os.path.join(self.output_dir, base)) for l in self.link_builds: symlink = os.path.join(l, base) with suppress(FileNotFoundError): os.unlink(symlink) os.symlink(abs_file, symlink) for f in self.dsc['files']: abs_file = os.path.join(abs_dir, f['name']) os.symlink(abs_file, os.path.join(self.output_dir, f['name'])) for l in self.link_builds: symlink = os.path.join(l, f['name']) with suppress(FileNotFoundError): os.unlink(symlink) os.symlink(abs_file, symlink)
def __init__(self, buildable, *, vendor): self.buildable = buildable self._product_prefix = None self.arch_wildcards = set() self.archs = [] self.binary_packages = [] self.changes_produced = {} self.dirname = None self.dsc = None self.dsc_name = None self.indep = False self.logs = {} self.merged_changes = OrderedDict() self.nominal_suite = None self.source_from_archive = False self.source_package = None self.sourceful_changes_name = None self.suite = None self.together_with = None self.vendor = vendor self._version = None if os.path.exists(self.buildable): if os.path.isdir(self.buildable): changelog = os.path.join(self.buildable, 'debian', 'changelog') changelog = Changelog(open(changelog)) self.source_package = changelog.get_package() self.nominal_suite = changelog.distributions self._version = Version(changelog.version) control = os.path.join(self.buildable, 'debian', 'control') if len(changelog.distributions.split()) != 1: raise ArgumentError('Cannot build for multiple ' 'distributions at once') for paragraph in Deb822.iter_paragraphs(open(control)): self.arch_wildcards |= set( paragraph.get('architecture', '').split()) binary = paragraph.get('package') if binary is not None: self.binary_packages.append(binary) elif self.buildable.endswith('.changes'): self.dirname = os.path.dirname(self.buildable) self.sourceful_changes_name = self.buildable sourceful_changes = Changes(open(self.buildable)) if 'source' not in sourceful_changes['architecture']: raise ArgumentError('Changes file {!r} must be ' 'sourceful'.format(self.buildable)) self.nominal_suite = sourceful_changes['distribution'] for f in sourceful_changes['files']: if f['name'].endswith('.dsc'): if self.dsc_name is not None: raise ArgumentError('Changes file {!r} contained ' 'more than one .dsc ' 'file'.format(self.buildable)) self.dsc_name = os.path.join(self.dirname, f['name']) if self.dsc_name is None: raise ArgumentError('Changes file {!r} did not contain a ' '.dsc file'.format(self.buildable)) self.dsc = Dsc(open(self.dsc_name)) elif self.buildable.endswith('.dsc'): self.dirname = os.path.dirname(self.buildable) self.dsc_name = self.buildable self.dsc = Dsc(open(self.dsc_name)) else: raise ArgumentError('buildable must be .changes, .dsc or ' 'directory, not {!r}'.format( self.buildable)) else: self.source_from_archive = True if '_' in self.buildable: source, version = self.buildable.split('_', 1) else: source = self.buildable version = None self.source_package = source if version is not None: self._version = Version(version) if self.dsc is not None: self.source_package = self.dsc['source'] self._version = Version(self.dsc['version']) self.arch_wildcards = set(self.dsc['architecture'].split()) self.binary_packages = [ p.strip() for p in self.dsc['binary'].split(',') ]
# We only want the version and then replace that with +ubports n_version = n_version + "+ubports" # git-dch cannot handle "-" in changelog files, so make sure there is none # is there is, destroy them! n_version = n_version.replace("-", "") dist = changelog.distributions if args.dist: dist = args.dist date_now = datetime.now(tzlocal()).strftime("%a, %d %b %Y %X %z") changelog.new_block( package=changelog.get_package(), version=Version(n_version), distributions=dist, urgency='medium', author='UBports auto importer <*****@*****.**>', date=date_now, ) changelog.add_change('') changelog.add_change(' * Imported to UBports') changelog.add_change('') f = open(changelog_file, "w") changelog.write_to_open_file(f) f.close()