def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level, comp_opts, format='tar'): """ Create a source tree archive with submodules. Concatenates the archives generated by git-archive into one and compresses the end result. Exception handling is left to the caller. """ prefix = sanitize_prefix(prefix) tempdir = tempfile.mkdtemp() main_archive = os.path.join(tempdir, "main.%s" % format) submodule_archive = os.path.join(tempdir, "submodule.%s" % format) try: # generate main (tmp) archive repo.archive(format=format, prefix=prefix, output=main_archive, treeish=treeish) # generate each submodule's archive 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=format, prefix='%s%s/' % (prefix, tarpath), output=submodule_archive, treeish=commit, cwd=subdir) if format == 'tar': CatenateTarArchive(main_archive)(submodule_archive) elif format == 'zip': CatenateZipArchive(main_archive)(submodule_archive) # compress the output if comp_type: # Redirect through stdout directly to the correct output file in # order to avoid determining the output filename of the compressor try: comp_level_opt = '-%d' % comp_level if comp_level is not None else '' except TypeError: raise GbpError("Invalid compression level '%s'" % comp_level) ret = os.system( "%s --stdout %s %s %s > %s" % (comp_type, comp_level_opt, comp_opts, main_archive, output)) if ret: raise GbpError("Error creating %s: %d" % (output, ret)) else: shutil.move(main_archive, output) finally: shutil.rmtree(tempdir)
def _archive_comp_submodules(self, treeish, output, prefix, comp, format='tar'): """ Create a compressed source tree archive with submodules. Concatenates the archives generated by git-archive into one and compresses the end result. Exception handling is left to the caller. """ prefix = self.sanitize_prefix(prefix) tempdir = tempfile.mkdtemp() main_archive = os.path.join(tempdir, "main.%s" % format) submodule_archive = os.path.join(tempdir, "submodule.%s" % format) try: # generate main (tmp) archive self.archive(format=format, prefix=prefix, output=main_archive, treeish=treeish) # generate each submodule's archive and append it to the main archive for (subdir, commit) in self.get_submodules(treeish): tarpath = [subdir, subdir[2:]][subdir.startswith("./")] gbp.log.debug("Processing submodule %s (%s)" % (subdir, commit[0:8])) self.archive(format=format, prefix='%s%s/' % (prefix, tarpath), output=submodule_archive, treeish=commit, cwd=subdir) if format == 'tar': CatenateTarArchive(main_archive)(submodule_archive) elif format == 'zip': CatenateZipArchive(main_archive)(submodule_archive) # compress the output if comp and comp.type: # Redirect through stdout directly to the correct output file in # order to avoid determining the output filename of the compressor ret = os.system("%s %s > %s" % (comp.cmdline(), main_archive, output)) if ret: raise GitRepositoryError("Error creating %s: %d" % (output, ret)) else: shutil.move(main_archive, output) finally: shutil.rmtree(tempdir)
def git_archive_submodules(repo, treeish, output, tmpdir_base, prefix, comp_type, comp_level, comp_opts, format='tar'): """ Create a source tree 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. """ prefix = sanitize_prefix(prefix) tempdir = tempfile.mkdtemp(dir=tmpdir_base, prefix='git-archive_') main_archive = os.path.join(tempdir, "main.%s" % format) submodule_archive = os.path.join(tempdir, "submodule.%s" % format) try: # generate main (tmp) archive repo.archive(format=format, prefix=prefix, output=main_archive, treeish=treeish) # generate each submodule's arhive and append it to the main archive for (subdir, commit) in repo.get_submodules(treeish): tarpath = [subdir, subdir[2:]][subdir.startswith("./")] subrepo = GitRepository(os.path.join(repo.path, subdir)) gbp.log.debug("Processing submodule %s (%s)" % (subdir, commit[0:8])) subrepo.archive(format=format, prefix='%s%s/' % (prefix, tarpath), output=submodule_archive, treeish=commit) if format == 'tar': CatenateTarArchive(main_archive)(submodule_archive) elif format == 'zip': CatenateZipArchive(main_archive)(submodule_archive) # compress the output if comp_type: compress(comp_type, ['--stdout', '-%s' % comp_level] + comp_opts + [main_archive], output) else: shutil.move(main_archive, output) finally: shutil.rmtree(tempdir)
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. """ prefix = sanitize_prefix(prefix) 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=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)