diff options
author | Guido Günther <agx@sigxcpu.org> | 2017-11-27 19:59:32 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2017-11-27 22:49:52 +0100 |
commit | 09e013ffed5c4d64b2c4bc04755c5b8921f554f4 (patch) | |
tree | 650e210b02096789ce300c07d994bba0dc715427 | |
parent | a12c5960232fc10996324d3204bd468cb80ec76b (diff) |
DebianSource: provide mapping for control file as well
This makes sure we have the logic to access these files in debian/
in one place.
Gbp-Dch: Ignore
-rw-r--r-- | gbp/deb/source.py | 15 | ||||
-rw-r--r-- | tests/15_test_DebianSource.py | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/gbp/deb/source.py b/gbp/deb/source.py index 643aac2e..a2e1c9a8 100644 --- a/gbp/deb/source.py +++ b/gbp/deb/source.py @@ -20,6 +20,7 @@ import os from gbp.deb import DebianPkgPolicy as Policy from gbp.deb.format import DebianSourceFormat from gbp.deb.changelog import ChangeLog +from gbp.deb.control import Control class FileVfs(object): @@ -56,6 +57,7 @@ class DebianSource(object): package. """ self._changelog = None + self._control = None if isinstance(vfs, str): self._vfs = FileVfs(vfs) @@ -101,6 +103,19 @@ class DebianSource(object): return self._changelog @property + def control(self): + """ + Return the L{gbp.deb.Control} + """ + if not self._control: + try: + with self._vfs.open('debian/control', 'rb') as cf: + self._control = Control(cf.read().decode('utf-8')) + except IOError as err: + raise DebianSourceError('Failed to read control file: %s' % err) + return self._control + + @property def sourcepkg(self): """ The source package's name diff --git a/tests/15_test_DebianSource.py b/tests/15_test_DebianSource.py index efc38b4f..06ffb78b 100644 --- a/tests/15_test_DebianSource.py +++ b/tests/15_test_DebianSource.py @@ -110,3 +110,11 @@ class TestDebianSource(testutils.DebianGitTestRepo): source = DebianSource('.') self.assertEquals(source.changelog.distribution, "UNRELEASED") self.assertFalse(source.is_releasable()) + + def test_control(self): + os.makedirs('debian/') + with open('debian/control', 'w') as f: + f.write("Source: foo") + source = DebianSource('.') + self.assertIsNotNone(source.control) + self.assertEquals(source.control.name, "foo") |