aboutsummaryrefslogtreecommitdiff
path: root/gbp/deb.py
diff options
context:
space:
mode:
Diffstat (limited to 'gbp/deb.py')
-rw-r--r--gbp/deb.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/gbp/deb.py b/gbp/deb.py
index df3e25e..b682b93 100644
--- a/gbp/deb.py
+++ b/gbp/deb.py
@@ -272,6 +272,47 @@ def do_uscan():
return (True, None)
return (True, tarball)
+def remove_toplevel(dest_dir):
+ """remove leading directory of a tar archive"""
+ # Check if tarball extracts into a single folder or not:
+ tar_topdir = tar_toplevel(dest_dir)
+ if tar_topdir != dest_dir:
+ # If it extracts a single folder, move all of its contents to dest_dir:
+ r = glob.glob("%s/*" % tar_topdir)
+ r.extend(glob.glob("%s/.*" % tar_topdir)) # include hidden files and folders
+ for f in r:
+ os.rename(f, os.path.join(dest_dir, os.path.basename(f)))
+
+ # Remove that single folder:
+ os.rmdir(tar_topdir)
+
+def extract_orig(orig_tarball, dest_dir, filter):
+ """extract orig tarball to export dir before exporting from git"""
+ print "Extracting %s to '%s'" % (os.path.basename(orig_tarball), dest_dir)
+
+ # move_old_export(dest_dir) was pushed up to the caller because we need to
+ # be able to extract an orig_tarball without side effects
+
+ # Make sure the destination dir exists and is empty
+ gbpc.RemoveTree(dest_dir)()
+ os.mkdir(dest_dir)
+
+ # unpack the main tarball
+ unpack_orig(orig_tarball, dest_dir, filter)
+
+ # make sure to remove the top level folder if there is only one
+ remove_toplevel(dest_dir)
+
+ # eventually unpack the additional tarballs
+ src_dir = os.path.dirname(orig_tarball)
+ for c, f in orig_components(orig_tarball, os.listdir(src_dir)).iteritems():
+ component_dir = os.path.join(dest_dir, c)
+ print "Extracting %s to '%s'" % (f, component_dir)
+ gbpc.RemoveTree(component_dir)()
+ os.mkdir(component_dir)
+ unpack_orig(os.path.join(src_dir, f), component_dir, filter)
+ remove_toplevel(component_dir)
+
def unpack_orig(archive, tmpdir, filters):
"""
unpack a .orig.tar.gz to tmpdir, leave the cleanup to the caller in case of