summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-11-22 22:51:21 +0100
committerGuido Günther <agx@sigxcpu.org>2011-11-22 22:51:21 +0100
commita2a13ed17be28e3654c697acacdde1bc88ed7df8 (patch)
treeda37d777502606905a99449cc5f9096f8c7d3b26
parentd2c103390ac8377438519b1afd48a9cc7bdf89d5 (diff)
buildpackage: move export of source tree into separate function
-rw-r--r--gbp/scripts/buildpackage.py60
1 files changed, 36 insertions, 24 deletions
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py
index c6dccbcc..96567f93 100644
--- a/gbp/scripts/buildpackage.py
+++ b/gbp/scripts/buildpackage.py
@@ -150,6 +150,39 @@ def prepare_upstream_tarball(repo, cp, options, tarball_dir, output_dir):
git_archive_build_orig(repo, cp, output_dir, options)
+def export_source(repo, cp, options, dest_dir, tarball_dir):
+ """
+ Export a verion of the source tree when building in a separate directory
+
+ @param repo: the git repository to export from
+ @type repo: L{gbp.git.GitRepository}
+ @param cp: the package's changelog
+ @param options: options to apply
+ @param dest_dir: where to export the source to
+ @param tarball_dir: where to fetch the tarball form in overlay mode
+ @returns: the temporary directory
+ """
+ # write a tree of the index if necessary:
+ if options.export == index_name:
+ tree = repo.write_tree()
+ elif options.export == wc_name:
+ tree = write_wc(repo)
+ else:
+ tree = options.export
+ if not repo.has_treeish(tree):
+ raise GbpError # git-ls-tree printed an error message already
+
+ # Extract orig tarball if git-overlay option is selected:
+ if options.overlay:
+ if du.is_native(cp):
+ raise GbpError, "Cannot overlay Debian native package"
+ extract_orig(os.path.join(tarball_dir, du.orig_file(cp, options.comp_type)), dest_dir)
+
+ gbp.log.info("Exporting '%s' to '%s'" % (options.export, dest_dir))
+ if not dump_tree(repo, dest_dir, tree, options.with_submodules):
+ raise GbpError
+
+
def dump_tree(repo, export_dir, treeish, with_submodules):
"dump a tree to output_dir"
output_dir = os.path.dirname(export_dir)
@@ -201,8 +234,8 @@ def move_old_export(target):
if e == errno.EEXIST:
os.rename(target, "%s.obsolete.%s" % (target, time.time()))
-
def prepare_output_dir(dir):
+ """Prepare the directory where the build result will be put"""
output_dir = dir
if not dir:
output_dir = '..'
@@ -483,10 +516,7 @@ def main(argv):
if not options.tag_only:
output_dir = prepare_output_dir(options.export_dir)
- if options.tarball_dir:
- tarball_dir = options.tarball_dir
- else:
- tarball_dir = output_dir
+ tarball_dir = options.tarball_dir or output_dir
# Get/build the upstream tarball if necessary. We delay this in
# case of a postexport so the hook gets chance to modify the
@@ -502,26 +532,8 @@ def main(argv):
# Export to another build dir if requested:
if options.export_dir:
- # write a tree of the index if necessary:
- if options.export == index_name:
- tree = repo.write_tree()
- elif options.export == wc_name:
- tree = write_wc(repo)
- else:
- tree = options.export
- if not repo.has_treeish(tree):
- raise GbpError # git-ls-tree printed an error message already
tmp_dir = os.path.join(output_dir, "%s-tmp" % cp['Source'])
-
- # Extract orig tarball if git-overlay option is selected:
- if options.overlay:
- if du.is_native(cp):
- raise GbpError, "Cannot overlay Debian native package"
- extract_orig(os.path.join(output_dir, du.orig_file(cp, options.comp_type)), tmp_dir)
-
- gbp.log.info("Exporting '%s' to '%s'" % (options.export, tmp_dir))
- if not dump_tree(repo, tmp_dir, tree, options.with_submodules):
- raise GbpError
+ export_source(repo, cp, options, tmp_dir, output_dir)
# Run postexport hook
if options.postexport: