From 38085480c9422826e55a2d9f4d465b36bbfee436 Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Wed, 6 May 2020 13:59:53 +0200 Subject: Spec.clean_spec: split/move some logic into a new function --- mgagnome | 58 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/mgagnome b/mgagnome index 23560a9..cfe79ac 100755 --- a/mgagnome +++ b/mgagnome @@ -441,6 +441,26 @@ class SpecFile(): def clean_spec(self): """Clean the spec file of deprecated statements""" + made_changes = False + with open(self.path, "r", encoding="utf-8") as fp_spec: + data = fp_spec.read() + + made_changes, data = self._clean_spec_regexp(made_changes, data) + made_changes, data = self._clean_spec_py_requires(made_changes, data) + made_changes, data = self._clean_spec_defines(made_changes, data) + made_changes, data = self._clean_spec_patches(made_changes, data) + + # Overwrite file with new version number + if made_changes: + self._changed_spec_file = True + write_file(self.path, data) + + return made_changes + + + def _clean_spec_regexp(self, made_changes, data): + """Clean spec using regular expressions""" + re_rm_buildroot = r'^(?:\s*\[[^\n\]\[]+\][ \t]+\&\&[ \t]+)?(?:rm|\%__rm|\%\{__rm\}) *' \ r'(?:-rf|-fr|-r) *"?(?:[%$]buildroot|[%$]\{buildroot\}|[%$]\{buildroot\}|' \ r'\$RPM_BUILDROOT|\$RPM_BUILD_ROOT|\$\{RPM_BUILD_ROOT\}|\$RPM_BUILD_DIR)"?/?[ \t]*\n' @@ -566,33 +586,19 @@ class SpecFile(): ('use new Python macros', r'%{python3_version}', re.compile(r'%{py3ver}', re.MULTILINE)), ] - made_changes = False - with open(self.path, "r", encoding="utf-8") as fp_spec: - data = fp_spec.read() - for reason, change_to, regexp in re_clean_spec: - - if change_to is None: - change_to = "" - if 'keeppre' in regexp.groupindex: - change_to += r'\g' - if 'keeppost' in regexp.groupindex: - change_to += r'\g' - data, subs = regexp.subn(change_to, data) - if subs: - made_changes = True - self._changes['SILENT %s' % reason] = True - - - made_changes, data = self._clean_spec_py_requires(made_changes, data) - made_changes, data = self._clean_spec_defines(made_changes, data) - made_changes, data = self._clean_spec_patches(made_changes, data) - - # Overwrite file with new version number - if made_changes: - self._changed_spec_file = True - write_file(self.path, data) + for reason, change_to, regexp in re_clean_spec: + if change_to is None: + change_to = "" + if 'keeppre' in regexp.groupindex: + change_to += r'\g' + if 'keeppost' in regexp.groupindex: + change_to += r'\g' + data, subs = regexp.subn(change_to, data) + if subs: + made_changes = True + self._changes['SILENT %s' % reason] = True - return made_changes + return made_changes, data def _clean_spec_py_requires(self, made_changes, data): -- cgit v1.2.1