def changes_file_suffix(dpkg_args): """ >>> changes_file_suffix(['-A']) 'all' >>> changes_file_suffix(['-S']) 'source' >>> changes_file_suffix([]) == du.get_arch() True """ if '-S' in dpkg_args: return 'source' elif '-A' in dpkg_args: return 'all' else: return os.getenv('ARCH', None) or du.get_arch()
def changes_file_suffix(builder, dpkg_args): """ >>> changes_file_suffix('debuild', ['-A']) 'all' >>> changes_file_suffix('debuild', ['-S']) 'source' >>> changes_file_suffix('debuild -A', ['-uc', '-us']) 'all' >>> changes_file_suffix('debuild -S', ['-uc', '-us']) 'source' >>> changes_file_suffix('debuild', []) == du.get_arch() True """ args = shlex.split(builder) + dpkg_args if '-S' in args: return 'source' elif '-A' in args: return 'all' else: return os.getenv('ARCH', None) or du.get_arch()
def main(argv): retval = 0 prefix = "git-" cp = None branch = None options, gbp_args, dpkg_args = parse_args(argv, prefix) if not options: return 1 try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 else: repo_dir = os.path.abspath(os.path.curdir) try: Command(options.cleaner, shell=True)() if not options.ignore_new: (ret, out) = repo.is_clean() if not ret: gbp.log.err("You have uncommitted changes in your source tree:") gbp.log.err(out) raise GbpError("Use --git-ignore-new to ignore.") try: branch = repo.get_branch() except GitRepositoryError: # Not being on any branch is o.k. with --git-ignore-branch if not options.ignore_branch: raise if not options.ignore_new and not options.ignore_branch: if branch != options.debian_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch)) raise GbpError("Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name.") tree = write_tree(repo, options) cp = fetch_changelog(repo, options, tree) if not options.tag_only: output_dir = prepare_output_dir(options.export_dir) tarball_dir = options.tarball_dir or output_dir # Get/build the upstream tarball if necessary. We delay this in # case of a postexport hook so the hook gets a chance to modify the # sources and create different tarballs (#640382) # We don't delay it in general since we want to fail early if the # tarball is missing. if not cp.is_native(): if options.postexport: gbp.log.info("Postexport hook set, delaying tarball creation") else: prepare_upstream_tarball(repo, cp, options, tarball_dir, output_dir) # Export to another build dir if requested: if options.export_dir: tmp_dir = os.path.join(output_dir, "%s-tmp" % cp['Source']) export_source(repo, tree, cp, options, tmp_dir, output_dir) # Run postexport hook if options.postexport: RunAtCommand(options.postexport, shell=True, extra_env={'GBP_GIT_DIR': repo.git_dir, 'GBP_TMP_DIR': tmp_dir})(dir=tmp_dir) major = (cp.debian_version if cp.is_native() else cp.upstream_version) export_dir = os.path.join(output_dir, "%s-%s" % (cp['Source'], major)) gbp.log.info("Moving '%s' to '%s'" % (tmp_dir, export_dir)) move_old_export(export_dir) os.rename(tmp_dir, export_dir) # Delayed tarball creation in case a postexport hook is used: if not cp.is_native() and options.postexport: prepare_upstream_tarball(repo, cp, options, tarball_dir, output_dir) if options.export_dir: build_dir = export_dir else: build_dir = repo_dir if options.prebuild: RunAtCommand(options.prebuild, shell=True, extra_env={'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': build_dir})(dir=build_dir) setup_pbuilder(options) # Finally build the package: RunAtCommand(options.builder, dpkg_args, shell=True, extra_env={'GBP_BUILD_DIR': build_dir})(dir=build_dir) if options.postbuild: arch = os.getenv('ARCH', None) or du.get_arch() changes = os.path.abspath("%s/../%s_%s_%s.changes" % (build_dir, cp['Source'], cp.noepoch, arch)) gbp.log.debug("Looking for changes file %s" % changes) if not os.path.exists(changes): changes = os.path.abspath("%s/../%s_%s_source.changes" % (build_dir, cp['Source'], cp.noepoch)) Command(options.postbuild, shell=True, extra_env={'GBP_CHANGES_FILE': changes, 'GBP_BUILD_DIR': build_dir})() if options.tag or options.tag_only: gbp.log.info("Tagging %s" % cp.version) tag = repo.version_to_tag(options.debian_tag, cp.version) if options.retag and repo.has_tag(tag): repo.delete_tag(tag) repo.create_tag(name=tag, msg="Debian release %s" % cp.version, sign=options.sign_tags, keyid=options.keyid) if options.posttag: sha = repo.rev_parse("%s^{}" % tag) Command(options.posttag, shell=True, extra_env={'GBP_TAG': tag, 'GBP_BRANCH': branch or '(no branch)', 'GBP_SHA1': sha})() except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 finally: drop_index() if not options.tag_only: if options.export_dir and options.purge and not retval: RemoveTree(export_dir)() if cp and not gbp.notifications.notify(cp, not retval, options.notify): gbp.log.err("Failed to send notification") retval = 1 return retval