def export_vcs_tree(tree, directory, subpath=""): try: export(tree, directory, "dir", None, subdir=(subpath or None)) except OSError as e: if e.errno == errno.ENOSPC: raise DetailedFailure(1, ["export"], NoSpaceOnDevice()) raise
def prepare_symlink_export(self): self.requireFeature(features.SymlinkFeature) work_a = self.make_branch_and_tree('wta') os.symlink('target', 'wta/link') work_a.add('link') work_a.commit('add link') tree_a = self.workingtree_to_test_tree(work_a) export(tree_a, 'output', self.exporter)
def prepare_export(self): work_a = self.make_branch_and_tree('wta') self.build_tree_contents([('wta/file', b'a\nb\nc\nd\n'), ('wta/dir', b'')]) work_a.add('file') work_a.add('dir') work_a.commit('add file') tree_a = self.workingtree_to_test_tree(work_a) export(tree_a, 'output', self.exporter)
def make_upstream_version(self, version, contents, pristine_tar_format=None): upstream = self.make_branch_and_tree("upstream") self.build_tree_contents(contents) upstream.smart_add([upstream.basedir]) revprops = {} if pristine_tar_format is not None: _mod_export.export(upstream, "export") if pristine_tar_format == "gz": tarfile_path = "export.tar.gz" _mod_export.export(upstream, tarfile_path, "tgz") revprops["deb-pristine-delta"] = standard_b64encode( make_pristine_tar_delta("export", "export.tar.gz")) elif pristine_tar_format == "bz2": tarfile_path = "export.tar.bz2" _mod_export.export(upstream, tarfile_path, "tbz2") revprops["deb-pristine-delta-bz2"] = standard_b64encode( make_pristine_tar_delta("export", "export.tar.bz2")) else: raise AssertionError("unknown pristine tar format %s" % pristine_tar_format) else: tarfile_path = "export.tar.gz" _mod_export.export(upstream, tarfile_path, "tgz") tarfile_sha1 = osutils.sha_file_by_name(tarfile_path) revid = upstream.commit("import upstream %s" % version, revprops=revprops) source = Branch.open("source") source.repository.fetch(upstream.branch.repository) source.tags.set_tag("upstream-%s" % version, revid) return tarfile_sha1
def prepare_nested_export(self, recurse_nested): tree = self.make_branch_and_tree('dir') self.build_tree(['dir/a']) tree.add('a') tree.commit('1') subtree = self.make_branch_and_tree('dir/subdir') self.build_tree(['dir/subdir/b']) subtree.add('b') subtree.commit('1a') try: tree.add_reference(subtree) except UnsupportedOperation: raise TestNotApplicable('format does not supported nested trees') tree.commit('2') export(tree, 'output', self.exporter, recurse_nested=recurse_nested)
def extract_upstream_tarball(branch, package, version, dest_dir): """Extract the upstream tarball from a branch. :param branch: Branch with the upstream pristine tar data :param package: Package name :param version: Package version :param dest_dir: Destination directory """ tag_names = ["upstream-%s" % version, "upstream/%s" % version] for tag_name in tag_names: try: revid = branch.tags.lookup_tag(tag_name) except errors.NoSuchTag: pass else: break else: raise errors.NoSuchTag(tag_names[0]) tree = branch.repository.revision_tree(revid) rev = branch.repository.get_revision(revid) if 'deb-pristine-delta' in rev.properties: uuencoded = rev.properties['deb-pristine-delta'] dest_filename = "%s_%s.orig.tar.gz" % (package, version) elif 'deb-pristine-delta-bz2' in rev.properties: uuencoded = rev.properties['deb-pristine-delta-bz2'] dest_filename = "%s_%s.orig.tar.bz2" % (package, version) else: uuencoded = None if uuencoded is not None: delta = standard_b64decode(uuencoded) dest = os.path.join(dest_dir, "orig") try: _mod_export.export(tree, dest, format='dir') reconstruct_pristine_tar(dest, delta, os.path.join(dest_dir, dest_filename)) finally: if os.path.exists(dest): shutil.rmtree(dest) else: # Default to .tar.gz dest_filename = "%s_%s.orig.tar.gz" % (package, version) _mod_export.export(tree, os.path.join(dest_dir, dest_filename), per_file_timestamps=True)
subdir = package else: packaging_tree = None subdir = None try: ret = create_dist_schroot( tree, subdir=subdir, target_dir=os.path.abspath(args.target_directory), packaging_tree=packaging_tree, chroot=args.chroot, include_controldir=args.include_controldir, ) except NoBuildToolsFound: logging.info("No build tools found, falling back to simple export.") export(tree, "dist.tar.gz", "tgz", None) except NotImplementedError: logging.info("Build system does not support dist tarball creation, " "falling back to simple export.") export(tree, "dist.tar.gz", "tgz", None) except UnidentifiedError as e: logging.fatal("Unidentified error: %r", e.lines) except DetailedFailure as e: logging.fatal("Identified error during dist creation: %s", e.error) except DistNoTarball: logging.fatal("dist operation did not create a tarball") else: logging.info("Created %s", ret) sys.exit(0)