From 98222133e548f1c88a28a26bbc9e23f1d42a4007 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 22 Jan 2012 16:46:51 +0100 Subject: deb: Add UpstreamSource.build_tarball_name to build a tarball name from a (package, version, compression) triplet optionally adding a directory. --- gbp/deb/__init__.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'gbp') diff --git a/gbp/deb/__init__.py b/gbp/deb/__init__.py index 92d893ab..b02c5fa8 100644 --- a/gbp/deb/__init__.py +++ b/gbp/deb/__init__.py @@ -277,6 +277,34 @@ class UpstreamSource(object): if m: return (m.group('package'), m.group('version')) + @staticmethod + def build_tarball_name(name, version, compression, dir=None): + """ + Given a source package's I{name}, I{version} and I{compression} + return the name of the corresponding upstream tarball. + + >>> UpstreamSource.build_tarball_name('foo', '1.0', 'bzip2') + 'foo_1.0.orig.tar.bz2' + >>> UpstreamSource.build_tarball_name('bar', '0.0~git1234', 'xz') + 'bar_0.0~git1234.orig.tar.xz' + + @param name: the source package's name + @type name: C{str} + @param version: the upstream version + @type version: C{str} + @param compression: the desired compression + @type compression: C{str} + @param dir: a directory to prepend + @type dir: C{str} + @return: the tarballs name corresponding to the input parameters + @rtype: C{str} + """ + ext = compressor_opts[compression][1] + tarball = "%s_%s.orig.tar.%s" % (name, version, ext) + if dir: + tarball = os.path.join(dir, tarball) + return tarball + class DscFile(object): """Keeps all needed data read from a dscfile""" @@ -397,8 +425,10 @@ def orig_file(cp, compression): >>> orig_file({'Source': 'bar', 'Upstream-Version': '0.0~git1234'}, "xz") 'bar_0.0~git1234.orig.tar.xz' """ - ext = compressor_opts[compression][1] - return "%s_%s.orig.tar.%s" % (cp['Source'], cp['Upstream-Version'], ext) + return UpstreamSource.build_tarball_name(cp['Source'], + cp['Upstream-Version'], + compression) + def is_valid_packagename(name): "Is this a valid Debian package name?" -- cgit v1.2.3