From 6b4ccbf064ec68dae8573b592ccd41fd56a1e774 Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Sat, 18 Feb 2017 14:58:36 +0100 Subject: better handle Patch[nr] starting with zeros --- mgagnome | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mgagnome b/mgagnome index 274ef9a..7d95697 100755 --- a/mgagnome +++ b/mgagnome @@ -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 -- cgit v1.2.1