diff options
author | Olav Vitters <olav@vitters.nl> | 2017-02-18 14:58:36 +0100 |
---|---|---|
committer | Olav Vitters <olav@vitters.nl> | 2017-02-18 14:58:36 +0100 |
commit | 6b4ccbf064ec68dae8573b592ccd41fd56a1e774 (patch) | |
tree | 009abb6069cbfbb71f5296e96311d88ea595e9a6 | |
parent | c22fede7855472159c5bf515db06aea453054d40 (diff) | |
download | mgagnome-6b4ccbf064ec68dae8573b592ccd41fd56a1e774.tar mgagnome-6b4ccbf064ec68dae8573b592ccd41fd56a1e774.tar.gz mgagnome-6b4ccbf064ec68dae8573b592ccd41fd56a1e774.tar.bz2 mgagnome-6b4ccbf064ec68dae8573b592ccd41fd56a1e774.tar.xz mgagnome-6b4ccbf064ec68dae8573b592ccd41fd56a1e774.zip |
better handle Patch[nr] starting with zeros
-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 |