Introduce PkgPolicy.is_valid_orig_archive()
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 9 Jul 2012 13:10:37 +0000 (16:10 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:22:07 +0000 (14:22 +0200)
A new method for checking if the given filename is usable as a orig
(upstream) source archive.

Also, takes this method into use in the UpstreamSource class.

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

index ad47162..e80e94b 100644 (file)
@@ -131,6 +131,14 @@ class PkgPolicy(object):
             raise NotImplementedError("Class needs to provide upstreamversion_re")
         return True if cls.upstreamversion_re.match(version) else False
 
+    @classmethod
+    def is_valid_orig_archive(cls, filename):
+        "Is this a valid orig source archive"
+        (base, arch_fmt, compression) =  parse_archive_filename(filename)
+        if arch_fmt == 'tar' and compression:
+            return True
+        return False
+
     @staticmethod
     def guess_upstream_src_version(filename, extra_regex=r''):
         """
@@ -264,16 +272,7 @@ class UpstreamSource(object):
             self._orig = False
             return
 
-        parts = self._path.split('.')
-        try:
-            if parts[-1] == 'tgz':
-                self._orig = True
-            elif parts[-2] == 'tar':
-                if (parts[-1] in compressor_opts or
-                    parts[-1] in compressor_aliases):
-                        self._orig = True
-        except IndexError:
-            self._orig = False
+        self._orig = self._pkg_policy.is_valid_orig_archive(os.path.basename(self.path))
 
     def is_orig(self):
         """