From 9042d481cc2d939877235b6ebc30ff9495fc0eed Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Tue, 28 Apr 2020 10:20:17 +0200 Subject: pylint: make more variables conform to pylint --- mgagnome | 68 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/mgagnome b/mgagnome index 8abe1f2..a7e7923 100755 --- a/mgagnome +++ b/mgagnome @@ -431,8 +431,8 @@ class SpecFile(): change_to += r'\g' if 'keeppost' in regexp.groupindex: change_to += r'\g' - data, nr = regexp.subn(change_to, data) - if nr: + data, subs = regexp.subn(change_to, data) + if subs: made_changes = True self._changes['SILENT %s' % reason] = True if should_rebuild: @@ -453,10 +453,10 @@ class SpecFile(): if match2.group('br') in new_brs: brs_in_file.add(match2.group('br')) - for br in set(new_brs) - brs_in_file: - change_to += ''.join((br_pre, br, "\n")) - data, nr = regexp.subn(change_to, data) - if nr: + for buildreq in set(new_brs) - brs_in_file: + change_to += ''.join((br_pre, buildreq, "\n")) + data, subs = regexp.subn(change_to, data) + if subs: made_changes = True self._changes['SILENT %s' % reason] = True @@ -475,10 +475,10 @@ class SpecFile(): if match and match.group('definition') and len(re_variable.findall(data)) == 1: match2 = re_spec.search(data) if match2: - data, nr = re_spec.subn(r'\g' + match.group('definition').replace('\\', '\\\\') + r'\g', data) - if nr: + data, subs = re_spec.subn(r'\g' + match.group('definition').replace('\\', '\\\\') + r'\g', data) + if subs: made_changes = True - data, nr = re_variable.subn('', data) + data, subs = re_variable.subn('', data) converted_defines.append(search_for) if made_changes and converted_defines: @@ -573,9 +573,9 @@ class SpecFile(): def buildrequires(self): rpm.delMacro("_topdir") rpm.addMacro("_topdir", os.path.join(self.cwd, '..')) - ts = rpm.ts() + trans_set = rpm.ts() try: - spec = ts.parseSpec(self.path) + spec = trans_set.parseSpec(self.path) except ValueError as exc: # Reraise this into a more specific exception raise SpecFileError from exc @@ -588,7 +588,7 @@ class SpecFile(): require_flags = spec.sourceHeader[rpm.RPMTAG_REQUIREFLAGS] require_ver = spec.sourceHeader[rpm.RPMTAG_REQUIREVERSION] - br = {} + buildreqs = {} for req, flag, ver in itertools.zip_longest(requires, require_flags, require_ver): # bitmask other than 15 means the require is (probably?) a require for a trigger or script if flag & 15 != flag: @@ -602,8 +602,8 @@ class SpecFile(): if flag & rpm.RPMSENSE_EQUAL: ver_cmp += '=' - br[req] = (ver_cmp, ver) - return br + buildreqs[req] = (ver_cmp, ver) + return buildreqs @property def uses_apply_patches(self): @@ -624,9 +624,9 @@ class SpecFile(): with open(self.path, "r", encoding="utf-8") as f: data = f.read() - data, nr = self.re_update_patch.subn(lambda match: '' if match.group('nr') in nrs or (match.group('nr').isdigit() and int(match.group('nr')) in nrs) else match.group(0), data) + data, subs = self.re_update_patch.subn(lambda match: '' if match.group('nr') in nrs or (match.group('nr').isdigit() and int(match.group('nr')) in nrs) else match.group(0), data) - if not nr: + if not subs: print("ERROR: Could not remove patch nr %s!" % patchnr, file=sys.stderr) return False @@ -642,13 +642,11 @@ class SpecFile(): subprocess.check_call(['mgarepo', 'sync'], cwd=self.cwd) return True - def check_and_update_patches(self, check_only=False): + def check_and_update_patches(self, check_only=False, lines_in_log=15): """Check if patches still apply Remove any merged patches""" - LOGLINES = 15 - initial_patches = self.patches patches = initial_patches uses_apply_patches = self.uses_apply_patches if patches else False @@ -719,11 +717,11 @@ class SpecFile(): print("ERROR: Problem removing merged patch: %s" % failed_patch, file=sys.stderr) return False - if cmd and len(cmd_output) > LOGLINES: + if cmd and len(cmd_output) > lines_in_log: print('+ %s' % cmd, file=sys.stdout) print("\n".join(cmd_output), file=sys.stdout) elif os.path.exists(logfile): - subprocess.call(['tail', '-n', str(LOGLINES), logfile]) + subprocess.call(['tail', '-n', str(lines_in_log), logfile]) if failed_patch: print("ERROR: Problem applying patch: %s" % failed_patch, file=sys.stderr) @@ -752,21 +750,21 @@ class SpecFile(): data = f.read() # Change any "," in buildrequires into multiple lines - data, nr = self.re_update_br_unsplit.subn(lambda match: ''.join((''.join((match.group('pre'), match2.group(0), match.group('unsplitpost'))) for match2 in self.re_br_part.finditer(match.group('unsplit')) if match.group(0).strip() != '')), data) - if nr: + data, subs = self.re_update_br_unsplit.subn(lambda match: ''.join((''.join((match.group('pre'), match2.group(0), match.group('unsplitpost'))) for match2 in self.re_br_part.finditer(match.group('unsplit')) if match.group(0).strip() != '')), data) + if subs: made_changes = True self._changes['SILENT one line per buildrequirement'] = True # Change =< and => operators into <= and >= - data, nr = self.re_update_br_fix_operator.subn(lambda match: match.group(0).replace('=>', '>=').replace('=<', '<') if self.re_update_br.match(match.group(0).replace('=>', '>=').replace('=<', '<')) else match.group(0), data) - if nr: + data, subs = self.re_update_br_fix_operator.subn(lambda match: match.group(0).replace('=>', '>=').replace('=<', '<') if self.re_update_br.match(match.group(0).replace('=>', '>=').replace('=<', '<')) else match.group(0), data) + if subs: made_changes = True self._changes['SILENT fix operator in buildrequires'] = True # Now update buildrequires if any - data, nr = self.re_update_br.subn(lambda match: ''.join((match.group('pre'), changes[match.group('br')], match.group('post'))) if match.group('br') in changes else match.group(0), data) + data, subs = self.re_update_br.subn(lambda match: ''.join((match.group('pre'), changes[match.group('br')], match.group('post'))) if match.group('br') in changes else match.group(0), data) - if nr: + if subs: made_changes = True self._changes['SILENT %s' % change_description] = True elif len(changes) != 0: @@ -826,8 +824,8 @@ class SpecFile(): return False # XXX - validate current release - data, nr = self.re_update_release.subn(r'\g
%%mkrel %s\g' % release, data, 1)
-        if nr != 1:
+        data, subs = self.re_update_release.subn(r'\g
%%mkrel %s\g' % release, data, 1)
+        if subs != 1:
             print(data, file=sys.stdout)
             print("ERROR: Could not increase release!", file=sys.stderr)
             return False
@@ -859,13 +857,13 @@ class SpecFile():
         if data is None:
             return False
 
-        data, nr = self.re_update_version.subn(r'\g
%s\g' % version, data, 1)
-        if nr != 1:
+        data, subs = self.re_update_version.subn(r'\g
%s\g' % version, data, 1)
+        if subs != 1:
             print("ERROR: Could not increase version!", file=sys.stderr)
             return False
 
-        data, nr = self.re_update_release.subn(r'\g
%mkrel 1\g', data, 1)
-        if nr != 1:
+        data, subs = self.re_update_release.subn(r'\g
%mkrel 1\g', data, 1)
+        if subs != 1:
             print(data, file=sys.stdout)
             print("ERROR: Could not reset release!", file=sys.stderr)
             return False
@@ -1472,7 +1470,7 @@ def cmd_clean_spec_multi(args):
     # Convert perl- and -devel buildrequires into perl() and pkgconfig() requires
     if options.convert_br:
         re_prov_get_version = re.compile(r'^[^(]+\([^)]+-(?P[0-9]+\.[0-9][0-9.]*)\)$')
-        br = spec.buildrequires
+        buildreqs = spec.buildrequires
         no_alt = set()
         no_change = {}
         convert_brs = {
@@ -1526,7 +1524,7 @@ def cmd_clean_spec_multi(args):
                 continue
 
             keys['changes'] = {}
-            br_old = [r for r in list(br.keys()) if keys['check_br'](r)]
+            br_old = [r for r in list(buildreqs.keys()) if keys['check_br'](r)]
             if options.debug and br_old:
                 pprint.pprint(br_old)
             for req in br_old:
-- 
cgit v1.2.1