diff options
-rwxr-xr-x | mgagnome | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -559,25 +559,27 @@ class SpecFile(object): self._changes.clear() subprocess.check_call(["svn", "revert", "-R", os.path.join(self.cwd, '..')]) - def remove_patch(self, nr): - nrs = [str(nr)] - if nr == 0: nrs.append('') + def remove_patch(self, patchnr): + """Remove a patch from the spec file""" + # Uses string as well as numeric comparisons to determine which patch to remove + nrs = [str(patchnr), patchnr] + if patchnr == 0: nrs.append('') with open(self.path, "r", encoding="utf-8") as f: data = f.read() len_before=len(data) - data, nr = self.re_update_patch.subn(lambda mo: '' if mo.group('nr') in nrs else mo.group(0), data) + data, nr = self.re_update_patch.subn(lambda mo: '' if mo.group('nr') in nrs or (mo.group('nr').isdigit() and int(mo.group('nr')) in nrs) else mo.group(0), data) # XXX - pretty hacky if len(data) == len_before: - print("ERROR: Could not remove patch nr %s!" % nr, file=sys.stderr) + print("ERROR: Could not remove patch nr %s!" % patchnr, file=sys.stderr) return False # Overwrite file with new version number write_file(self.path, data) - self._changes['dropped merged patch %s' % nr] = True + self._changes['dropped merged patch %s' % patchnr] = True subprocess.check_call(['mgarepo', 'sync'], cwd=self.cwd) return True |