summaryrefslogtreecommitdiff
path: root/gbp/deb/format.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2013-03-29 15:55:12 +0100
committerGuido Günther <agx@sigxcpu.org>2013-04-13 14:26:24 +0200
commita60f37dab018ee827aef631f0e1646e720194655 (patch)
tree78e4185d2a5ed9c58544aad4cd4360c6c6904793 /gbp/deb/format.py
parent8fd5ec31272984a7fcff628c50b4c22d7e4107ec (diff)
Introduce Source class
so we don't have to expose all the details of Debian's different files and conventions.
Diffstat (limited to 'gbp/deb/format.py')
-rw-r--r--gbp/deb/format.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/gbp/deb/format.py b/gbp/deb/format.py
index 8d6ac5e..9abba73 100644
--- a/gbp/deb/format.py
+++ b/gbp/deb/format.py
@@ -40,6 +40,7 @@ class DebianSourceFormat(object):
...
DebianSourceFormatError: Cannot get source format from '1.0 broken'
"""
+ format_file = 'debian/source/format'
def _parse(self, content):
parts = content.split()
@@ -68,6 +69,9 @@ class DebianSourceFormat(object):
"""The 'type' (e.g. git, native)"""
return self._type
+ def __str__(self):
+ return "%s (%s)" % (self._version, self._type)
+
@classmethod
def parse_file(klass, filename):
"""
@@ -91,6 +95,21 @@ class DebianSourceFormat(object):
with file(filename) as f:
return klass(f.read())
+ @classmethod
+ def from_content(klass, version, type, format_file=None):
+ """
+ Write a format file from I{type} and I{format} at
+ I{format_file}
+
+ @param version: the source package format version
+ @param type: the format type
+ @param format_file: the format file to create with
+ the above parameters
+ """
+ format_file = format_file or klass.format_file
+ with file(klass.format_file, 'w') as f:
+ f.write("%s (%s)" % (version, type))
+ return klass.parse_file(klass.format_file)
if __name__ == "__main__":
import doctest