UpstreamSource: add 'archive_fmt' and 'compression' properties
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 9 Jul 2012 14:16:21 +0000 (17:16 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:22:07 +0000 (14:22 +0200)
New properties for easily getting the archive format (tar, zip, ...) and
compression format (gzip, bzip2, ...) of the sources.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/pkg/__init__.py

index e80e94b..8c79938 100644 (file)
@@ -254,6 +254,9 @@ class UpstreamSource(object):
         self._pkg_policy = pkg_policy
         self._path = name
         self.unpacked = unpacked
+        self._filename_base, \
+        self._archive_fmt, \
+        self._compression = parse_archive_filename(os.path.basename(self.path))
 
         self._check_orig()
         if self.is_dir():
@@ -294,6 +297,28 @@ class UpstreamSource(object):
     def path(self):
         return self._path.rstrip('/')
 
+    @property
+    def archive_fmt(self):
+        """
+        >>> UpstreamSource('foo/bar.tar.gz').archive_fmt
+        'tar'
+        >>> UpstreamSource('foo.bar.zip').archive_fmt
+        'zip'
+        >>> UpstreamSource('foo.bar.baz').archive_fmt
+        """
+        return self._archive_fmt
+
+    @property
+    def compression(self):
+        """
+        >>> UpstreamSource('foo/bar.tar.gz').compression
+        'gzip'
+        >>> UpstreamSource('foo.bar.zip').compression
+        >>> UpstreamSource('foo.bz2').compression
+        'bzip2'
+        """
+        return self._compression
+
     def unpack(self, dir, filters=[]):
         """
         Unpack packed upstream sources into a given directory