Refactor deb helpers: move build_tarball_name()
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 8 Feb 2012 12:26:24 +0000 (14:26 +0200)
committerGuido Günther <agx@sigxcpu.org>
Tue, 1 May 2012 20:28:19 +0000 (22:28 +0200)
from UpstreamSource class to DebianPkgPolicy.

gbp/deb/__init__.py
gbp/deb/pristinetar.py

index 0b5168e..c0919c3 100644 (file)
@@ -60,6 +60,34 @@ class DebianPkgPolicy(PkgPolicy):
     letters (a-z), digits (0-9), full stops (.), plus signs (+), minus signs
     (-), colons (:) and tildes (~)"""
 
+    @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.
+
+        >>> DebianPkgPolicy.build_tarball_name('foo', '1.0', 'bzip2')
+        'foo_1.0.orig.tar.bz2'
+        >>> DebianPkgPolicy.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 DpkgCompareVersions(gbpc.Command):
     cmd='/usr/bin/dpkg'
@@ -290,34 +318,6 @@ 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"""
@@ -438,9 +438,9 @@ def orig_file(cp, compression):
     >>> orig_file({'Source': 'bar', 'Upstream-Version': '0.0~git1234'}, "xz")
     'bar_0.0~git1234.orig.tar.xz'
     """
-    return UpstreamSource.build_tarball_name(cp['Source'],
-                                             cp['Upstream-Version'],
-                                             compression)
+    return DebianPkgPolicy.build_tarball_name(cp['Source'],
+                                              cp['Upstream-Version'],
+                                              compression)
 
 
 def parse_uscan(out):
index 2ac82ef..a2f191f 100644 (file)
@@ -20,7 +20,7 @@ import os, re
 import gbp.log
 from gbp.command_wrappers import Command
 from gbp.pkg import compressor_opts
-from gbp.deb import UpstreamSource
+from gbp.deb import DebianPkgPolicy
 
 class PristineTar(Command):
     """The pristine-tar branch in a git repository"""
@@ -91,10 +91,10 @@ class PristineTar(Command):
         @param output_dir: the directory to put the tarball into
         @type output_dir: C{str}
         """
-        name = UpstreamSource.build_tarball_name(package,
-                                                 version,
-                                                 comp_type,
-                                                 output_dir)
+        name = DebianPkgPolicy.build_tarball_name(package,
+                                                  version,
+                                                  comp_type,
+                                                  output_dir)
         self._checkout(name)
 
     def commit(self, archive, upstream):