diff options
author | Olav Vitters <olav@vitters.nl> | 2020-05-06 13:59:53 +0200 |
---|---|---|
committer | Olav Vitters <olav@vitters.nl> | 2020-05-06 13:59:53 +0200 |
commit | 38085480c9422826e55a2d9f4d465b36bbfee436 (patch) | |
tree | 27fead6dc00cc870d78c224bcdf6c16d28beb839 | |
parent | d2cfcf139fc8f9f874e89c6e30c96a52ba4888a3 (diff) | |
download | mgagnome-38085480c9422826e55a2d9f4d465b36bbfee436.tar mgagnome-38085480c9422826e55a2d9f4d465b36bbfee436.tar.gz mgagnome-38085480c9422826e55a2d9f4d465b36bbfee436.tar.bz2 mgagnome-38085480c9422826e55a2d9f4d465b36bbfee436.tar.xz mgagnome-38085480c9422826e55a2d9f4d465b36bbfee436.zip |
Spec.clean_spec: split/move some logic into a new function
-rwxr-xr-x | mgagnome | 58 |
1 files changed, 32 insertions, 26 deletions
@@ -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<keeppre>' - if 'keeppost' in regexp.groupindex: - change_to += r'\g<keeppost>' - 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<keeppre>' + if 'keeppost' in regexp.groupindex: + change_to += r'\g<keeppost>' + 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): |