diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-11-30 19:11:35 +0200 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-03-08 14:04:00 +0200 |
commit | 8664d4ec6dba1bcd2f4445d4767265f5411ba44e (patch) | |
tree | e3a1d1ebd39d835cd1c1e43f1b29789fdf8e4e41 | |
parent | b0c6afb86c20cfe9aafa79a276cdfcab40405cba (diff) | |
download | git-buildpackage-8664d4ec6dba1bcd2f4445d4767265f5411ba44e.tar.gz git-buildpackage-8664d4ec6dba1bcd2f4445d4767265f5411ba44e.tar.bz2 git-buildpackage-8664d4ec6dba1bcd2f4445d4767265f5411ba44e.zip |
rpm helpers: support updating tags in the spec file
Currently only the 'VCS' tag is supported.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r-- | gbp/rpm/__init__.py | 26 | ||||
-rw-r--r-- | tests/test_rpm.py | 19 | ||||
-rw-r--r-- | tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec | 1 | ||||
-rw-r--r-- | tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec.orig | 46 | ||||
-rw-r--r-- | tests/test_rpm_data/specs/gbp-test-reference2.spec | 44 | ||||
-rw-r--r-- | tests/test_rpm_data/specs/gbp-test2-reference2.spec | 48 |
6 files changed, 181 insertions, 3 deletions
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index 3d3142e2..713208a2 100644 --- a/gbp/rpm/__init__.py +++ b/gbp/rpm/__init__.py @@ -338,11 +338,15 @@ class SpecFile(object): 'tag_line': lineobj} self.patches[tagnum] = new_patch ret['lastpatchtag'] = lineobj - # 'Name:' and 'Packager:' tags + # Other tags elif tagname == 'name': ret['nametag'] = lineobj elif tagname == 'packager': ret['packagertag'] = lineobj + elif tagname == 'vcs': + ret['vcstag'] = lineobj + elif tagname == 'release': + ret['releasetag'] = lineobj continue # Parse special macros @@ -385,6 +389,26 @@ class SpecFile(object): ret['prepmacro'] = lineobj return ret + def set_tag(self, tag, value): + """Update a tag in spec file content""" + loc = self.parse_content() + + key = tag.lower() + "tag" + if tag.lower() == 'vcs': + if value: + text = '%-12s%s\n' % ('VCS:', value) + if key in loc: + gbp.log.info("Updating '%s' tag in spec" % tag) + loc[key].set_data(text) + else: + gbp.log.info("Adding '%s' tag to spec" % tag) + self.content.insert_after(loc['releasetag'], text) + elif key in loc: + gbp.log.info("Removing '%s' tag from spec" % tag) + self.content.delete(loc[key]) + else: + raise GbpError("Setting '%s:' tag not supported") + def update_patches(self, patchfilenames): """ Update spec with new patch tags and patch macros. diff --git a/tests/test_rpm.py b/tests/test_rpm.py index f9cc8876..55eab93b 100644 --- a/tests/test_rpm.py +++ b/tests/test_rpm.py @@ -153,14 +153,29 @@ class TestSpecFile(object): spec.write_spec_file() assert filecmp.cmp(tmp_spec, reference_spec) is True - # Test a second spec file + # Test adding the VCS tag + reference_spec = os.path.join(SPEC_DIR, 'gbp-test-reference2.spec') + spec.set_tag('vcs', 'myvcstag') + spec.write_spec_file() + assert filecmp.cmp(tmp_spec, reference_spec) is True + + def test_update_spec2(self): + """Another test for spec autoupdate functionality""" + tmp_spec = os.path.join(self.tmpdir, 'gbp-test.spec') shutil.copy2(os.path.join(SPEC_DIR, 'gbp-test2.spec'), tmp_spec) - reference_spec = os.path.join(SPEC_DIR, 'gbp-test2-reference.spec') + + reference_spec = os.path.join(SPEC_DIR, 'gbp-test2-reference2.spec') spec = SpecFile(tmp_spec) spec.update_patches(['new.patch']) + spec.set_tag('vcs', 'myvcstag') spec.write_spec_file() assert filecmp.cmp(tmp_spec, reference_spec) is True + # Test removing the VCS tag + reference_spec = os.path.join(SPEC_DIR, 'gbp-test2-reference.spec') + spec.set_tag('vcs', '') + spec.write_spec_file() + assert filecmp.cmp(tmp_spec, reference_spec) is True class TestUtilityFunctions(object): diff --git a/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec index ffae7e99..4180a877 100644 --- a/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec +++ b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec @@ -13,6 +13,7 @@ Patch: my.patch Patch10: my2.patch Patch20: my3.patch Packager: Markus Lehtonen <markus.lehtonen@linux.intel.com> +VCS: myoldvcstag %description Package for testing the RPM functionality of git-buildpackage. diff --git a/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec.orig b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec.orig new file mode 100644 index 00000000..ffae7e99 --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec.orig @@ -0,0 +1,46 @@ +Name: gbp-test2 +Summary: Test package 2 for git-buildpackage +Epoch: 2 +Version: 3.0 +Release: 0 +Group: Development/Libraries +License: GPLv2 +Source10: ftp://ftp.host.com/%{name}-%{version}.tar.gz +Source: foo.txt +Source20: bar.tar.gz +# Gbp-Ignore-Patches: 0 +Patch: my.patch +Patch10: my2.patch +Patch20: my3.patch +Packager: Markus Lehtonen <markus.lehtonen@linux.intel.com> + +%description +Package for testing the RPM functionality of git-buildpackage. + + +%prep +%setup -T -n %{name}-%{version} -c -a 10 + +%patch +%patch -P 10 -p1 + +echo "Do things" + +# Gbp-Patch-Macros + +%build +make + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/%{_datadir}/%{name} +cp -R * %{buildroot}/%{_datadir}/%{name} +install %{SOURCE0} %{buildroot}/%{_datadir}/%{name} + + + +%files +%defattr(-,root,root,-) +%dir %{_datadir}/%{name} +%{_datadir}/%{name} diff --git a/tests/test_rpm_data/specs/gbp-test-reference2.spec b/tests/test_rpm_data/specs/gbp-test-reference2.spec new file mode 100644 index 00000000..f006fc77 --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test-reference2.spec @@ -0,0 +1,44 @@ +Name: gbp-test +Summary: Test package for git-buildpackage +Version: 1.0 +Release: 1 +VCS: myvcstag +Group: Development/Libraries +License: GPLv2 +Source: %{name}-%{version}.tar.bz2 +Source1: foo.txt +Source20: bar.tar.gz +# Gbp-Ignore-Patches: 0 +Patch0: my.patch +# Patches auto-generated by git-buildpackage: +Patch1: new.patch + + +%description +Package for testing the RPM functionality of git-buildpackage. + + +%prep +%setup -n %{name} -a 20 + +%patch0 +# new.patch +%patch1 -p1 + + +%build +make + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/%{_datadir}/%{name} +cp -R * %{buildroot}/%{_datadir}/%{name} +install %{SOURCE0} %{buildroot}/%{_datadir}/%{name} + + + +%files +%defattr(-,root,root,-) +%dir %{_datadir}/%{name} +%{_datadir}/%{name} diff --git a/tests/test_rpm_data/specs/gbp-test2-reference2.spec b/tests/test_rpm_data/specs/gbp-test2-reference2.spec new file mode 100644 index 00000000..02356d0a --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test2-reference2.spec @@ -0,0 +1,48 @@ +Name: gbp-test2 +Summary: Test package 2 for git-buildpackage +Epoch: 2 +Version: 3.0 +Release: 0 +Group: Development/Libraries +License: GPLv2 +Source10: ftp://ftp.host.com/%{name}-%{version}.tar.gz +Source: foo.txt +Source20: bar.tar.gz +# Gbp-Ignore-Patches: 0 +Patch: my.patch +# Patches auto-generated by git-buildpackage: +Patch1: new.patch +Packager: Markus Lehtonen <markus.lehtonen@linux.intel.com> +VCS: myvcstag + +%description +Package for testing the RPM functionality of git-buildpackage. + + +%prep +%setup -T -n %{name}-%{version} -c -a 10 + +%patch + +echo "Do things" + +# Gbp-Patch-Macros +# new.patch +%patch1 -p1 + +%build +make + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/%{_datadir}/%{name} +cp -R * %{buildroot}/%{_datadir}/%{name} +install %{SOURCE0} %{buildroot}/%{_datadir}/%{name} + + + +%files +%defattr(-,root,root,-) +%dir %{_datadir}/%{name} +%{_datadir}/%{name} |