def unpack_tarballs(sourcepackage, source, version, component_tarballs, options): tmpdir = tempfile.mkdtemp(dir='../') if not source.is_dir(): # Unpack main tarball source.unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked)) if orig_needs_repack(source, options): gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked)) (source, tmpdir) = repack_upstream(source, sourcepackage, version, tmpdir, options.filters) if not source.is_dir(): # Unpack component tarballs for (component, tarball) in component_tarballs: unpack_component_tarball(source.unpacked, component, tarball, options.filters) return (source, tmpdir)
def unpack_tarballs(name, sources, version, options): tmpdir = tempfile.mkdtemp(dir='../') if not sources[0].is_dir(): # Unpack main tarball sources[0].unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (sources[0].path, sources[0].unpacked)) if orig_needs_repack(sources[0], options): gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (sources[0].path, sources[0].unpacked)) # FIXME: we should repack the other tarballs here too (See #860457) # for that we better move around sources instead of source[0] (source, tmpdir) = repack_upstream(sources[0], name, version, tmpdir, options.filters) sources[0] = source if not sources[0].is_dir(): # Unpack component tarballs for s in sources[1:]: s.unpack(sources[0].unpacked, options.filters) return (sources, tmpdir)
def unpack_tarballs(repo, name, sources, version, options): tmpdir = tempfile.mkdtemp(dir='../') if not sources[0].is_dir(): # Unpack main tarball sources[0].unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (sources[0].path, sources[0].unpacked)) try: postunpack_hook(repo, tmpdir, sources, options) except gbpc.CommandExecFailed: raise GbpError() # The hook already printed an error message if orig_needs_repack(sources[0], options): gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (sources[0].path, sources[0].unpacked)) # FIXME: we should repack the other tarballs here too (See #860457) # for that we better move around sources instead of source[0] (source, tmpdir) = repack_upstream(sources[0], name, version, tmpdir, options.filters) sources[0] = source if not sources[0].is_dir(): # Unpack component tarballs for s in sources[1:]: s.unpack(sources[0].unpacked, options.filters) return (sources, tmpdir)
def main(argv): ret = 0 tmpdir = '' pristine_orig = None linked = False (options, args) = parse_args(argv) if not options: return 1 try: source = find_source(options.uscan, args) if not source: return ret try: repo = DebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) # an empty repo has now branches: initial_branch = repo.get_branch() is_empty = False if initial_branch else True if not repo.has_branch(options.upstream_branch) and not is_empty: raise GbpError(no_upstream_branch_msg % options.upstream_branch) (sourcepackage, version) = detect_name_and_version(repo, source, options) (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err("Repository has uncommitted changes, commit these first: ") raise GbpError(out) if repo.bare: set_bare_repo_options(options) if not source.is_dir(): tmpdir = tempfile.mkdtemp(dir='../') source.unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked)) if orig_needs_repack(source, options): 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, linked) = prepare_pristine_tar(source.path, sourcepackage, version) # Don't mess up our repo with git metadata from an upstream tarball try: if os.path.isdir(os.path.join(source.unpacked, '.git/')): raise GbpError("The orig tarball contains .git metadata - giving up.") except OSError: pass try: upstream_branch = [ options.upstream_branch, 'master' ][is_empty] filter_msg = ["", " (filtering out %s)" % options.filters][len(options.filters) > 0] gbp.log.info("Importing '%s' to branch '%s'%s..." % (source.path, upstream_branch, filter_msg)) gbp.log.info("Source package is %s" % sourcepackage) gbp.log.info("Upstream version is %s" % version) import_branch = [ options.upstream_branch, None ][is_empty] msg = upstream_import_commit_msg(options, version) if options.vcs_tag: parents = [repo.rev_parse("%s^{}" % options.vcs_tag)] else: parents = None commit = repo.commit_dir(source.unpacked, msg=msg, branch=import_branch, other_parents=parents, ) if options.pristine_tar: if pristine_orig: repo.pristine_tar.commit(pristine_orig, upstream_branch) else: gbp.log.warn("'%s' not an archive, skipping pristine-tar" % source.path) tag = repo.version_to_tag(options.upstream_tag, version) repo.create_tag(name=tag, msg="Upstream version %s" % version, commit=commit, sign=options.sign_tags, keyid=options.keyid) if is_empty: repo.create_branch(options.upstream_branch, rev=commit) repo.force_head(options.upstream_branch, hard=True) elif options.merge: gbp.log.info("Merging to '%s'" % options.debian_branch) repo.set_branch(options.debian_branch) try: repo.merge(tag) except GitRepositoryError: raise GbpError("Merge failed, please resolve.") if options.postimport: epoch = '' if os.access('debian/changelog', os.R_OK): # No need to check the changelog file from the # repository, since we're certain that we're on # the debian-branch cp = ChangeLog(filename='debian/changelog') if cp.has_epoch(): epoch = '%s:' % cp.epoch info = { 'version': "%s%s-1" % (epoch, version) } env = { 'GBP_BRANCH': options.debian_branch } gbpc.Command(format_msg(options.postimport, info), extra_env=env, shell=True)() # Update working copy and index if we've possibly updated the # checked out branch current_branch = repo.get_branch() if current_branch in [ options.upstream_branch, repo.pristine_tar_branch]: repo.force_head(current_branch, hard=True) except (gbpc.CommandExecFailed, GitRepositoryError) as err: msg = err.__str__() if len(err.__str__()) else '' raise GbpError("Import of %s failed: %s" % (source.path, msg)) except GbpError as err: if len(err.__str__()): 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) if not ret: gbp.log.info("Successfully imported version %s of %s" % (version, source.path)) return ret
def main(argv): ret = 0 tmpdir = '' pristine_orig = None linked = False repo = None (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error try: try: repo = ImportOrigDebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) is_empty = repo.is_empty() if not repo.has_branch(options.upstream_branch) and not is_empty: raise GbpError(no_upstream_branch_msg % options.upstream_branch) (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err("Repository has uncommitted changes, commit these first: ") raise GbpError(out) # Download the main tarball if options.download: source = download_orig(args[0]) else: source = find_source(options.uscan, args) if not source: return ExitCodes.failed # The main tarball (sourcepackage, version) = detect_name_and_version(repo, source, options) # Additionl tarballs we expect to exist component_tarballs = get_component_tarballs(sourcepackage, version, source.path, options.components) tag = repo.version_to_tag(options.upstream_tag, version) if repo.has_tag(tag): raise GbpError("Upstream tag '%s' already exists" % tag) if repo.bare: set_bare_repo_options(options) if not source.is_dir(): # Unpack main tarball tmpdir = tempfile.mkdtemp(dir='../') source.unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked)) if orig_needs_repack(source, options): gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked)) (source, tmpdir) = repack_source(source, sourcepackage, version, tmpdir, options.filters) if not source.is_dir(): # Unpack component tarballs for (component, tarball) in component_tarballs: unpack_component_tarball(source.unpacked, component, tarball, options.filters) (pristine_orig, linked) = prepare_pristine_tar(source.path, sourcepackage, version) # Don't mess up our repo with git metadata from an upstream tarball try: if os.path.isdir(os.path.join(source.unpacked, '.git/')): raise GbpError("The orig tarball contains .git metadata - giving up.") except OSError: pass try: import_branch = options.upstream_branch filter_msg = ["", " (filtering out %s)" % options.filters][len(options.filters) > 0] gbp.log.info("Importing '%s' to branch '%s'%s..." % (source.path, import_branch, filter_msg)) gbp.log.info("Source package is %s" % sourcepackage) gbp.log.info("Upstream version is %s" % version) msg = upstream_import_commit_msg(options, version) commit = repo.commit_dir(source.unpacked, msg=msg, branch=import_branch, other_parents=repo.vcs_tag_parent(options.vcs_tag, version), create_missing_branch=is_empty, ) if options.pristine_tar: if pristine_orig: repo.rrr_branch('pristine-tar') repo.create_pristinetar_commits(import_branch, pristine_orig, component_tarballs) else: gbp.log.warn("'%s' not an archive, skipping pristine-tar" % source.path) repo.create_tag(name=tag, msg="Upstream version %s" % version, commit=commit, sign=options.sign_tags, keyid=options.keyid) if is_empty: repo.create_branch(branch=options.debian_branch, rev=commit) repo.force_head(options.debian_branch, hard=True) elif options.merge: repo.rrr_branch(options.debian_branch) debian_branch_merge(repo, tag, version, options) # Update working copy and index if we've possibly updated the # checked out branch current_branch = repo.get_branch() if current_branch in [options.upstream_branch, repo.pristine_tar_branch]: repo.force_head(current_branch, hard=True) except (gbpc.CommandExecFailed, GitRepositoryError) as err: msg = str(err) or 'Unknown error, please report a bug' raise GbpError("Import of %s failed: %s" % (source.path, msg)) except GbpError as err: if str(err): gbp.log.err(err) ret = 1 if repo and repo.has_rollbacks() and options.rollback: gbp.log.err("Error detected, Will roll back changes.") try: repo.rollback() # Make sure the very last line as an error message gbp.log.err("Rolled back changes after import error.") except Exception as e: gbp.log.err("%s" % e) gbp.log.err("Clean up manually and please report a bug: %s" % repo.rollback_errors) if pristine_orig and linked and not options.symlink_orig: os.unlink(pristine_orig) if tmpdir: cleanup_tmp_tree(tmpdir) if not ret: gbp.log.info("Successfully imported version %s of %s" % (version, source.path)) return ret
def main(argv): ret = 0 tmpdir = '' pristine_orig = None linked = False (options, args) = parse_args(argv) if not options: return 1 try: if options.download: source = download_orig(args[0]) else: source = find_source(options.uscan, args) if not source: return ret try: repo = DebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) # an empty repo has now branches: initial_branch = repo.get_branch() is_empty = False if initial_branch else True if not repo.has_branch(options.upstream_branch) and not is_empty: raise GbpError(no_upstream_branch_msg % options.upstream_branch) (sourcepackage, version) = detect_name_and_version(repo, source, options) (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err( "Repository has uncommitted changes, commit these first: ") raise GbpError(out) if repo.bare: set_bare_repo_options(options) if not source.is_dir(): tmpdir = tempfile.mkdtemp(dir='../') source.unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked)) if orig_needs_repack(source, options): 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, linked) = prepare_pristine_tar(source.path, sourcepackage, version) # Don't mess up our repo with git metadata from an upstream tarball try: if os.path.isdir(os.path.join(source.unpacked, '.git/')): raise GbpError( "The orig tarball contains .git metadata - giving up.") except OSError: pass try: upstream_branch = [options.upstream_branch, 'master'][is_empty] filter_msg = ["", " (filtering out %s)" % options.filters ][len(options.filters) > 0] gbp.log.info("Importing '%s' to branch '%s'%s..." % (source.path, upstream_branch, filter_msg)) gbp.log.info("Source package is %s" % sourcepackage) gbp.log.info("Upstream version is %s" % version) import_branch = [options.upstream_branch, None][is_empty] msg = upstream_import_commit_msg(options, version) if options.vcs_tag: parents = [ repo.rev_parse( "%s^{}" % repo.version_to_tag(options.vcs_tag, version)) ] else: parents = None commit = repo.commit_dir( source.unpacked, msg=msg, branch=import_branch, other_parents=parents, ) if options.pristine_tar: if pristine_orig: repo.pristine_tar.commit(pristine_orig, upstream_branch) else: gbp.log.warn("'%s' not an archive, skipping pristine-tar" % source.path) tag = repo.version_to_tag(options.upstream_tag, version) repo.create_tag(name=tag, msg="Upstream version %s" % version, commit=commit, sign=options.sign_tags, keyid=options.keyid) if is_empty: repo.create_branch(options.upstream_branch, rev=commit) repo.force_head(options.upstream_branch, hard=True) elif options.merge: gbp.log.info("Merging to '%s'" % options.debian_branch) repo.set_branch(options.debian_branch) try: repo.merge(tag) except GitRepositoryError: raise GbpError("Merge failed, please resolve.") if options.postimport: epoch = '' if os.access('debian/changelog', os.R_OK): # No need to check the changelog file from the # repository, since we're certain that we're on # the debian-branch cp = ChangeLog(filename='debian/changelog') if cp.has_epoch(): epoch = '%s:' % cp.epoch info = {'version': "%s%s-1" % (epoch, version)} env = {'GBP_BRANCH': options.debian_branch} gbpc.Command(format_str(options.postimport, info), extra_env=env, shell=True)() # Update working copy and index if we've possibly updated the # checked out branch current_branch = repo.get_branch() if current_branch in [ options.upstream_branch, repo.pristine_tar_branch ]: repo.force_head(current_branch, hard=True) except (gbpc.CommandExecFailed, GitRepositoryError) as err: msg = str(err) or 'Unknown error, please report a bug' raise GbpError("Import of %s failed: %s" % (source.path, msg)) except GbpError as err: if str(err): 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) if not ret: gbp.log.info("Successfully imported version %s of %s" % (version, source.path)) return ret
def main(argv): ret = 0 tmpdir = "" pristine_orig = None linked = False (options, args) = parse_args(argv) if not options: return 1 try: try: repo = DebianGitRepository(".") except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath("."))) # an empty repo has now branches: initial_branch = repo.get_branch() is_empty = False if initial_branch else True if not repo.has_branch(options.upstream_branch) and not is_empty: raise GbpError(no_upstream_branch_msg % options.upstream_branch) (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err("Repository has uncommitted changes, commit these first: ") raise GbpError(out) # Download the source if options.download: source = download_orig(args[0]) else: source = find_source(options.uscan, args) if not source: return ret (sourcepackage, version) = detect_name_and_version(repo, source, options) tag = repo.version_to_tag(options.upstream_tag, version) if repo.has_tag(tag): raise GbpError("Upstream tag '%s' already exists" % tag) if repo.bare: set_bare_repo_options(options) if not source.is_dir(): tmpdir = tempfile.mkdtemp(dir="../") source.unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked)) if orig_needs_repack(source, options): 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, linked) = prepare_pristine_tar(source.path, sourcepackage, version) # Don't mess up our repo with git metadata from an upstream tarball try: if os.path.isdir(os.path.join(source.unpacked, ".git/")): raise GbpError("The orig tarball contains .git metadata - giving up.") except OSError: pass try: upstream_branch = [options.upstream_branch, "master"][is_empty] filter_msg = ["", " (filtering out %s)" % options.filters][len(options.filters) > 0] gbp.log.info("Importing '%s' to branch '%s'%s..." % (source.path, upstream_branch, filter_msg)) gbp.log.info("Source package is %s" % sourcepackage) gbp.log.info("Upstream version is %s" % version) import_branch = [options.upstream_branch, None][is_empty] msg = upstream_import_commit_msg(options, version) if options.vcs_tag: parents = [repo.rev_parse("%s^{}" % repo.version_to_tag(options.vcs_tag, version))] else: parents = None commit = repo.commit_dir(source.unpacked, msg=msg, branch=import_branch, other_parents=parents) if options.pristine_tar: if pristine_orig: repo.pristine_tar.commit(pristine_orig, upstream_branch) else: gbp.log.warn("'%s' not an archive, skipping pristine-tar" % source.path) repo.create_tag( name=tag, msg="Upstream version %s" % version, commit=commit, sign=options.sign_tags, keyid=options.keyid, ) if is_empty: repo.create_branch(options.upstream_branch, rev=commit) repo.force_head(options.upstream_branch, hard=True) if options.debian_branch != "master": repo.rename_branch("master", options.debian_branch) elif options.merge: debian_branch_merge(repo, tag, version, options) # Update working copy and index if we've possibly updated the # checked out branch current_branch = repo.get_branch() if current_branch in [options.upstream_branch, repo.pristine_tar_branch]: repo.force_head(current_branch, hard=True) except (gbpc.CommandExecFailed, GitRepositoryError) as err: msg = str(err) or "Unknown error, please report a bug" raise GbpError("Import of %s failed: %s" % (source.path, msg)) except GbpError as err: if str(err): 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) if not ret: gbp.log.info("Successfully imported version %s of %s" % (version, source.path)) return ret
def main(argv): ret = 0 tmpdir = '' pristine_orig = None linked = False repo = None (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error try: try: repo = ImportOrigDebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) is_empty = repo.is_empty() if not repo.has_branch(options.upstream_branch) and not is_empty: raise GbpError(no_upstream_branch_msg % options.upstream_branch) (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err( "Repository has uncommitted changes, commit these first: ") raise GbpError(out) # Download the main tarball if options.download: source = download_orig(args[0]) else: source = find_source(options.uscan, args) if not source: return ExitCodes.failed # The main tarball (sourcepackage, version) = detect_name_and_version(repo, source, options) # Additionl tarballs we expect to exist component_tarballs = get_component_tarballs(sourcepackage, version, source.path, options.components) tag = repo.version_to_tag(options.upstream_tag, version) if repo.has_tag(tag): raise GbpError("Upstream tag '%s' already exists" % tag) if repo.bare: set_bare_repo_options(options) if not source.is_dir(): # Unpack main tarball tmpdir = tempfile.mkdtemp(dir='../') source.unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked)) if orig_needs_repack(source, options): gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked)) (source, tmpdir) = repack_source(source, sourcepackage, version, tmpdir, options.filters) if not source.is_dir(): # Unpack component tarballs for (component, tarball) in component_tarballs: unpack_component_tarball(source.unpacked, component, tarball, options.filters) (pristine_orig, linked) = prepare_pristine_tar(source.path, sourcepackage, version) # Don't mess up our repo with git metadata from an upstream tarball try: if os.path.isdir(os.path.join(source.unpacked, '.git/')): raise GbpError( "The orig tarball contains .git metadata - giving up.") except OSError: pass try: import_branch = options.upstream_branch filter_msg = ["", " (filtering out %s)" % options.filters ][len(options.filters) > 0] gbp.log.info("Importing '%s' to branch '%s'%s..." % (source.path, import_branch, filter_msg)) gbp.log.info("Source package is %s" % sourcepackage) gbp.log.info("Upstream version is %s" % version) msg = upstream_import_commit_msg(options, version) commit = repo.commit_dir( source.unpacked, msg=msg, branch=import_branch, other_parents=repo.vcs_tag_parent(options.vcs_tag, version), create_missing_branch=is_empty, ) if options.pristine_tar: if pristine_orig: repo.rrr_branch('pristine-tar') repo.create_pristinetar_commits(import_branch, pristine_orig, component_tarballs) else: gbp.log.warn("'%s' not an archive, skipping pristine-tar" % source.path) repo.create_tag(name=tag, msg="Upstream version %s" % version, commit=commit, sign=options.sign_tags, keyid=options.keyid) if is_empty: repo.create_branch(branch=options.debian_branch, rev=commit) repo.force_head(options.debian_branch, hard=True) elif options.merge: repo.rrr_branch(options.debian_branch) debian_branch_merge(repo, tag, version, options) # Update working copy and index if we've possibly updated the # checked out branch current_branch = repo.get_branch() if current_branch in [ options.upstream_branch, repo.pristine_tar_branch ]: repo.force_head(current_branch, hard=True) except (gbpc.CommandExecFailed, GitRepositoryError) as err: msg = str(err) or 'Unknown error, please report a bug' raise GbpError("Import of %s failed: %s" % (source.path, msg)) except GbpError as err: if str(err): gbp.log.err(err) ret = 1 if repo and repo.has_rollbacks() and options.rollback: gbp.log.err("Error detected, Will roll back changes.") try: repo.rollback() # Make sure the very last line as an error message gbp.log.err("Rolled back changes after import error.") except Exception as e: gbp.log.err("%s" % e) gbp.log.err("Clean up manually and please report a bug: %s" % repo.rollback_errors) if pristine_orig and linked and not options.symlink_orig: os.unlink(pristine_orig) if tmpdir: cleanup_tmp_tree(tmpdir) if not ret: gbp.log.info("Successfully imported version %s of %s" % (version, source.path)) return ret