From e6bb7bc011091f8b4489581c76d2de87ee6713e5 Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Tue, 22 Jul 2014 01:39:32 +0200 Subject: allow specifying replacement string and add regexp for ensuring download.gnome.org is over https --- mgagnome | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mgagnome b/mgagnome index 1fbbf58..36f1c5c 100755 --- a/mgagnome +++ b/mgagnome @@ -386,11 +386,12 @@ class SpecFile(object): re_rm_buildroot = r'^(?:\s*\[[^\n\]\[]+\][ \t]+\&\&[ \t]+)?(?:rm|\%__rm|\%\{__rm\}) *(?:-rf|-fr|-r) *"?(?:[%$]buildroot|[%$]\{buildroot\}|[%$]\{buildroot\}|\$RPM_BUILDROOT|\$RPM_BUILD_ROOT|\$\{RPM_BUILD_ROOT\}|\$RPM_BUILD_DIR)"?/?[ \t]*\n' re_clean_spec = [ # remove %defattr - ('remove defattr', re.compile(r'(?P^\%files(?:[ \t]+[^\n]*)?\n(?:^\%doc [^\n]+\n)?)^\%defattr\s*\(- *, *root *, *root *(?:, *-)?\)\s*\n', re.MULTILINE + re.IGNORECASE)), - ('remove cleaning buildroot in install', re.compile(r'(?P^\%install(?:[ \t]+[^\n]*)?\n)' + re_rm_buildroot + r'\n?', re.MULTILINE + re.IGNORECASE)), - ('remove clean section', re.compile(r'^\%clean[ \t]*\n(?:' + re_rm_buildroot + r')?\s*(?P(?:^#[^%\n]+\n)*^(?:\%files|\%post|\%pre|\%trigger|\%install|\%package|\%check|\%_font_pkg|$(?!.|\n)))', re.MULTILINE + re.IGNORECASE)), - ('remove buildroot definition', re.compile(r'^BuildRoot[ \t]*:[^\n]+\n', re.MULTILINE + re.IGNORECASE)), - ('remove unneeded setup option', re.compile(r'^(?P\%setup -q )-n (?:\%name|\%\{name\})-(?:\%version|\%\{version\})(?P\n)', re.MULTILINE + re.IGNORECASE)), + ('remove defattr', None, re.compile(r'(?P^\%files(?:[ \t]+[^\n]*)?\n(?:^\%doc [^\n]+\n)?)^\%defattr\s*\(- *, *root *, *root *(?:, *-)?\)\s*\n', re.MULTILINE + re.IGNORECASE)), + ('remove cleaning buildroot in install', None, re.compile(r'(?P^\%install(?:[ \t]+[^\n]*)?\n)' + re_rm_buildroot + r'\n?', re.MULTILINE + re.IGNORECASE)), + ('remove clean section', None, re.compile(r'^\%clean[ \t]*\n(?:' + re_rm_buildroot + r')?\s*(?P(?:^#[^%\n]+\n)*^(?:\%files|\%post|\%pre|\%trigger|\%install|\%package|\%check|\%_font_pkg|$(?!.|\n)))', re.MULTILINE + re.IGNORECASE)), + ('remove buildroot definition', None, re.compile(r'^BuildRoot[ \t]*:[^\n]+\n', re.MULTILINE + re.IGNORECASE)), + ('remove unneeded setup option', None, re.compile(r'^(?P\%setup -q )-n (?:\%name|\%\{name\})-(?:\%version|\%\{version\})(?P\n)', re.MULTILINE + re.IGNORECASE)), + ('https for download.gnome.org', r'\ghttps://\g', re.compile(r'^(?PSource[0-9]*[ \t]*:[^\n]+)http://(?Pdownload.gnome.org/[^\n]+\n)', re.MULTILINE + re.IGNORECASE)), ] re_convert_br = [ ('remove py_requires', ('python',), re.compile(r'^\%(?:py_requires|\{py_requires\})[ \t]*\n', re.MULTILINE)), @@ -400,10 +401,11 @@ class SpecFile(object): made_changes = False with open(self.path, "rw") as f: data = f.read() - for reason, regexp in re_clean_spec: - change_to = "" - if 'keeppre' in regexp.groupindex: change_to += r'\g' - if 'keeppost' in regexp.groupindex: change_to += r'\g' + 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, nr = regexp.subn(change_to, data) if nr: made_changes = True -- cgit v1.2.1