def patchseries(self, unapplied=False, ignored=False): """Return non-ignored patches of the RPM as a gbp patchseries""" series = PatchSeries() if 'patch' in self._tags: tags = self._patches() applied = [] for macro in self._special_directives['patch']: if macro['id'] in tags: applied.append((macro['id'], macro['args'])) ignored = set() if ignored else set(self.ignorepatches) # Put all patches that are applied first in the series for num, args in applied: if num not in ignored: opts = self._patch_macro_opts(args) strip = int(opts.strip) if opts.strip else 0 filename = os.path.basename(tags[num]['linevalue']) series.append( Patch(os.path.join(self.specdir, filename), strip=strip)) # Finally, append all unapplied patches to the series, if requested if unapplied: applied_nums = set([num for num, _args in applied]) unapplied = set(tags.keys()).difference(applied_nums) for num in sorted(unapplied): if num not in ignored: filename = os.path.basename(tags[num]['linevalue']) series.append( Patch(os.path.join(self.specdir, filename), strip=0)) return series
def patchseries(self, unapplied=False, ignored=False): """Return non-ignored patches of the RPM as a gbp patchseries""" series = PatchSeries() if "patch" in self._tags: tags = self._patches() applied = [] for macro in self._special_directives["patch"]: if macro["id"] in tags: applied.append((macro["id"], macro["args"])) ignored = set() if ignored else set(self.ignorepatches) # Put all patches that are applied first in the series for num, args in applied: if num not in ignored: opts = self._patch_macro_opts(args) strip = int(opts.strip) if opts.strip else 0 filename = os.path.basename(tags[num]["linevalue"]) series.append(Patch(os.path.join(self.specdir, filename), strip=strip)) # Finally, append all unapplied patches to the series, if requested if unapplied: applied_nums = set([num for num, _args in applied]) unapplied = set(tags.keys()).difference(applied_nums) for num in sorted(unapplied): if num not in ignored: filename = os.path.basename(tags[num]["linevalue"]) series.append(Patch(os.path.join(self.specdir, filename), strip=0)) return series
def bb_to_patch_series(bbfile): """Get all local patches as a series""" series = PatchSeries() for path in bbfile.localfiles: if path.endswith('.patch'): series.append(Patch(path)) return series
def safe_patches(queue, tmpdir_base): """ Safe the current patches in a temporary directory below 'tmpdir_base'. Also, uncompress compressed patches here. @param queue: an existing patch queue @param tmpdir_base: base under which to create tmpdir @return: tmpdir and a safed queue (with patches in tmpdir) @rtype: tuple """ tmpdir = tempfile.mkdtemp(dir=tmpdir_base, prefix='patchimport_') safequeue = PatchSeries() if len(queue) > 0: gbp.log.debug("Safeing patches '%s' in '%s'" % (os.path.dirname(queue[0].path), tmpdir)) for patch in queue: base, _archive_fmt, comp = parse_archive_filename(patch.path) uncompressors = {'gzip': gzip.open, 'bzip2': bz2.BZ2File} if comp in uncompressors: gbp.log.debug("Uncompressing '%s'" % os.path.basename(patch.path)) src = uncompressors[comp](patch.path, 'r') dst_name = os.path.join(tmpdir, os.path.basename(base)) if _archive_fmt: tar_name = dst_name dst_name += '.tar' elif comp: raise GbpError("Unsupported patch compression '%s', giving up" % comp) else: src = open(patch.path, 'r') dst_name = os.path.join(tmpdir, os.path.basename(patch.path)) dst = open(dst_name, 'w') dst.writelines(src) src.close() dst.close() if _archive_fmt: t = tarfile.open(dst_name, 'r:') t.extractall(path=tmpdir) t.close() dst_name = tar_name safequeue.append(patch) safequeue[-1].path = dst_name return safequeue
def safe_patches(queue, tmpdir_base): """ Safe the current patches in a temporary directory below 'tmpdir_base'. Also, uncompress compressed patches here. @param queue: an existing patch queue @param tmpdir_base: base under which to create tmpdir @return: tmpdir and a safed queue (with patches in tmpdir) @rtype: tuple """ tmpdir = tempfile.mkdtemp(dir=tmpdir_base, prefix='patchimport_') safequeue = PatchSeries() if len(queue) > 0: gbp.log.debug("Safeing patches '%s' in '%s'" % (os.path.dirname(queue[0].path), tmpdir)) for patch in queue: base, _archive_fmt, comp = parse_archive_filename(patch.path) uncompressors = {'gzip': gzip.open, 'bzip2': bz2.BZ2File} if comp in uncompressors: gbp.log.debug("Uncompressing '%s'" % os.path.basename(patch.path)) src = uncompressors[comp](patch.path, 'r') dst_name = os.path.join(tmpdir, os.path.basename(base)) elif comp: raise GbpError("Unsupported patch compression '%s', giving up" % comp) else: src = open(patch.path, 'r') dst_name = os.path.join(tmpdir, os.path.basename(patch.path)) dst = open(dst_name, 'w') dst.writelines(src) src.close() dst.close() safequeue.append(patch) safequeue[-1].path = dst_name return safequeue
def patchseries(self, unapplied=False, ignored=False): """Return non-ignored patches of the RPM as a gbp patchseries""" series = PatchSeries() ignored = set() if ignored else set(self.ignorepatches) tags = dict([(k, v) for k, v in self._patches().items() if k not in ignored]) if self._special_directives['autosetup']: # Return all patchses if %autosetup is used for num in sorted(tags): filename = os.path.basename(tags[num]['linevalue']) series.append(Patch(os.path.join(self.specdir, filename))) else: applied = [] for macro in self._special_directives['patch']: if macro['id'] in tags: applied.append((macro['id'], macro['args'])) # Put all patches that are applied first in the series for num, args in applied: opts = self._patch_macro_opts(args) strip = int(opts.strip) if opts.strip else 0 filename = os.path.basename(tags[num]['linevalue']) series.append(Patch(os.path.join(self.specdir, filename), strip=strip)) # Finally, append all unapplied patches to the series, if requested if unapplied: applied_nums = set([num for num, _args in applied]) unapplied = set(tags.keys()).difference(applied_nums) for num in sorted(unapplied): filename = os.path.basename(tags[num]['linevalue']) series.append(Patch(os.path.join(self.specdir, filename), strip=0)) return series
def safe_patches(queue): """ Safe the current patches in a temporary directory @param queue: an existing patch queue @return: safed queue (with patches in tmpdir) @rtype: tuple """ tmpdir = tempfile.mkdtemp(prefix='patchimport_') safequeue = PatchSeries() if len(queue) > 0: gbp.log.debug("Saving patches '%s' in '%s'" % (os.path.dirname(queue[0].path), tmpdir)) for patch in queue: base, _archive_fmt, comp = Archive.parse_filename(patch.path) uncompressors = {'gzip': gzip.open, 'bzip2': bz2.BZ2File} if comp in uncompressors: gbp.log.debug("Uncompressing '%s'" % os.path.basename(patch.path)) src = uncompressors[comp](patch.path, 'r') dst_name = os.path.join(tmpdir, os.path.basename(base)) elif comp: raise GbpError("Unsupported patch compression '%s', giving up" % comp) else: src = open(patch.path, 'rb') dst_name = os.path.join(tmpdir, os.path.basename(patch.path)) dst = open(dst_name, 'wb') dst.write(src.read()) src.close() dst.close() safequeue.append(patch) safequeue[-1].path = dst_name return safequeue