diff options
Diffstat (limited to 'gbp/scripts/buildpackage.py')
-rwxr-xr-x | gbp/scripts/buildpackage.py | 121 |
1 files changed, 5 insertions, 116 deletions
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index 3fd6917..7e3ea1e 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -20,15 +20,13 @@ import ConfigParser import errno import os, os.path -import pipes import sys -import time import tempfile import shutil import gbp.deb as du from gbp.command_wrappers import (Command, RunAtCommand, CommandExecFailed, - RemoveTree, CatenateTarArchive) + RemoveTree) from gbp.config import (GbpOptionParserDebian, GbpOptionGroup) from gbp.deb.git import (GitRepositoryError, DebianGitRepository) from gbp.deb.changelog import ChangeLog, NoChangeLogError, ParseChangeLogError @@ -36,63 +34,10 @@ from gbp.errors import GbpError from glob import glob import gbp.log import gbp.notifications - -# when we want to reference the index in a treeish context we call it: -index_name = "INDEX" -# when we want to reference the working copy in treeish context we call it: -wc_name = "WC" -# index file name used to export working copy -wc_index = ".git/gbp_index" - - -def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level, comp_opts): - """ - Create tar.gz of an archive with submodules - - since git-archive always writes an end of tarfile trailer we concatenate - the generated archives using tar and compress the result. - - Exception handling is left to the caller. - """ - - tarfile = output.rsplit('.', 1)[0] - tempdir = tempfile.mkdtemp() - submodule_tarfile = os.path.join(tempdir, "submodule.tar") - try: - # generate main tarfile - repo.archive(format='tar', prefix='%s/' % (prefix), - output=tarfile, treeish=treeish) - - # generate each submodule's tarfile and append it to the main archive - for (subdir, commit) in repo.get_submodules(treeish): - tarpath = [subdir, subdir[2:]][subdir.startswith("./")] - - gbp.log.debug("Processing submodule %s (%s)" % (subdir, commit[0:8])) - repo.archive(format='tar', prefix='%s/%s/' % (prefix, tarpath), - output=submodule_tarfile, treeish=commit, cwd=subdir) - CatenateTarArchive(tarfile)(submodule_tarfile) - - # compress the output - ret = os.system("%s -%s %s %s" % (comp_type, comp_level, comp_opts, tarfile)) - if ret: - raise GbpError("Error creating %s: %d" % (output, ret)) - finally: - shutil.rmtree(tempdir) - - -def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts): - """ - Create tar.gz of an archive without submodules - - Exception handling is left to the caller. - """ - pipe = pipes.Template() - pipe.prepend("git archive --format=tar --prefix=%s/ %s" % (prefix, treeish), '.-') - pipe.append('%s -c -%s %s' % (comp_type, comp_level, comp_opts), '--') - ret = pipe.copy('', output) - if ret: - raise GbpError("Error creating %s: %d" % (output, ret)) - +from gbp.scripts.common.buildpackage import (index_name, wc_name, + git_archive_submodules, + git_archive_single, dump_tree, + write_wc, drop_index) def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level, with_submodules): "create a compressed orig tarball in output_dir using git_archive" @@ -209,49 +154,6 @@ def export_source(repo, tree, cp, options, dest_dir, tarball_dir): raise GbpError -def dump_tree(repo, export_dir, treeish, with_submodules): - "dump a tree to output_dir" - output_dir = os.path.dirname(export_dir) - prefix = os.path.basename(export_dir) - - pipe = pipes.Template() - pipe.prepend('git archive --format=tar --prefix=%s/ %s' % (prefix, treeish), '.-') - pipe.append('tar -C %s -xf -' % output_dir, '-.') - top = os.path.abspath(os.path.curdir) - try: - ret = pipe.copy('', '') - if ret: - raise GbpError, "Error in dump_tree archive pipe" - - if with_submodules: - if repo.has_submodules(): - repo.update_submodules() - for (subdir, commit) in repo.get_submodules(treeish): - gbp.log.info("Processing submodule %s (%s)" % (subdir, commit[0:8])) - tarpath = [subdir, subdir[2:]][subdir.startswith("./")] - os.chdir(subdir) - pipe = pipes.Template() - pipe.prepend('git archive --format=tar --prefix=%s/%s/ %s' % - (prefix, tarpath, commit), '.-') - pipe.append('tar -C %s -xf -' % output_dir, '-.') - ret = pipe.copy('', '') - os.chdir(top) - if ret: - raise GbpError, "Error in dump_tree archive pipe in submodule %s" % subdir - except OSError, err: - gbp.log.err("Error dumping tree to %s: %s" % (output_dir, err[0])) - return False - except GbpError, err: - gbp.log.err(err) - return False - except Exception as e: - gbp.log.err("Error dumping tree to %s: %s" % (output_dir, e)) - return False - finally: - os.chdir(top) - return True - - def move_old_export(target): """move a build tree away if it exists""" try: @@ -261,19 +163,6 @@ def move_old_export(target): os.rename(target, "%s.obsolete.%s" % (target, time.time())) -def write_wc(repo): - """write out the current working copy as a treeish object""" - repo.add_files(repo.path, force=True, index_file=wc_index) - tree = repo.write_tree(index_file=wc_index) - return tree - - -def drop_index(): - """drop our custom index""" - if os.path.exists(wc_index): - os.unlink(wc_index) - - def extract_orig(orig_tarball, dest_dir): """extract orig tarball to export dir before exporting from git""" gbp.log.info("Extracting %s to '%s'" % (os.path.basename(orig_tarball), dest_dir)) |