def main(args): """gbs submit entry point.""" workdir = args.gitdir orphan_packaging = configmgr.get('packaging_branch', 'orphan-devel') if orphan_packaging and args.commit == 'HEAD': log.error("You seem to be submitting a development branch of an " "(orphan) packaging branch. Please export your changes to" "the packaging branch with 'gbs devel export' and submit" "from there.") raise GbsError("Refusing to submit from devel branch") message = args.msg if message is None: message = get_message() if not message: raise GbsError("tag message is required") try: repo = RpmGitRepository(workdir) commit = repo.rev_parse(args.commit) current_branch = repo.get_branch() except GitRepositoryError, err: raise GbsError(str(err))
def main(args): """gbs submit entry point.""" workdir = args.gitdir orphan_packaging = configmgr.get('packaging_branch', 'orphan-devel') if orphan_packaging and args.commit == 'HEAD': log.error( "You seem to be submitting a development branch of an " "(orphan) packaging branch. Please export your changes to the " "packaging branch with 'gbs devel export' and submit from there.") raise GbsError("Refusing to submit from devel branch") message = args.msg if message is None: message = get_message() if not message: raise GbsError("tag message is required") try: repo = RpmGitRepository(workdir) commit = repo.rev_parse(args.commit) current_branch = repo.get_branch() except GitRepositoryError, err: raise GbsError(str(err))
def main(argv): """Script main function""" options, args = parse_args(argv) if not options: return ExitCodes.parse_error try: init_tmpdir(options.tmp_dir, prefix='rpm-ch_') load_customizations(options.customization_file) editor_cmd = determine_editor(options) repo = RpmGitRepository('.') check_branch(repo, options) # Find and parse spec file spec = parse_spec_file(repo, options) # Find and parse changelog file ch_file = parse_changelog_file(repo, spec, options) since = get_start_commit(ch_file.changelog, repo, options) # Get range of commits from where to generate changes if args: gbp.log.info("Only looking for changes in '%s'" % ", ".join(args)) commits = repo.get_commits(since=since, until='HEAD', paths=args, options=options.git_log.split(" ")) commits.reverse() if not commits: gbp.log.info("No changes detected from %s to %s." % (since, 'HEAD')) # Do the actual update entries = entries_from_commits(ch_file.changelog, repo, commits, options) update_changelog(ch_file.changelog, entries, repo, spec, options) # Write to file ch_file.write() if editor_cmd: gbpc.Command(editor_cmd, [ch_file.path])() except (GbpError, GitRepositoryError, ChangelogError, NoSpecError) as err: if len(err.__str__()): gbp.log.err(err) return 1 except KeyboardInterrupt: gbp.log.err("Interrupted. Aborting.") return 1 finally: del_tmpdir() return 0
def init_repo(path): """Check and initialize Git repository""" try: repo = RpmGitRepository(path) clean, out = repo.is_clean() if not clean and not repo.is_empty(): gbp.log.err("Repository has uncommitted changes, commit " "these first:") gbp.log.err(out) raise GbpError except GitRepositoryError: gbp.log.info("No git repository found, creating one in %s" % path) repo = RpmGitRepository.create(path) return repo
def main(argv): """Script main function""" options, args = parse_args(argv) if not options: return ExitCodes.parse_error try: init_tmpdir(options.tmp_dir, prefix='rpm-ch_') load_customizations(options.customization_file) editor_cmd = determine_editor(options) repo = RpmGitRepository('.') check_branch(repo, options) # Find and parse spec file spec = parse_spec_file(repo, options) # Find and parse changelog file ch_file = parse_changelog_file(repo, spec, options) since = get_start_commit(ch_file.changelog, repo, options) # Get range of commits from where to generate changes if args: gbp.log.info("Only looking for changes in '%s'" % ", ".join(args)) commits = repo.get_commits(since=since, until='HEAD', paths=args, options=options.git_log.split(" ")) commits.reverse() if not commits: gbp.log.info("No changes detected from %s to %s." % (since, 'HEAD')) # Do the actual update entries = entries_from_commits(ch_file.changelog, repo, commits, options) update_changelog(ch_file.changelog, entries, repo, spec, options) # Write to file ch_file.write() if editor_cmd: gbpc.Command(editor_cmd, [ch_file.path])() except (GbpError, GitRepositoryError, ChangelogError, NoSpecError) as err: if len(err.__str__()): gbp.log.err(err) return 1 finally: del_tmpdir() return 0
def main(argv): """Entry point for git-buildpackage-rpm""" retval = 0 prefix = "git-" spec = None options, gbp_args, builder_args = parse_args(argv, prefix) if not options: return 1 try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 # Determine tree-ish to be exported try: tree = get_tree(repo, options.export) except GbpError as err: gbp.log.err('Failed to determine export treeish: %s' % err) return 1 # Re-parse config options with using the per-tree config file(s) from the # exported tree-ish options, gbp_args, builder_args = parse_args(argv, prefix, tree) try: # Create base temporary directory for this run options.tmp_dir = tempfile.mkdtemp(dir=options.tmp_dir, prefix='buildpackage-rpm_') except GbpError, err: gbp.log.err(err) return 1
def main(args): """gbs devel entry point.""" try: repo = RpmGitRepository(args.gitdir) except GitRepositoryError, err: raise GbsError(str(err))
def main(args): """gbs remotebuild entry point.""" obsconf = get_profile(args).obs if not obsconf or not obsconf.url: raise GbsError('no obs api found, please add it to gbs conf ' 'and try again') apiurl = obsconf.url if not apiurl.user: raise GbsError('empty user is not allowed for remotebuild, please '\ 'add user/passwd to gbs conf, and try again') if args.commit and args.include_all: raise Usage('--commit can\'t be specified together with ' '--include-all') obs_repo = args.repository obs_arch = args.arch if args.buildlog and None in (obs_repo, obs_arch): raise GbsError('please specify arch(-A) and repository(-R)') try: repo = RpmGitRepository(args.gitdir) except GitRepositoryError, err: raise GbsError(str(err))
def main(argv): """Script main function""" options, args = parse_args(argv) if not options: return 1 try: load_customizations(options.customization_file) editor_cmd = determine_editor(options) repo = RpmGitRepository('.') check_repo_state(repo, options) # Find and parse spec file spec = parse_spec_file(repo, options) # Find and parse changelog file ch_file = parse_changelog_file(repo, spec, options) # Get new entries entries = generate_new_entries(ch_file.changelog, repo, options, args) # Do the actual update tag, author, committer = update_changelog(ch_file.changelog, entries, repo, spec, options) # Write to file ch_file.write() if editor_cmd and not options.message: gbpc.Command(editor_cmd, [ch_file.path])() if options.commit: edit = True if editor_cmd else False msg = create_commit_message(spec, options) commit_changelog(repo, ch_file, msg, author, committer, edit) if options.tag: if options.retag and repo.has_tag(tag): repo.delete_tag(tag) create_packaging_tag(repo, tag, 'HEAD', spec.version, options) except (GbpError, GitRepositoryError, ChangelogError, NoSpecError) as err: if len(err.__str__()): gbp.log.err(err) return 1 return 0
def main(args): """gbs submit entry point.""" workdir = args.gitdir message = args.msg if message is None: message = get_message() if not message: raise GbsError("tag message is required") try: repo = RpmGitRepository(workdir) commit = repo.rev_parse(args.commit) current_branch = repo.get_branch() except GitRepositoryError, err: raise GbsError(str(err))
def main(args): """gbs export entry point.""" if args.commit and args.include_all: raise Usage("--commit can't be specified together with --include-all") workdir = args.gitdir try: repo = RpmGitRepository(workdir) except GitRepositoryError, err: raise GbsError(str(err))
def __call__(self, parser, namespace, value, option_string=None): workdir = value if not os.path.exists(workdir): raise GbsError("specified package dir %s does not exist" \ % workdir) try: repo = RpmGitRepository(value) workdir = repo.path except GitRepositoryError: pass read_localconf(workdir) setattr(namespace, self.dest, value)
def main(argv): """Main function for the gbp pq-rpm command""" retval = 0 (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch", "convert"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: # Create base temporary directory for this run init_tmpdir(options.tmp_dir, prefix='pq-rpm_') current = repo.get_branch() if action == "export": export_patches(repo, options) elif action == "import": import_spec_patches(repo, options) elif action == "drop": drop_pq(repo, current) elif action == "rebase": rebase_pq(repo, options) elif action == "apply": patch = Patch(patchfile) apply_single_patch(repo, current, patch, fallback_author=None) elif action == "switch": switch_pq(repo, current) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpError as err: if str(err): gbp.log.err(err) retval = 1 finally: del_tmpdir() return retval
def main(args): """gbs build entry point.""" global TMPDIR TMPDIR = os.path.join(configmgr.get('tmpdir', 'general'), '%s-gbs' % USERID) if args.commit and args.include_all: raise Usage('--commit can\'t be specified together with '\ '--include-all') if args.noinit and (args.clean or args.clean_once): raise Usage('--noinit can\'t be specified together with '\ '--clean or --clean-once') workdir = args.gitdir try: repo = RpmGitRepository(workdir) workdir = repo.path except GitRepositoryError: if args.spec: raise GbsError("git project can't be found for --spec, " "give it in argument or cd into it") read_localconf(workdir) hostarch = os.uname()[4] if args.arch: buildarch = args.arch else: buildarch = hostarch log.info('No arch specified, using system arch: %s' % hostarch) if not buildarch in SUPPORTEDARCHS: raise GbsError('arch %s not supported, supported archs are: %s ' % \ (buildarch, ','.join(SUPPORTEDARCHS))) profile = get_profile(args) if args.buildroot: build_root = args.buildroot elif 'TIZEN_BUILD_ROOT' in os.environ: build_root = os.environ['TIZEN_BUILD_ROOT'] elif profile.buildroot: build_root = profile.buildroot else: build_root = configmgr.get('buildroot', 'general') build_root = os.path.expanduser(build_root) # transform variables from shell to python convention ${xxx} -> %(xxx)s build_root = re.sub(r'\$\{([^}]+)\}', r'%(\1)s', build_root) sanitized_profile_name = re.sub("[^a-zA-Z0-9:._-]", "_", profile.name) build_root = build_root % { 'tmpdir': TMPDIR, 'profile': sanitized_profile_name } if profile.exclude_packages: log.info('the following packages have been excluded build from gbs ' 'config:\n %s' % '\n '.join(profile.exclude_packages)) if args.exclude: args.exclude += ',' + ','.join(profile.exclude_packages) else: args.exclude = ','.join(profile.exclude_packages) os.environ['TIZEN_BUILD_ROOT'] = os.path.abspath(build_root) # get virtual env from system env first if 'VIRTUAL_ENV' in os.environ: cmd = ['%s/usr/bin/depanneur' % os.environ['VIRTUAL_ENV']] else: cmd = ['depanneur'] cmd += ['--arch=%s' % buildarch] if args.clean: cmd += ['--clean'] # check & prepare repos and build conf if not args.noinit: cmd += prepare_repos_and_build_conf(args, buildarch, profile) else: cmd += ['--noinit'] cmd += ['--path=%s' % workdir] if args.ccache: cmd += ['--ccache'] if args.extra_packs: cmd += ['--extra-packs=%s' % args.extra_packs] if hostarch != buildarch and buildarch in CHANGE_PERSONALITY: cmd = [CHANGE_PERSONALITY[buildarch]] + cmd # Extra depanneur special command options cmd += prepare_depanneur_opts(args) # Extra options for gbs export if args.include_all: cmd += ['--include-all'] if args.commit: cmd += ['--commit=%s' % args.commit] if args.upstream_branch: cmd += ['--upstream-branch=%s' % args.upstream_branch] if args.upstream_tag: cmd += ['--upstream-tag=%s' % args.upstream_tag] if args.squash_patches_until: cmd += ['--squash-patches-until=%s' % args.squash_patches_until] if args.no_patch_export: cmd += ['--no-patch-export'] if args.define: cmd += [('--define="%s"' % i) for i in args.define] if args.spec: cmd += ['--spec=%s' % args.spec] # Determine if we're on devel branch orphan_packaging = configmgr.get('packaging_branch', 'orphan-devel') if orphan_packaging: cmd += ['--spec-commit=%s' % orphan_packaging] log.debug("running command: %s" % ' '.join(cmd)) retcode = os.system(' '.join(cmd)) if retcode != 0: raise GbsError('some packages failed to be built') else: log.info('Done')
def main(argv): """Main function for the gbp pq-rpm command""" retval = 0 try: parser = GbpOptionParserRpm(command=os.path.basename(argv[0]), prefix='', usage=USAGE_STRING) except ConfigParser.ParsingError as err: gbp.log.err('Invalid config file: %s' % err) return 1 parser.add_boolean_config_file_option(option_name="patch-numbers", dest="patch_numbers") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose command execution") parser.add_option( "--force", dest="force", action="store_true", default=False, help="In case of import even import if the branch already exists") parser.add_config_file_option(option_name="vendor", action="store", dest="vendor") parser.add_config_file_option(option_name="color", dest="color", type='tristate') parser.add_config_file_option(option_name="color-scheme", dest="color_scheme") parser.add_config_file_option(option_name="tmp-dir", dest="tmp_dir") parser.add_config_file_option(option_name="upstream-tag", dest="upstream_tag") parser.add_config_file_option(option_name="spec-file", dest="spec_file") parser.add_config_file_option(option_name="packaging-dir", dest="packaging_dir") parser.add_option( "--new-packaging-dir", help="Packaging directory in the new packaging branch. Only " "relevant for the 'convert' action. If not defined, defaults " "to '--packaging-dir'") parser.add_config_file_option( option_name="packaging-branch", dest="packaging_branch", help="Branch the packaging is being maintained on. Only relevant " "if a invariable/single pq-branch is defined, in which case " "this is used as the 'base' branch. Default is " "'%(packaging-branch)s'") parser.add_config_file_option(option_name="pq-branch", dest="pq_branch") parser.add_config_file_option(option_name="import-files", dest="import_files", type="string", action="callback", callback=opt_split_cb) parser.add_option( "--retain-history", action="store_true", help="When doing convert, preserve as much of the git history as " "possible, i.e. create one commit per commit. Only " "relevant for the 'convert' action.") parser.add_option( "--export-rev", action="store", dest="export_rev", default="", help="Export patches from treeish object TREEISH instead of head " "of patch-queue branch", metavar="TREEISH") parser.add_config_file_option("patch-export-compress", dest="patch_export_compress") parser.add_config_file_option("patch-export-squash-until", dest="patch_export_squash_until") parser.add_config_file_option("patch-export-ignore-path", dest="patch_export_ignore_path") (options, args) = parser.parse_args(argv) gbp.log.setup(options.color, options.verbose, options.color_scheme) options.patch_export_compress = string_to_int( options.patch_export_compress) if options.new_packaging_dir is None: options.new_packaging_dir = options.packaging_dir if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch", "convert"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 if os.path.abspath('.') != repo.path: gbp.log.warn("Switching to topdir before running commands") os.chdir(repo.path) try: # Create base temporary directory for this run options.tmp_dir = tempfile.mkdtemp(dir=options.tmp_dir, prefix='gbp-pq-rpm_') if action == "export": export_patches(repo, options) elif action == "import": import_spec_patches(repo, options) elif action == "drop": drop_pq_rpm(repo, options) elif action == "rebase": rebase_pq(repo, options) elif action == "apply": apply_single_patch(repo, patchfile, options) elif action == "switch": switch_pq(repo, options) elif action == "convert": convert_package(repo, options) except CommandExecFailed: retval = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpError, err: if len(err.__str__()): gbp.log.err(err) retval = 1
def main(argv): """Entry point for git-buildpackage-bb""" retval = 0 prefix = "git-" bbfile = None dump_dir = None if not bb: return 1 options, gbp_args, builder_args = parse_args(argv, prefix) if not options: return 1 try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 # Determine tree-ish to be exported try: tree = get_tree(repo, options.export) except GbpError as err: gbp.log.err('Failed to determine export treeish: %s' % err) return 1 # Re-parse config options with using the per-tree config file(s) from the # exported tree-ish options, gbp_args, builder_args = parse_args(argv, prefix, tree) branch = get_current_branch(repo) try: tinfoil = init_tinfoil(config_only=True) #bb_cfg_data = bb.data.createCopy(tinfoil.config_data) except GbpError: tinfoil = None # Use naive parsing because repository might only have .bb file gbp.log.info("Using naive standalone parsing of recipes in package repo.") bb_cfg_data = None try: tree = guess_export_params(repo, options) Command(options.cleaner, shell=True)() if not options.ignore_new: (ret, out) = repo.is_clean(options.ignore_untracked) if not ret: gbp.log.err("You have uncommitted changes in your source tree:") gbp.log.err(out) raise GbpError("Use --git-ignore-new or --git-ignore-untracked " "to ignore.") if not options.ignore_new and not options.ignore_branch: if branch != options.packaging_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.packaging_branch, branch)) raise GbpError("Use --git-ignore-branch to ignore or " "--git-packaging-branch to set the branch name.") if not options.tag_only: # Dump/parse meta to export dir if options.export_dir: export_dir = os.path.abspath(options.export_dir) else: export_dir = guess_export_dir(options, tinfoil, repo, tree) gbp.log.info("Dumping meta from tree '%s' to '%s'" % (options.export, export_dir)) bbfile = dump_meta(bb_cfg_data, options, repo, tree, export_dir) # Setup builder opts setup_builder(options, builder_args) if is_native(repo, options) and bbfile.getVar('SRCREV') == 'HEAD': # Update SRCREV for native packages that are exported from # pristine repository BBFile.set_var_val(bbfile.bb_path, 'SRCREV', repo.rev_parse(tree)) # TODO: Re-design the handling of native packages. Updating # SRCREV must probably be more explicit if options.patch_export: # Generate patches, if requested if options.patch_export_rev: patch_tree = get_tree(repo, options.patch_export_rev) else: patch_tree = tree export_patches(repo, bbfile, patch_tree, options) # Run postexport hook if options.postexport: RunAtCommand(options.postexport, shell=True, extra_env={'GBP_GIT_DIR': repo.git_dir, 'GBP_TMP_DIR': export_dir} )(dir=export_dir) # Do actual build if not options.no_build: if options.prebuild: RunAtCommand(options.prebuild, shell=True, extra_env={'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': export_dir} )(dir=export_dir) # Unlock cooker so that we are able to run external bitbake if options.builder == 'bitbake' and tinfoil: bb.utils.unlockfile(tinfoil.cooker.lock) # Finally build the package: bb_path = bbfile.getVar('FILE', True) builder_args.extend(['-b', bb_path]) RunAtCommand(options.builder, builder_args, shell=True, extra_env={'GBP_BUILD_DIR': export_dir})() if options.postbuild: Command(options.postbuild, shell=True, extra_env={'GBP_BUILD_DIR': export_dir})() else: # Tag-only: we just need to parse the meta bbfile = parse_bb(bb_cfg_data, options, repo, tree) # Tag (note: tags the exported version) if options.tag or options.tag_only: version = pkg_version(bbfile) gbp.log.info("Tagging %s" % RpmPkgPolicy.compose_full_version(version)) commit_info = repo.get_commit_info(tree) tag = packaging_tag_name(repo, version, commit_info, options) if options.retag and repo.has_tag(tag): repo.delete_tag(tag) create_packaging_tag(repo, tag, commit=tree, version=version, options=options) vcs_info = get_vcs_info(repo, tag) if options.posttag: sha = repo.rev_parse("%s^{}" % tag) Command(options.posttag, shell=True, extra_env={'GBP_TAG': tag, 'GBP_BRANCH': branch, 'GBP_SHA1': sha})() else: vcs_info = get_vcs_info(repo, tree) # TODO: Put VCS information to recipe if options.bb_vcs_info: raise GbpError("Injecting VCS info into recipe not yet supported") except CommandExecFailed: retval = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpAutoGenerateError as err: if len(err.__str__()): gbp.log.err(err) retval = 2 except GbpError, err: if len(err.__str__()): gbp.log.err(err) retval = 1
def main(argv): ret = 0 (options, args) = parse_args(argv) if not options: return 1 tmpdir = tempfile.mkdtemp(dir=options.tmp_dir, prefix='import-orig-rpm_') try: try: repo = RpmGitRepository('.') except GitRepositoryError: raise GbpError, "%s is not a git repository" % ( os.path.abspath('.')) spec = find_spec(repo, options) source = find_source(spec, options, args) # 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): if options.create_missing_branches: gbp.log.info("Will create missing branch '%s'" % options.upstream_branch) elif is_empty: options.create_missing_branches = True else: raise GbpError(no_upstream_branch_msg % options.upstream_branch) sourcepackage, version = detect_name_and_version( repo, source, spec, 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) # Prepare sources for importing if options.pristine_tar: prepare_pristine = pristine_tarball_name( source, sourcepackage, version, options.pristine_tarball_name) else: prepare_pristine = None unpacked_orig, pristine_orig = \ prepare_sources(source, sourcepackage, version, prepare_pristine, options.filters, options.filter_pristine_tar, options.orig_prefix, tmpdir) # Don't mess up our repo with git metadata from an upstream tarball if os.path.isdir(os.path.join(unpacked_orig, '.git/')): raise GbpError("The orig tarball contains .git metadata - " "giving up.") try: filter_msg = ["", " (filtering out %s)" % options.filters ][len(options.filters) > 0] gbp.log.info("Importing '%s' to branch '%s'%s..." % (source.path, options.upstream_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) if options.vcs_tag: parents = [repo.rev_parse("%s^{}" % options.vcs_tag)] else: parents = None commit = repo.commit_dir( unpacked_orig, msg=msg, branch=options.upstream_branch, other_parents=parents, create_missing_branch=options.create_missing_branches) if options.pristine_tar and pristine_orig: gbp.log.info("Pristine-tar: commiting %s" % pristine_orig) repo.pristine_tar.commit(pristine_orig, options.upstream_branch) tag_str_fields = dict(upstreamversion=version, vendor="Upstream") tag = repo.version_to_tag(options.upstream_tag, tag_str_fields) repo.create_tag(name=tag, msg="Upstream version %s" % version, commit=commit, sign=options.sign_tags, keyid=options.keyid) if options.merge: gbp.log.info("Merging to '%s'" % options.packaging_branch) if repo.has_branch(options.packaging_branch): repo.set_branch(options.packaging_branch) try: repo.merge(tag) except GitRepositoryError: raise GbpError, """Merge failed, please resolve.""" else: repo.create_branch(options.packaging_branch, rev=options.upstream_branch) if repo.get_branch() == options.packaging_branch: repo.force_head(options.packaging_branch, hard=True) if options.postimport: info = {'upstreamversion': version} env = {'GBP_BRANCH': options.packaging_branch} gbpc.Command(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 == options.upstream_branch or current_branch == repo.pristine_tar_branch): repo.force_head(current_branch, hard=True) except (GitRepositoryError, gbpc.CommandExecFailed): raise GbpError, "Import of %s failed" % source.path except GbpError, err: if len(err.__str__()): gbp.log.err(err) ret = 1
def main(argv): """Main function of the git-import-srpm script""" dirs = dict(top=os.path.abspath(os.curdir)) ret = 0 skipped = False options, args = parse_args(argv) if not options: return ExitCodes.parse_error if len(args) == 1: srpm = args[0] target = None elif len(args) == 2: srpm = args[0] target = args[1] else: gbp.log.err("Need to give exactly one package to import. Try --help.") return 1 try: dirs['tmp_base'] = init_tmpdir(options.tmp_dir, 'import-srpm_') except GbpError as err: gbp.log.err(err) return 1 try: if options.download: srpm = download_source(srpm) # Real srpm, we need to unpack, first true_srcrpm = False if not os.path.isdir(srpm) and not srpm.endswith(".spec"): src = parse_srpm(srpm) true_srcrpm = True dirs['pkgextract'] = tempfile.mkdtemp(prefix='pkgextract_') gbp.log.info("Extracting src rpm to '%s'" % dirs['pkgextract']) src.unpack(dirs['pkgextract']) preferred_spec = src.name + '.spec' srpm = dirs['pkgextract'] elif os.path.isdir(srpm): preferred_spec = os.path.basename(srpm.rstrip('/')) + '.spec' else: preferred_spec = None # Find and parse spec file if os.path.isdir(srpm): gbp.log.debug("Trying to import an unpacked srpm from '%s'" % srpm) dirs['src'] = os.path.abspath(srpm) spec = guess_spec(srpm, True, preferred_spec) else: gbp.log.debug("Trying to import an srpm from '%s' with spec " "file '%s'" % (os.path.dirname(srpm), srpm)) dirs['src'] = os.path.abspath(os.path.dirname(srpm)) spec = SpecFile(srpm) # Check the repository state try: repo = RpmGitRepository('.') is_empty = repo.is_empty() (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) except GitRepositoryError: gbp.log.info("No git repository found, creating one.") is_empty = True target = target or spec.name repo = RpmGitRepository.create(target) os.chdir(repo.path) repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo) if repo.bare: set_bare_repo_options(options) # Create more tempdirs dirs['origsrc'] = tempfile.mkdtemp(prefix='origsrc_') dirs['packaging_base'] = tempfile.mkdtemp(prefix='packaging_') dirs['packaging'] = os.path.join(dirs['packaging_base'], options.packaging_dir) try: os.mkdir(dirs['packaging']) except OSError as err: if err.errno != errno.EEXIST: raise if true_srcrpm: # For true src.rpm we just take everything files = os.listdir(dirs['src']) else: # Need to copy files to the packaging directory given by caller files = [os.path.basename(patch.path) for patch in spec.patchseries(unapplied=True, ignored=True)] for filename in spec.sources().values(): files.append(os.path.basename(filename)) files.append(os.path.join(spec.specdir, spec.specfile)) # Don't copy orig source archive, though if spec.orig_src and spec.orig_src['filename'] in files: files.remove(spec.orig_src['filename']) for fname in files: fpath = os.path.join(dirs['src'], fname) if os.path.exists(fpath): shutil.copy2(fpath, dirs['packaging']) else: gbp.log.err("File '%s' listed in spec not found" % fname) raise GbpError # Unpack orig source archive if spec.orig_src: orig_tarball = os.path.join(dirs['src'], spec.orig_src['filename']) sources = RpmUpstreamSource(orig_tarball) sources.unpack(dirs['origsrc'], options.filters) else: sources = None tag_str_fields = dict(spec.version, vendor=options.vendor.lower()) if options.native: src_tag_format = options.packaging_tag src_tag = repo.version_to_tag(src_tag_format, tag_str_fields) upstream_tag = src_tag upstream_str_fields = tag_str_fields else: src_tag_format = options.upstream_tag src_tag = repo.version_to_tag(src_tag_format, tag_str_fields) upstream_str_fields = filter_version(tag_str_fields, 'release', 'epoch') upstream_tag = repo.version_to_tag(src_tag_format, upstream_str_fields) ver_str = compose_version_str(spec.version) if repo.find_version(options.packaging_tag, tag_str_fields): gbp.log.warn("Version %s already imported." % ver_str) if options.allow_same_version: gbp.log.info("Moving tag of version '%s' since import forced" % ver_str) move_tag_stamp(repo, options.packaging_tag, tag_str_fields) else: raise SkipImport if is_empty: options.create_missing_branches = True # Determine author and committer info, currently same info is used # for both sources and packaging files author = None if spec.packager: match = re.match(r'(?P<name>.*[^ ])\s*<(?P<email>\S*)>', spec.packager.strip()) if match: author = GitModifier(match.group('name'), match.group('email')) if not author: author = GitModifier() gbp.log.debug("Couldn't determine packager info") committer = committer_from_author(author, options) # Import sources if sources: src_commit = repo.find_version(src_tag_format, upstream_str_fields) if not src_commit: gbp.log.info("Tag %s not found, importing sources" % src_tag) branch = [options.upstream_branch, options.packaging_branch][options.native] if not repo.has_branch(branch): if options.create_missing_branches: gbp.log.info("Will create missing branch '%s'" % branch) else: gbp.log.err(no_upstream_branch_msg % branch + "\n" "Also check the --create-missing-branches option.") raise GbpError src_vendor = "Native" if options.native else "Upstream" msg = "%s version %s" % (src_vendor, spec.upstreamversion) src_commit = repo.commit_dir(sources.unpacked, "Import %s" % msg, branch, author=author, committer=committer, create_missing_branch=options.create_missing_branches) repo.create_tag(name=src_tag if options.native else upstream_tag, msg=msg, commit=src_commit, sign=options.sign_tags, keyid=options.keyid) if not options.native: if options.pristine_tar: archive_fmt = parse_archive_filename(orig_tarball)[1] if archive_fmt == 'tar': repo.pristine_tar.commit(orig_tarball, 'refs/heads/%s' % options.upstream_branch) else: gbp.log.warn('Ignoring pristine-tar, %s archives ' 'not supported' % archive_fmt) else: gbp.log.info("No orig source archive imported") # Import packaging files. For native packages we assume that also # packaging files are found in the source tarball if not options.native or not sources: gbp.log.info("Importing packaging files") branch = options.packaging_branch if not repo.has_branch(branch): if options.create_missing_branches: gbp.log.info("Will create missing branch '%s'" % branch) else: gbp.log.err(no_packaging_branch_msg % branch + "\n" "Also check the --create-missing-branches " "option.") raise GbpError tag = repo.version_to_tag(options.packaging_tag, tag_str_fields) msg = "%s release %s" % (options.vendor, ver_str) if options.orphan_packaging or not sources: commit = repo.commit_dir(dirs['packaging_base'], "Import %s" % msg, branch, author=author, committer=committer, create_missing_branch=options.create_missing_branches) else: # Copy packaging files to the unpacked sources dir try: pkgsubdir = os.path.join(sources.unpacked, options.packaging_dir) os.mkdir(pkgsubdir) except OSError as err: if err.errno != errno.EEXIST: raise for fname in os.listdir(dirs['packaging']): shutil.copy2(os.path.join(dirs['packaging'], fname), pkgsubdir) commit = repo.commit_dir(sources.unpacked, "Import %s" % msg, branch, other_parents=[src_commit], author=author, committer=committer, create_missing_branch=options.create_missing_branches) # Import patches on top of the source tree # (only for non-native packages with non-orphan packaging) force_to_branch_head(repo, options.packaging_branch) # Create packaging tag repo.create_tag(name=tag, msg=msg, commit=commit, sign=options.sign_tags, keyid=options.keyid) force_to_branch_head(repo, options.packaging_branch) except KeyboardInterrupt: ret = 1 gbp.log.err("Interrupted. Aborting.") except gbpc.CommandExecFailed: ret = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) ret = 1 except GbpError as err: if str(err): gbp.log.err(err) ret = 1 except NoSpecError as err: gbp.log.err("Failed determine spec file: %s" % err) ret = 1 except SkipImport: skipped = True finally: os.chdir(dirs['top']) del_tmpdir() if not ret and not skipped: gbp.log.info("Version '%s' imported under '%s'" % (ver_str, repo.path)) return ret
def main(argv): """Main function of the git-import-srpm script""" dirs = dict(top=os.path.abspath(os.curdir)) ret = 0 skipped = False options, args = parse_args(argv) if len(args) != 1: gbp.log.err("Need to give exactly one package to import. Try --help.") return 1 try: dirs['tmp_base'] = tempfile.mkdtemp(dir=options.tmp_dir, prefix='import-srpm') except GbpError as err: gbp.log.err(err) return 1 try: srpm = args[0] if options.download: srpm = download_source(srpm, dirs) # Real srpm, we need to unpack, first true_srcrpm = False if not os.path.isdir(srpm) and not srpm.endswith(".spec"): src = parse_srpm(srpm) true_srcrpm = True dirs['pkgextract'] = tempfile.mkdtemp(dir=dirs['tmp_base'], prefix='pkgextract_') gbp.log.info("Extracting src rpm to '%s'" % dirs['pkgextract']) src.unpack(dirs['pkgextract']) preferred_spec = src.name + '.spec' srpm = dirs['pkgextract'] elif os.path.isdir(srpm): preferred_spec = os.path.basename(srpm.rstrip('/')) + '.spec' else: preferred_spec = None # Find and parse spec file if os.path.isdir(srpm): gbp.log.debug("Trying to import an unpacked srpm from '%s'" % srpm) dirs['src'] = os.path.abspath(srpm) spec = guess_spec(srpm, True, preferred_spec) else: gbp.log.debug("Trying to import an srpm from '%s' with spec "\ "file '%s'" % (os.path.dirname(srpm), srpm)) dirs['src'] = os.path.abspath(os.path.dirname(srpm)) spec = SpecFile(srpm) # Check the repository state try: repo = RpmGitRepository('.') is_empty = repo.is_empty() (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 except GitRepositoryError: gbp.log.info("No git repository found, creating one.") is_empty = True repo = RpmGitRepository.create(spec.name) os.chdir(repo.path) if repo.bare: set_bare_repo_options(options) # Create more tempdirs dirs['origsrc'] = tempfile.mkdtemp(dir=dirs['tmp_base'], prefix='origsrc_') dirs['packaging_base'] = tempfile.mkdtemp(dir=dirs['tmp_base'], prefix='packaging_') dirs['packaging'] = os.path.join(dirs['packaging_base'], options.packaging_dir) try: os.mkdir(dirs['packaging']) except OSError as err: if err.errno != errno.EEXIST: raise if true_srcrpm: # For true src.rpm we just take everything files = os.listdir(dirs['src']) else: # Need to copy files to the packaging directory given by caller files = [os.path.basename(patch.path) \ for patch in spec.patchseries(unapplied=True, ignored=True)] for filename in spec.sources().values(): files.append(os.path.basename(filename)) files.append(os.path.join(spec.specdir, spec.specfile)) # Don't copy orig source archive, though if spec.orig_src and spec.orig_src['filename'] in files: files.remove(spec.orig_src['filename']) for fname in files: fpath = os.path.join(dirs['src'], fname) if os.path.exists(fpath): shutil.copy2(fpath, dirs['packaging']) else: gbp.log.err("File '%s' listed in spec not found" % fname) raise GbpError # Unpack orig source archive if spec.orig_src: orig_tarball = os.path.join(dirs['src'], spec.orig_src['filename']) sources = RpmUpstreamSource(orig_tarball) sources.unpack(dirs['origsrc'], options.filters) else: sources = None src_tag_format = options.packaging_tag if options.native \ else options.upstream_tag tag_str_fields = dict(spec.version, vendor=options.vendor.lower()) src_tag = repo.version_to_tag(src_tag_format, tag_str_fields) ver_str = compose_version_str(spec.version) if repo.find_version(options.packaging_tag, tag_str_fields): gbp.log.warn("Version %s already imported." % ver_str) if options.allow_same_version: gbp.log.info("Moving tag of version '%s' since import forced" % ver_str) move_tag_stamp(repo, options.packaging_tag, tag_str_fields) else: raise SkipImport if is_empty: options.create_missing_branches = True # Determine author and committer info, currently same info is used # for both sources and packaging files author = None if spec.packager: match = re.match(r'(?P<name>.*[^ ])\s*<(?P<email>\S*)>', spec.packager.strip()) if match: author = GitModifier(match.group('name'), match.group('email')) if not author: author = GitModifier() gbp.log.debug("Couldn't determine packager info") committer = committer_from_author(author, options) # Import sources if sources: src_commit = repo.find_version(src_tag_format, tag_str_fields) if not src_commit: gbp.log.info("Tag %s not found, importing sources" % src_tag) branch = [options.upstream_branch, options.packaging_branch][options.native] if not repo.has_branch(branch): if options.create_missing_branches: gbp.log.info("Will create missing branch '%s'" % branch) else: gbp.log.err( no_upstream_branch_msg % branch + "\n" "Also check the --create-missing-branches option.") raise GbpError src_vendor = "Native" if options.native else "Upstream" msg = "%s version %s" % (src_vendor, spec.upstreamversion) src_commit = repo.commit_dir( sources.unpacked, "Imported %s" % msg, branch, author=author, committer=committer, create_missing_branch=options.create_missing_branches) repo.create_tag(name=src_tag, msg=msg, commit=src_commit, sign=options.sign_tags, keyid=options.keyid) if not options.native: if options.pristine_tar: archive_fmt = parse_archive_filename(orig_tarball)[1] if archive_fmt == 'tar': repo.pristine_tar.commit( orig_tarball, 'refs/heads/%s' % options.upstream_branch) else: gbp.log.warn('Ignoring pristine-tar, %s archives ' 'not supported' % archive_fmt) else: gbp.log.info("No orig source archive imported") # Import packaging files. For native packages we assume that also # packaging files are found in the source tarball if not options.native or not sources: gbp.log.info("Importing packaging files") branch = options.packaging_branch if not repo.has_branch(branch): if options.create_missing_branches: gbp.log.info("Will create missing branch '%s'" % branch) else: gbp.log.err(no_packaging_branch_msg % branch + "\n" "Also check the --create-missing-branches " "option.") raise GbpError tag = repo.version_to_tag(options.packaging_tag, tag_str_fields) msg = "%s release %s" % (options.vendor, ver_str) if options.orphan_packaging or not sources: commit = repo.commit_dir( dirs['packaging_base'], "Imported %s" % msg, branch, author=author, committer=committer, create_missing_branch=options.create_missing_branches) else: # Copy packaging files to the unpacked sources dir try: pkgsubdir = os.path.join(sources.unpacked, options.packaging_dir) os.mkdir(pkgsubdir) except OSError as err: if err.errno != errno.EEXIST: raise for fname in os.listdir(dirs['packaging']): shutil.copy2(os.path.join(dirs['packaging'], fname), pkgsubdir) commit = repo.commit_dir( sources.unpacked, "Imported %s" % msg, branch, other_parents=[src_commit], author=author, committer=committer, create_missing_branch=options.create_missing_branches) # Import patches on top of the source tree # (only for non-native packages with non-orphan packaging) force_to_branch_head(repo, options.packaging_branch) # Create packaging tag repo.create_tag(name=tag, msg=msg, commit=commit, sign=options.sign_tags, keyid=options.keyid) force_to_branch_head(repo, options.packaging_branch) except KeyboardInterrupt: ret = 1 gbp.log.err("Interrupted. Aborting.") except gbpc.CommandExecFailed: ret = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) ret = 1 except GbpError as err: if str(err): gbp.log.err(err) ret = 1 except NoSpecError as err: gbp.log.err("Failed determine spec file: %s" % err) ret = 1 except SkipImport: skipped = True finally: os.chdir(dirs['top']) gbpc.RemoveTree(dirs['tmp_base'])() if not ret and not skipped: gbp.log.info("Version '%s' imported under '%s'" % (ver_str, spec.name)) return ret
def main(argv): """Entry point for gbp-buildpackage-rpm""" retval = 0 prefix = "git-" spec = None options, gbp_args, builder_args = parse_args(argv, prefix) if not options: return 1 try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 # Determine tree-ish to be exported try: tree = get_tree(repo, options.export) except GbpError as err: gbp.log.err('Failed to determine export treeish: %s' % err) return 1 # Re-parse config options with using the per-tree config file(s) from the # exported tree-ish options, gbp_args, builder_args = parse_args(argv, prefix, tree) branch = get_current_branch(repo) try: init_tmpdir(options.tmp_dir, prefix='buildpackage-rpm_') tree = get_tree(repo, options.export) spec = parse_spec(options, repo, treeish=tree) 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.") if not options.ignore_new and not options.ignore_branch: if branch != options.packaging_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.packaging_branch, branch)) raise GbpError( "Use --git-ignore-branch to ignore or " "--git-packaging-branch to set the branch name.") # Dump from git to a temporary directory: packaging_tree = '%s:%s' % (tree, options.packaging_dir) dump_dir = tempfile.mkdtemp(prefix='packaging_') gbp.log.debug("Dumping packaging files to '%s'" % dump_dir) if not dump_tree(repo, dump_dir, packaging_tree, False, False): raise GbpError # Re-parse spec from dump dir to get version etc. spec = rpm.SpecFile(os.path.join(dump_dir, spec.specfile)) if not options.tag_only: # Setup builder opts setup_builder(options, builder_args) if options.use_mock: setup_mock(options) # Prepare final export dirs export_dir = makedir(options.export_dir) source_dir = makedir( os.path.join(export_dir, options.export_sourcedir)) spec_dir = makedir(os.path.join(export_dir, options.export_specdir)) # Move packaging files to final export dir gbp.log.debug("Exporting packaging files from '%s' to '%s'" % (dump_dir, export_dir)) for fname in os.listdir(dump_dir): src = os.path.join(dump_dir, fname) if fname == spec.specfile: dst = os.path.join(spec_dir, fname) else: dst = os.path.join(source_dir, fname) try: shutil.copy2(src, dst) except IOError as err: raise GbpError("Error exporting packaging files: %s" % err) spec.specdir = os.path.abspath(spec_dir) # Get/build the orig tarball if is_native(repo, options): if spec.orig_src and not options.no_create_orig: # Just build source archive from the exported tree gbp.log.info( "Creating (native) source archive %s from '%s'" % (spec.orig_src['filename'], tree)) if spec.orig_src['compression']: gbp.log.debug( "Building source archive with " "compression '%s -%s'" % (spec.orig_src['compression'], options.comp_level)) orig_prefix = spec.orig_src['prefix'] if not git_archive(repo, spec, source_dir, tree, orig_prefix, options.comp_level, options.with_submodules): raise GbpError("Cannot create source tarball at '%s'" % source_dir) # Non-native packages: create orig tarball from upstream elif spec.orig_src: prepare_upstream_tarball(repo, spec, options, source_dir) # Run postexport hook if options.postexport: RunAtCommand(options.postexport, shell=True, extra_env={ 'GBP_GIT_DIR': repo.git_dir, 'GBP_TMP_DIR': export_dir })(dir=export_dir) # Do actual build if not options.no_build and not options.tag_only: if options.prebuild: RunAtCommand(options.prebuild, shell=True, extra_env={ 'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': export_dir })(dir=export_dir) # Finally build the package: if options.builder.startswith("rpmbuild"): builder_args.append( os.path.join(spec.specdir, spec.specfile)) else: builder_args.append(spec.specfile) RunAtCommand(options.builder, builder_args, shell=True, extra_env={'GBP_BUILD_DIR': export_dir})(dir=export_dir) if options.postbuild: changes = os.path.abspath("%s/%s.changes" % (source_dir, spec.name)) gbp.log.debug("Looking for changes file %s" % changes) Command(options.postbuild, shell=True, extra_env={ 'GBP_CHANGES_FILE': changes, 'GBP_BUILD_DIR': export_dir })() # Tag (note: tags the exported version) if options.tag or options.tag_only: gbp.log.info("Tagging %s" % rpm.compose_version_str(spec.version)) tag = create_packaging_tag(repo, tree, spec.name, spec.version, options) vcs_info = get_vcs_info(repo, tag) if options.posttag: sha = repo.rev_parse("%s^{}" % tag) Command(options.posttag, shell=True, extra_env={ 'GBP_TAG': tag, 'GBP_BRANCH': branch, 'GBP_SHA1': sha })() else: vcs_info = get_vcs_info(repo, tree) except CommandExecFailed: retval = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpAutoGenerateError as err: if len(err.__str__()): gbp.log.err(err) retval = 2 except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 finally: drop_index() del_tmpdir() if not options.tag_only: if spec and options.notify: summary = "Gbp-rpm %s" % ["failed", "successful"][not retval] message = ("Build of %s %s %s" % (spec.name, rpm.compose_version_str( spec.version), ["failed", "succeeded"][not retval])) if not gbp.notifications.notify(summary, message, options.notify): gbp.log.err("Failed to send notification") retval = 1 return retval
def main(argv): """Main function for the gbp pq-rpm command""" retval = 0 (options, args) = parse_args(argv) if not options: return 1 gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch", "convert"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: # Create base temporary directory for this run options.tmp_dir = tempfile.mkdtemp(dir=options.tmp_dir, prefix='gbp-pq-rpm_') current = repo.get_branch() if action == "export": export_patches(repo, options) elif action == "import": import_spec_patches(repo, options) elif action == "drop": drop_pq(repo, current) elif action == "rebase": rebase_pq(repo, options) elif action == "apply": patch = Patch(patchfile) apply_single_patch(repo, current, patch, fallback_author=None) elif action == "switch": switch_pq(repo, current) except CommandExecFailed: retval = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpError, err: if str(err): gbp.log.err(err) retval = 1
def main(argv): """Entry point for gbp-clone-bb""" retval = 0 if not bb: return 1 (options, args) = parse_args(argv) if not options: return 1 if len(args) < 2: gbp.log.err("Need a package or repository to clone.") return 1 # Determine target dir clone_to = os.path.curdir auto_name = False if len(args) < 3: if 'BUILDDIR' in os.environ: clone_to = os.path.join(os.environ['BUILDDIR'], 'devel') auto_name = True else: clone_to = args[2] try: tinfoil = init_tinfoil() source, revision = guess_remote(tinfoil, args[1]) gbp.log.info("Cloning from %s..." % source) repo = GitRepository.clone(clone_to, source, options.depth, auto_name=auto_name) os.chdir(repo.path) # Reparse the config files of the cloned repository so we pick up the # branch information from there: (options, args) = parse_args(argv) # Track all branches: if options.all: remotes = repo.get_remote_branches() for remote in remotes: local = remote.replace("origin/", "", 1) if not repo.has_branch(local) and local != "HEAD": repo.create_branch(local, remote) else: # only track gbp's default branches branches = [options.packaging_branch, options.upstream_branch] gbp.log.debug('Will track branches: %s' % branches) for branch in branches: remote = 'origin/%s' % branch if repo.has_branch(remote, remote=True) and \ not repo.has_branch(branch): repo.create_branch(branch, remote) gbp.log.info("Successfully cloned into %s" % clone_to) if (revision and repo.rev_parse('HEAD') != repo.rev_parse('%s^0' % revision)): gbp.log.info("Checking out revision %s" % revision) repo.set_branch(revision) except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 return retval
def main(argv): """Entry point for gbp-buildpackage-rpm""" retval = 0 prefix = "git-" spec = None options, gbp_args, builder_args = parse_args(argv, prefix) if not options: return 1 try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 # Determine tree-ish to be exported try: tree = get_tree(repo, options.export) except GbpError as err: gbp.log.err('Failed to determine export treeish: %s' % err) return 1 # Re-parse config options with using the per-tree config file(s) from the # exported tree-ish options, gbp_args, builder_args = parse_args(argv, prefix, tree) branch = get_current_branch(repo) try: init_tmpdir(options.tmp_dir, prefix='buildpackage-rpm_') tree = get_tree(repo, options.export) spec = parse_spec(options, repo, treeish=tree) 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.") if not options.ignore_new and not options.ignore_branch: if branch != options.packaging_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.packaging_branch, branch)) raise GbpError("Use --git-ignore-branch to ignore or " "--git-packaging-branch to set the branch name.") # Dump from git to a temporary directory: packaging_tree = '%s:%s' % (tree, options.packaging_dir) dump_dir = tempfile.mkdtemp(prefix='packaging_') gbp.log.debug("Dumping packaging files to '%s'" % dump_dir) if not dump_tree(repo, dump_dir, packaging_tree, False, False): raise GbpError # Re-parse spec from dump dir to get version etc. spec = rpm.SpecFile(os.path.join(dump_dir, spec.specfile)) if not options.tag_only: # Setup builder opts setup_builder(options, builder_args) if options.use_mock: setup_mock(options) # Prepare final export dirs export_dir = makedir(options.export_dir) source_dir = makedir(os.path.join(export_dir, options.export_sourcedir)) spec_dir = makedir(os.path.join(export_dir, options.export_specdir)) # Move packaging files to final export dir gbp.log.debug("Exporting packaging files from '%s' to '%s'" % (dump_dir, export_dir)) for fname in os.listdir(dump_dir): src = os.path.join(dump_dir, fname) if fname == spec.specfile: dst = os.path.join(spec_dir, fname) else: dst = os.path.join(source_dir, fname) try: shutil.copy2(src, dst) except IOError as err: raise GbpError("Error exporting packaging files: %s" % err) spec.specdir = os.path.abspath(spec_dir) # Get/build the orig tarball if is_native(repo, options): if spec.orig_src and not options.no_create_orig: # Just build source archive from the exported tree gbp.log.info("Creating (native) source archive %s from '%s'" % (spec.orig_src['filename'], tree)) if spec.orig_src['compression']: gbp.log.debug("Building source archive with " "compression '%s -%s'" % (spec.orig_src['compression'], options.comp_level)) orig_prefix = spec.orig_src['prefix'] if not git_archive(repo, spec, source_dir, tree, orig_prefix, options.comp_level, options.with_submodules): raise GbpError("Cannot create source tarball at '%s'" % source_dir) # Non-native packages: create orig tarball from upstream elif spec.orig_src: prepare_upstream_tarball(repo, spec, options, source_dir) # Run postexport hook if options.postexport: RunAtCommand(options.postexport, shell=True, extra_env={'GBP_GIT_DIR': repo.git_dir, 'GBP_TMP_DIR': export_dir} )(dir=export_dir) # Do actual build if not options.no_build and not options.tag_only: if options.prebuild: RunAtCommand(options.prebuild, shell=True, extra_env={'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': export_dir} )(dir=export_dir) # Finally build the package: if options.builder.startswith("rpmbuild"): builder_args.append(os.path.join(spec.specdir, spec.specfile)) else: builder_args.append(spec.specfile) RunAtCommand(options.builder, builder_args, shell=True, extra_env={'GBP_BUILD_DIR': export_dir} )(dir=export_dir) if options.postbuild: changes = os.path.abspath("%s/%s.changes" % (source_dir, spec.name)) gbp.log.debug("Looking for changes file %s" % changes) Command(options.postbuild, shell=True, extra_env={'GBP_CHANGES_FILE': changes, 'GBP_BUILD_DIR': export_dir})() # Tag (note: tags the exported version) if options.tag or options.tag_only: gbp.log.info("Tagging %s" % rpm.compose_version_str(spec.version)) tag = create_packaging_tag(repo, tree, spec.name, spec.version, options) vcs_info = get_vcs_info(repo, tag) if options.posttag: sha = repo.rev_parse("%s^{}" % tag) Command(options.posttag, shell=True, extra_env={'GBP_TAG': tag, 'GBP_BRANCH': branch, 'GBP_SHA1': sha})() else: vcs_info = get_vcs_info(repo, tree) except CommandExecFailed: retval = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpAutoGenerateError as err: if len(err.__str__()): gbp.log.err(err) retval = 2 except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 finally: drop_index() del_tmpdir() if not options.tag_only: if spec and options.notify: summary = "Gbp-rpm %s" % ["failed", "successful"][not retval] message = ("Build of %s %s %s" % (spec.name, rpm.compose_version_str(spec.version), ["failed", "succeeded"][not retval])) if not gbp.notifications.notify(summary, message, options.notify): gbp.log.err("Failed to send notification") retval = 1 return retval
def main(argv): """Main function for the gbp pq-rpm command""" retval = 0 if not bb: return 1 options, args = parse_args(argv) if not options: return 1 if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 if os.path.abspath('.') != repo.path: gbp.log.warn("Switching to topdir before running commands") os.chdir(repo.path) try: # Initialize BitBake tinfoil = init_tinfoil(config_only=True, tracking=True) bb_cfg_data = bb.data.createCopy(tinfoil.config_data) # Create base temporary directory for this run options.tmp_dir = tempfile.mkdtemp(dir=options.tmp_dir, prefix='gbp-pq-bb_') if action == "export": export_patches(bb_cfg_data, repo, options) elif action == "import": import_bb_patches(bb_cfg_data, repo, options) elif action == "drop": drop_pq_bb(bb_cfg_data, repo, options) elif action == "rebase": rebase_pq(bb_cfg_data, repo, options) elif action == "apply": apply_single_patch(bb_cfg_data, repo, patchfile, options) elif action == "switch": switch_pq(bb_cfg_data, repo, options) except CommandExecFailed: retval = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpError, err: if len(err.__str__()): gbp.log.err(err) retval = 1