diff options
-rw-r--r-- | gbp/command_wrappers.py | 13 | ||||
-rw-r--r-- | gbp/pkg/__init__.py | 24 | ||||
-rw-r--r-- | gbp/scripts/common/import_orig.py | 4 | ||||
-rw-r--r-- | tests/06_test_upstream_source.py | 9 |
4 files changed, 39 insertions, 11 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py index f1312e4c..0d29af17 100644 --- a/gbp/command_wrappers.py +++ b/gbp/command_wrappers.py @@ -169,7 +169,8 @@ class UnpackTarArchive(Command): class PackTarArchive(Command): """Wrap tar to pack a compressed tar archive""" - def __init__(self, archive, dir, dest, filters=[], compression=None): + def __init__(self, archive, dir, dest, filters=[], compression=None, + transform=None): self.archive = archive self.dir = dir exclude = [("--exclude=%s" % _filter) for _filter in filters] @@ -177,8 +178,14 @@ class PackTarArchive(Command): if not compression: compression = '-a' - Command.__init__(self, 'tar', exclude + - ['-C', dir, compression, '-cf', archive, dest]) + args = exclude + ['-C', dir, compression, '-cf', archive ] + + if transform != None: + args.append('--transform=%s' % transform) + + args.append(dest) + + Command.__init__(self, 'tar', args) self.run_error = 'Couldn\'t repack "%s"' % self.archive diff --git a/gbp/pkg/__init__.py b/gbp/pkg/__init__.py index fbca005d..ad471629 100644 --- a/gbp/pkg/__init__.py +++ b/gbp/pkg/__init__.py @@ -336,7 +336,8 @@ class UpstreamSource(object): if len(unpacked) == 1 and os.path.isdir(unpacked[0]): return unpacked[0] else: - return dir + # We can determine "no prefix" from this + return os.path.join(dir, ".") def _unpack_tar(self, dir, filters): """ @@ -350,7 +351,7 @@ class UpstreamSource(object): # unpackArchive already printed an error message raise GbpError - def pack(self, newarchive, filters=[]): + def pack(self, newarchive, filters=[], newprefix=None): """ Recreate a new archive from the current one @@ -358,6 +359,8 @@ class UpstreamSource(object): @type newarchive: string @param filters: tar filters to apply @type filters: array of strings + @param newprefix: new prefix, None implies that prefix is not mangled + @type newprefix: string or None @return: the new upstream source @rtype: UpstreamSource """ @@ -370,12 +373,21 @@ class UpstreamSource(object): if type(filters) != type([]): raise GbpError("Filters must be a list") + run_dir = os.path.dirname(self.unpacked.rstrip('/')) + pack_this = os.path.basename(self.unpacked.rstrip('/')) + transform = None + if newprefix is not None: + newprefix = newprefix.strip('/.') + if newprefix: + transform = 's!%s!%s!' % (pack_this, newprefix) + else: + transform = 's!%s!%s!' % (pack_this, '.') try: - unpacked = self.unpacked.rstrip('/') repackArchive = gbpc.PackTarArchive(newarchive, - os.path.dirname(unpacked), - os.path.basename(unpacked), - filters) + run_dir, + pack_this, + filters, + transform=transform) repackArchive() except gbpc.CommandExecFailed: # repackArchive already printed an error diff --git a/gbp/scripts/common/import_orig.py b/gbp/scripts/common/import_orig.py index 349ec595..d2490b39 100644 --- a/gbp/scripts/common/import_orig.py +++ b/gbp/scripts/common/import_orig.py @@ -108,9 +108,9 @@ def ask_package_version(default, ver_validator_func, err_msg): gbp.log.warn("\nNot a valid upstream version: '%s'.\n%s" % (version, err_msg)) -def repack_source(source, new_name, unpack_dir, filters): +def repack_source(source, new_name, unpack_dir, filters, new_prefix=None): """Repack the source tree""" - repacked = source.pack(new_name, filters) + 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 diff --git a/tests/06_test_upstream_source.py b/tests/06_test_upstream_source.py index 34787bf4..ac210a03 100644 --- a/tests/06_test_upstream_source.py +++ b/tests/06_test_upstream_source.py @@ -72,6 +72,15 @@ class TestTar(unittest.TestCase): self._check_tar(repacked, ["gbp/errors.py"], ["gbp/__init__.py"]) + def test_pack_mangle_prefix(self): + """Check if mangling prefix works""" + source = UpstreamSource(os.path.abspath("gbp/")) + target = self.tmpdir.join("gbp_0.1.tar.bz2") + repacked = source.pack(target, newprefix="foobar") + self._check_tar(repacked, ["foobar/errors.py", "foobar/__init__.py"]) + repacked2 = source.pack(target, newprefix="") + self._check_tar(repacked2, ["./errors.py", "./__init__.py"]) + class TestZip(unittest.TestCase): """Test if unpacking zip archives works""" |