diff options
-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): |