From cf48b03984e0dffec3b72447436f15d043794873 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Guido=20G=C3=BCnther?= Date: Mon, 5 Nov 2012 20:39:24 +0100 Subject: [PATCH] Allow to remove the orig tarball symlink that's used make pristine-tar see the correct orig tarball name. Closes: #692401 --- gbp/config.py | 5 +++++ gbp/scripts/common/import_orig.py | 1 - gbp/scripts/import_orig.py | 41 ++++++++++++++++++++++++++++----------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/gbp/config.py b/gbp/config.py index 6d8fcfe..7f269d4 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -129,6 +129,7 @@ class GbpOptionParser(OptionParser): 'template-dir': '', 'remote-config': '', 'allow-unauthenticated': 'False', + 'symlink-orig': 'True', } help = { 'debian-branch': @@ -252,6 +253,10 @@ class GbpOptionParser(OptionParser): 'allow-unauthenticated': ("Don't verify integrity of downloaded source, " "default is '%(allow-unauthenticated)s'"), + 'symlink-orig': + ("Whether to creat a symlink from the upstream tarball " + "to the orig.tar.gz if needed, default is " + "'%(symlink-orig)s'") } def_config_files = [ '/etc/git-buildpackage/gbp.conf', diff --git a/gbp/scripts/common/import_orig.py b/gbp/scripts/common/import_orig.py index 4381b96..a884573 100644 --- a/gbp/scripts/common/import_orig.py +++ b/gbp/scripts/common/import_orig.py @@ -21,7 +21,6 @@ import os import tempfile import gbp.command_wrappers as gbpc from gbp.pkg import UpstreamSource -from gbp.errors import GbpError import gbp.log class OrigUpstreamSource(UpstreamSource): diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 6db790c..046f47d 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -20,7 +20,6 @@ import ConfigParser import os import sys -import re import tempfile import gbp.command_wrappers as gbpc from gbp.deb import (DebianPkgPolicy, parse_changelog_repo) @@ -32,8 +31,7 @@ from gbp.errors import (GbpError, GbpNothingImported) import gbp.log from gbp.scripts.common.import_orig import (OrigUpstreamSource, cleanup_tmp_tree, ask_package_name, ask_package_version, - repacked_tarball_name, repack_source, - is_link_target) + repack_source, is_link_target) # Try to import readline, since that will cause raw_input to get fancy # line editing and history capabilities. However, if readline is not @@ -44,30 +42,43 @@ except ImportError: pass -def symlink_orig(archive, pkg, version): +def prepare_pristine_tar(archive, pkg, version): """ - Create a symlink from I{archive} ti I{_.orig.tar.} so - pristine-tar will see the correct basename. - - @return: archive path to be used by pristine tar + Prepare the upstream source for pristine tar import. + + This checks if the upstream source is actually a tarball + and creates a symlink from I{archive} + to I{_.orig.tar.} so pristine-tar will + see the correct basename. + + @param archive: the upstream source's name + @type archive: C{str} + @param pkg: the source package's name + @type pkg: C{str} + @param version: the upstream version number + @type version: C{str} @rtype: C{str} """ + linked = False if os.path.isdir(archive): return None + ext = os.path.splitext(archive)[1] if ext in ['.tgz', '.tbz2', '.tlz', '.txz' ]: ext = ".%s" % ext[2:] link = "../%s_%s.orig.tar%s" % (pkg, version, ext) + if os.path.basename(archive) != os.path.basename(link): try: if not is_link_target(archive, link): os.symlink(os.path.abspath(archive), link) + linked = True except OSError as err: raise GbpError("Cannot symlink '%s' to '%s': %s" % (archive, link, err[1])) - return link + return (link, linked) else: - return archive + return (archive, linked) def upstream_import_commit_msg(options, version): @@ -207,6 +218,8 @@ def parse_args(argv): dest="filter_pristine_tar") import_group.add_config_file_option(option_name="import-msg", dest="import_msg") + import_group.add_boolean_config_file_option(option_name="symlink-orig", + dest="symlink_orig") cmd_group.add_config_file_option(option_name="postimport", dest="postimport") parser.add_boolean_config_file_option(option_name="interactive", @@ -234,6 +247,7 @@ def main(argv): ret = 0 tmpdir = '' pristine_orig = None + linked = False (options, args) = parse_args(argv) try: @@ -273,7 +287,9 @@ def main(argv): gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked)) (source, tmpdir) = repack_source(source, sourcepackage, version, tmpdir, options.filters) - pristine_orig = symlink_orig(source.path, sourcepackage, version) + (pristine_orig, linked) = prepare_pristine_tar(source.path, + sourcepackage, + version) # Don't mess up our repo with git metadata from an upstream tarball try: @@ -353,6 +369,9 @@ def main(argv): gbp.log.err(err) ret = 1 + if pristine_orig and linked and not options.symlink_orig: + os.unlink(pristine_orig) + if tmpdir: cleanup_tmp_tree(tmpdir) -- 2.7.4