pq-rpm: support importing compressed patches
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 7 Jun 2012 16:13:43 +0000 (19:13 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:45:07 +0000 (14:45 +0200)
Adds support for importing compressed patches.

NOTE: Only gzip is supported, for the time being, other compression
methods shouldn't be to hard to add, if needed.

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

index b6ded2c..480e382 100755 (executable)
@@ -25,6 +25,7 @@ import shutil
 import sys
 import tempfile
 import re
+import gzip
 from gbp.config import (GbpOptionParserRpm, GbpOptionGroup)
 from gbp.rpm.git import (GitRepositoryError, RpmGitRepository)
 from gbp.git import GitModifier
@@ -33,6 +34,7 @@ from gbp.command_wrappers import (Command, GitCommand, RunAtCommand,
 from gbp.errors import GbpError
 import gbp.log
 from gbp.patch_series import (PatchSeries, Patch)
+from gbp.pkg import parse_archive_filename
 from gbp.rpm import (SpecFile, guess_spec)
 from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base,
                                    parse_gbp_commands, format_patch,
@@ -160,7 +162,7 @@ def export_patches(repo, branch, options):
 def safe_patches(queue, tmpdir_base):
     """
     Safe the current patches in a temporary directory
-    below 'tmpdir_base'
+    below 'tmpdir_base'. Also, uncompress compressed patches here.
 
     @param queue: an existing patch queue
     @param tmpdir_base: base under which to create tmpdir
@@ -174,10 +176,24 @@ def safe_patches(queue, tmpdir_base):
     if len(queue) > 0:
         gbp.log.debug("Safeing patches '%s' in '%s'" % (os.path.dirname(queue[0].path), tmpdir))
         for p in queue:
-            dst = os.path.join(tmpdir, os.path.basename(p.path))
-            shutil.copy(p.path, dst)
+            (base, archive_fmt, comp) = parse_archive_filename(p.path)
+            if comp == 'gzip':
+                gbp.log.debug("Uncompressing '%s'" % os.path.basename(p.path))
+                src = gzip.open(p.path, 'r')
+                dst_name = os.path.join(tmpdir, os.path.basename(base))
+            elif comp:
+                raise GbpError, ("Unsupported compression of a patch, giving up")
+            else:
+                src = open(p.path, 'r')
+                dst_name = os.path.join(tmpdir, os.path.basename(p.path))
+
+            dst = open(dst_name, 'w')
+            dst.writelines(src)
+            src.close()
+            dst.close()
+
             safequeue.append(p)
-            safequeue[-1].path = dst;
+            safequeue[-1].path = dst_name;
 
     return (tmpdir, safequeue)