diff options
author | Olav Vitters <olav@vitters.nl> | 2014-07-22 01:39:32 +0200 |
---|---|---|
committer | Olav Vitters <olav@vitters.nl> | 2014-07-22 01:39:32 +0200 |
commit | e6bb7bc011091f8b4489581c76d2de87ee6713e5 (patch) | |
tree | 1d8c48acaedb537f59c8dff186efd1c0538cc058 | |
parent | 90e408af16858fc11b3ef53c028d4e128f64a8f3 (diff) | |
download | mgagnome-e6bb7bc011091f8b4489581c76d2de87ee6713e5.tar mgagnome-e6bb7bc011091f8b4489581c76d2de87ee6713e5.tar.gz mgagnome-e6bb7bc011091f8b4489581c76d2de87ee6713e5.tar.bz2 mgagnome-e6bb7bc011091f8b4489581c76d2de87ee6713e5.tar.xz mgagnome-e6bb7bc011091f8b4489581c76d2de87ee6713e5.zip |
allow specifying replacement string and add regexp for ensuring download.gnome.org is over https
-rwxr-xr-x | mgagnome | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -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<keeppre>^\%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<keeppre>^\%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<keeppost>(?:^#[^%\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<keeppre>\%setup -q )-n (?:\%name|\%\{name\})-(?:\%version|\%\{version\})(?P<keeppost>\n)', re.MULTILINE + re.IGNORECASE)), + ('remove defattr', None, re.compile(r'(?P<keeppre>^\%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<keeppre>^\%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<keeppost>(?:^#[^%\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<keeppre>\%setup -q )-n (?:\%name|\%\{name\})-(?:\%version|\%\{version\})(?P<keeppost>\n)', re.MULTILINE + re.IGNORECASE)), + ('https for download.gnome.org', r'\g<keeppre>https://\g<keeppost>', re.compile(r'^(?P<keeppre>Source[0-9]*[ \t]*:[^\n]+)http://(?P<keeppost>download.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<keeppre>' - if 'keeppost' in regexp.groupindex: change_to += r'\g<keeppost>' + 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, nr = regexp.subn(change_to, data) if nr: made_changes = True |