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>
Tue, 3 Mar 2015 08:07:46 +0000 (10:07 +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 0512df7ab136a6eed7bbad2bdae30945ccc256ae..567d5c2d5489f70b3b141f690bb9ca720beb060e 100644 (file)
@@ -469,19 +469,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 abcecc49c68ff94236f24e86786e8c2457a2dec5..000522293b05274419724ade42d7b5e266d5278d 100644 (file)
@@ -117,7 +117,7 @@ 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 1fb8413e47f9ee431652cd0ced2c467aa8866ffa..38cf9995adacbeb69c2f8553b39d1ad1f8910ea6 100644 (file)
@@ -330,7 +330,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 d6715dfbaa8d14bd3d2dcd10d90a5b4fd2bcfc7d..687b430a2ba2a279935f2b71a36faf5890f4f1da 100644 (file)
@@ -334,7 +334,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 a9e2ee76abe18d7d9d286d5e3f12e92907e5a866..c7a866d20b253df78a8e614ffbfe229603edd501 100755 (executable)
@@ -309,7 +309,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