From d55dfc1682678d966e2303223ef5198d24f1bc9d Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Wed, 16 Dec 2015 19:18:54 +0100 Subject: ensure spec changes are commited only once --- mgagnome | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/mgagnome b/mgagnome index d143272..fdc9534 100755 --- a/mgagnome +++ b/mgagnome @@ -51,6 +51,9 @@ import requests import concurrent.futures +# for merging comments in order +import collections + SLEEP_INITIAL=180 SLEEP_REPEAT=30 SLEEP_TIMES=30 @@ -315,11 +318,11 @@ class SpecFile(object): self.path = path self.cwd = os.path.dirname(path) self.module = module - self._changes = [] + self._changes = collections.OrderedDict() @property def changes(self): - return self._changes[0] if len(self._changes) == 1 else "\n".join(("- %s" % change for change in self._changes)) + return ''.join(self._changes.keys()) if len(self._changes) == 1 else "\n".join(("- %s" % change for change in self._changes.keys())) @property def version(self): @@ -374,7 +377,7 @@ class SpecFile(object): data, nr = regexp.subn(change_to, data) if nr: made_changes = True - self._changes.append('SILENT %s' % reason) + self._changes['SILENT %s' % reason] = True # Convert %py_requires and %py_requires -d # - first figure out how a buildrequire is usually defined @@ -396,7 +399,7 @@ class SpecFile(object): data, nr = regexp.subn(change_to, data) if nr: made_changes = True - self._changes.append('SILENT %s' % reason) + self._changes['SILENT %s' % reason] = True # Convert: # %define name SOMETHING @@ -421,7 +424,7 @@ class SpecFile(object): if made_changes and converted_defines: data = data.lstrip() - self._changes.append('SILENT remove variable definition(s) %s' % ", ".join(converted_defines)) + self._changes['SILENT remove variable definition(s) %s' % ", ".join(converted_defines)] = True made_changes, data = self._clean_spec_patches(f, made_changes, data) @@ -503,7 +506,7 @@ class SpecFile(object): if self.check_and_update_patches(check_only=True): pass data = change_to - self._changes.append('SILENT use autopatch') + self._changes['SILENT use autopatch'] = True made_changes = True finally: if not made_changes: @@ -541,7 +544,7 @@ class SpecFile(object): def _revert_changes(self): """Revert uncommited changes made to spec file""" - self._changes = [] + self._changes.clear() subprocess.check_call(["svn", "revert", "-R", os.path.join(self.cwd, '..')]) def remove_patch(self, nr): @@ -562,7 +565,7 @@ class SpecFile(object): # Overwrite file with new version number write_file(self.path, data) - self._changes.append('dropped merged patch %s' % nr) + self._changes['dropped merged patch %s' % nr] = True subprocess.check_call(['mgarepo', 'sync'], cwd=self.cwd) return True @@ -671,7 +674,7 @@ class SpecFile(object): data, nr = self.re_update_br_unsplit.subn(lambda mo: ''.join((''.join((mo.group('pre'), mo2.group(0), mo.group('unsplitpost'))) for mo2 in self.re_br_part.finditer(mo.group('unsplit')) if mo.group(0).strip() != '')), data) if data_before != data: made_changes = True - self._changes.append('SILENT one line per buildrequirement') + self._changes['SILENT one line per buildrequirement'] = True data_before = data # Change =< and => operators into <= and >= @@ -679,7 +682,7 @@ class SpecFile(object): data, nr = self.re_update_br_fix_operator.subn(lambda mo: mo.group(0).replace('=>', '>=').replace('=<', '<') if self.re_update_br.match(mo.group(0).replace('=>', '>=').replace('=<', '<')) else mo.group(0), data) if data_before != data: made_changes = True - self._changes.append('SILENT fix operator in buildrequires') + self._changes['SILENT fix operator in buildrequires'] = True data_before = data # Now update buildrequires if any @@ -688,7 +691,7 @@ class SpecFile(object): # XXX - very hacky because of multiple changes, could miss out on a change if data_before != data: made_changes = True - self._changes.append('SILENT %s' % change_description) + self._changes['SILENT %s' % change_description] = True elif len(changes) != 0: print("ERROR: Could not update buildrequires!", file=sys.stderr) print(changes) @@ -763,7 +766,7 @@ class SpecFile(object): # Overwrite file with new version number write_file(self.path, data) - self._changes.append('new version %s' % version) + self._changes['new version %s' % version] = True # Verify that RPM also agrees that version number has changed if self.version != version: -- cgit v1.2.1