def extract_commit(source): """ Try to extract git archive information from a source entry """ origin_name = '{0}.origin'.format(source) if not os.path.exists(origin_name): return (None, None) with open(origin_name, 'r') as origin_file: url = origin_file.readline().strip() # Note: sha is the empty string if EOF sha = origin_file.readline().strip() # .gitarchive-info wins over everything else if tarfile.is_tarfile(source): with Tarball(source) as tarball: try: archive_info = tarball.extractfile('.gitarchive-info') if archive_info: commitish = get_commit_id(archive_info) return (url, commitish) except KeyError: print("No .gitarchive-info info found for {0}".format(source)) if sha: return (url, sha) return (None, None)
def __contains__(self, name): # the extraction of the names is delayed as we may not yet # have downloaded the Archive at the time of creating the # object if self._names is None: with Tarball(self.path) as tarball: self._names = [os.path.basename(n) for n in tarball.getnames()] return name in self._names
def extract_source(self, name, destdir): """ Extract source 'name' to destdir. Raises KeyError if the requested source cannot be found. """ # For an archive, extract_source extracts the file from the archive # and writes it to the destination. with Tarball(self.path) as tarball: target_path = os.path.normpath(os.path.join(self.prefix, name)) tarball.extract((target_path, ), destdir)
def extract_sources(self, names, destdir): """ Extract all the source [names] to [destdir]. Raises [KeyError] for the first requested source that cannot be found. """ with Tarball(self.path) as tarball: target_paths = [ os.path.normpath(os.path.join(self.prefix, name)) for name in names ] tarball.extract(target_paths, destdir)
def extract_commit(source, manifests): """ Try to extract git archive information from a source entry """ if tarfile.is_tarfile(source): with Tarball(source) as tarball: try: archive_info = tarball.extractfile('.gitarchive-info') if archive_info: name = os.path.basename(source) origin_name = '{0}.origin'.format(source) if os.path.exists(origin_name): with open(origin_name, 'r') as origin_file: name = origin_file.readline() manifests[name.strip()] = get_commit_id(archive_info) except KeyError: pass
def extract_sources(self, names, destdir): """ Extract all the source [names] to [destdir]. Raises [KeyError] for the first requested source that cannot be found. """ with Tarball(self.path) as tarball: # patches within the patchqueue target_paths = [ os.path.normpath(os.path.join(self.prefix, name)) for name in set(names) & set(self.series()) ] # files not in the patchqueue target_paths += [ os.path.normpath(name) for name in set(names) - set(self.series()) ] tarball.extract(target_paths, destdir)
def populate_working_directory(tmpdir, spec, link, sources, patchqueue): """ Build a working directory containing everything needed to build the SRPM. """ # Copy spec to working area tmp_specfile = os.path.join(tmpdir, os.path.basename(spec)) shutil.copyfile(spec, tmp_specfile) manifests = {} # Copy sources to working area for source in sources: extract_commit(source, manifests) shutil.copy(source, tmpdir) if manifests: add_manifest_entry(manifests, tmp_specfile) else: print("No .gitarchive-info found for {0}".format(spec)) spec = Spec(tmp_specfile, check_package_name=False) # Expand patchqueue to working area, rewriting spec as needed if link and patchqueue: # Extract patches if link.patchqueue is not None: with Patchqueue(patchqueue, branch=link.patchqueue) as patches: patches.extract_all(tmpdir) patches.add_to_spec(spec, tmp_specfile) # Extract non-patchqueue sources with Tarball(patchqueue) as tarball: if link.sources is not None: for source in spec.local_sources(): path = os.path.join(link.sources, source) tarball.extract(path, tmpdir) if link.patches is not None: for patch in spec.local_patches(): path = os.path.join(link.patches, patch) tarball.extract(path, tmpdir) return tmp_specfile
def populate_working_directory(tmpdir, spec, link, sources, patchqueue): """ Build a working directory containing everything needed to build the SRPM. """ # Copy spec to working area tmp_specfile = os.path.join(tmpdir, os.path.basename(spec)) shutil.copyfile(spec, tmp_specfile) # Copy sources to working area, rewriting spec as needed tarball_filters = ['.tar.gz', '.tar.bz2'] for source in sources: if any([ext in source for ext in tarball_filters]): extract_topdir(tmp_specfile, source) shutil.copy(source, tmpdir) spec = Spec(tmp_specfile, check_package_name=False) # Expand patchqueue to working area, rewriting spec as needed if link and patchqueue: # Extract patches if link.patchqueue is not None: with Patchqueue(patchqueue, branch=link.patchqueue) as patches: patches.extract_all(tmpdir) patches.add_to_spec(spec, tmp_specfile) # Extract non-patchqueue sources with Tarball(patchqueue) as tarball: if link.sources is not None: for source in spec.local_sources(): path = os.path.join(link.sources, source) tarball.extract(path, tmpdir) if link.patches is not None: for patch in spec.local_patches(): path = os.path.join(link.patches, patch) tarball.extract(path, tmpdir) return tmp_specfile