From 3763ee4e3f0a3160da0c531d534b07c186a74cc0 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Thu, 14 Jun 2012 19:30:26 +0300 Subject: [PATCH] UpstreamSource.pack: support prefix mangling Add support for changing the prefix directory inside the tarball that is generated. Also, fixes a bug that caused a "prefix-less" tarball to get one, if unpacked and then repacked. Also, adds this support to repack_source() in common/import_orig. Signed-off-by: Markus Lehtonen Conflicts: gbp/pkg/__init__.py gbp/scripts/common/import_orig.py --- gbp/pkg/__init__.py | 11 +++++++++++ gbp/scripts/common/import_orig.py | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/gbp/pkg/__init__.py b/gbp/pkg/__init__.py index 9c54c86..0b20a9c 100644 --- a/gbp/pkg/__init__.py +++ b/gbp/pkg/__init__.py @@ -495,6 +495,17 @@ class UpstreamSource(object): except gbpc.CommandExecFailed: raise GbpError("Unpacking of %s failed" % self.path) + def _unpacked_toplevel(self, dir): + """unpacked archives can contain a leading directory or not""" + unpacked = glob.glob('%s/*' % dir) + unpacked.extend(glob.glob("%s/.*" % dir)) # include hidden files and folders + # Check that dir contains nothing but a single folder: + if len(unpacked) == 1 and os.path.isdir(unpacked[0]): + return unpacked[0] + else: + # We can determine "no prefix" from this + return os.path.join(dir, ".") + def _unpack_tar(self, dir, filters): """ Unpack a tarball to I{dir} applying a list of I{filters}. Leave the diff --git a/gbp/scripts/common/import_orig.py b/gbp/scripts/common/import_orig.py index 3d01f9e..576c7e5 100644 --- a/gbp/scripts/common/import_orig.py +++ b/gbp/scripts/common/import_orig.py @@ -222,4 +222,12 @@ def prepare_sources(source, pkg_name, pkg_version, pristine_commit_name, tmpdir) pristine_path = pristine.path if pristine else '' return (filtered.unpacked, pristine_path) +def repack_source(source, new_name, unpack_dir, filters, new_prefix=None): + """Repack the source tree""" + repacked = source.pack(new_name, filters, new_prefix) + if source.is_orig(): # 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) + return repacked -- 2.7.4