UpstreamSource.unpack: return UpstreamSource instance
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 6 Jun 2013 12:19:37 +0000 (15:19 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:22:08 +0000 (14:22 +0200)
Trying to keep UpstreamSource in consistent state so that unpacked and
packed sources are kept in sync.

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

index 2029ec5..9c54c86 100644 (file)
@@ -467,19 +467,27 @@ class UpstreamSource(object):
         if type(filters) != type([]):
             raise GbpError("Filters must be a list")
 
-        self._unpack_archive(dir, filters)
+        if self._unpack_archive(dir, filters):
+            ret = type(self)(dir, prefix=self._prefix)
+        else:
+            ret = self
         src_dir = os.path.join(dir, self._prefix)
-        self.unpacked = src_dir if os.path.isdir(src_dir) else dir
+        ret.unpacked = src_dir if os.path.isdir(src_dir) else dir
+        return ret
 
     def _unpack_archive(self, dir, filters):
         """
-        Unpack packed upstream sources into a given directory.
+        Unpack packed upstream sources into a given directory. Return True if
+        the output was filtered, otherwise False.
         """
         ext = os.path.splitext(self.path)[1]
         if ext in [ ".zip", ".xpi" ]:
             self._unpack_zip(dir)
         else:
             self._unpack_tar(dir, filters)
+            if filters:
+                return True
+        return False
 
     def _unpack_zip(self, dir):
         try:
index 80807a6..f110216 100644 (file)
@@ -114,6 +114,6 @@ def repack_source(source, new_name, unpack_dir, filters, new_prefix=None):
     if source.is_tarball(): # the tarball was filtered on unpack
         repacked.unpacked = source.unpacked
     else: # otherwise unpack the generated tarball get a filtered tree
-        repacked.unpack(unpack_dir, filters)
+        repacked.unpack(unpack_dir)
     return repacked
 
index c0bf650..f1416d9 100644 (file)
@@ -329,7 +329,7 @@ def main(argv):
 
             dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
             upstream = DebianUpstreamSource(src.tgz)
-            upstream.unpack(dirs['tmp'], options.filters)
+            upstream = upstream.unpack(dirs['tmp'], options.filters)
 
             format = [(options.upstream_tag, "Upstream"), (options.debian_tag, "Debian")][src.native]
             tag = repo.version_to_tag(format[0], src.upstream_version)
index 1a81816..9ca203c 100644 (file)
@@ -306,7 +306,7 @@ def main(argv):
 
         if not source.is_dir():
             unpack_dir = tempfile.mkdtemp(prefix='unpack', dir=tmpdir)
-            source.unpack(unpack_dir, options.filters)
+            source = source.unpack(unpack_dir, options.filters)
             gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked))
 
         if orig_needs_repack(source, options):
index 472b801..a04e107 100755 (executable)
@@ -300,7 +300,7 @@ def main(argv):
         if spec.orig_src:
             orig_tarball = os.path.join(dirs['src'], spec.orig_src['filename'])
             sources = RpmUpstreamSource(orig_tarball)
-            sources.unpack(dirs['origsrc'], options.filters)
+            sources = sources.unpack(dirs['origsrc'], options.filters)
         else:
             sources = None