def add_parser(subparsers): parser = subparsers.add_parser('trim', description="""\ Moves a given sub directory into the root of the git repository. If you call trim on a patched branch (even --undo), bad things will happen...\ """) parser.set_defaults(func=main) add = parser.add_argument add('--sub-directory', '-s', metavar='SUB_DIRECTORY', help="the sub directory to move the root of the repository", default=None) add('--force', '-f', help="force the change of the SUB_DIRECTORY if set", action='store_true', default=False) add('--undo', '-u', help="reverses the the trim using 'git reset --hard'", action='store_true', default=False) add_global_arguments(parser) return parser
def main(sysargs=None): if len(sysargs if sysargs is not None else sys.argv[1:]) == 0: # This means show me the current config, first check we have an env ensure_clean_working_env() if not branch_exists('bloom'): sys.exit("No bloom branch found") show_current() info("See: 'git-bloom-config -h' on how to change the configs") return 0 parser = get_argument_parser() add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) # Also check to see if git has been init'ed check_git_init() # Check that the current directory is a serviceable git/bloom repo try: ensure_clean_working_env() ensure_git_root() except SystemExit: parser.print_usage() raise # Then call the verb try: args.func(args) except (KeyboardInterrupt, EOFError): error("\nUser sent a Keyboard Interrupt, aborting.", exit=True)
def main(sysargs=None): if len(sysargs if sysargs is not None else sys.argv[1:]) == 0: # This means show me the current config, first check we have an env ensure_clean_working_env() if not branch_exists(BLOOM_CONFIG_BRANCH): sys.exit("No {0} branch found".format(BLOOM_CONFIG_BRANCH)) show_current() info("See: 'git-bloom-config -h' on how to change the configs") return 0 parser = get_argument_parser() add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) # Also check to see if git has been init'ed check_git_init() # Check that the current directory is a serviceable git/bloom repo try: ensure_clean_working_env() ensure_git_root() except SystemExit: parser.print_usage() raise # Then call the verb try: args.func(args) except (KeyboardInterrupt, EOFError): error("\nUser sent a Keyboard Interrupt, aborting.", exit=True)
def add_parser(subparsers): parser = subparsers.add_parser( 'remove', description="Removes any applied patches from the working branch, " "including any un-exported patches, so use with caution.") parser.set_defaults(func=main) add_global_arguments(parser) return parser
def add_parser(subparsers): parser = subparsers.add_parser('import', description="""\ Imports the patches from the patches branch, which is named 'patches/<current branch name>', onto the current working branch. """) parser.set_defaults(func=main) add_global_arguments(parser) return parser
def add_parser(subparsers): parser = subparsers.add_parser( 'remove', description="Removes any applied patches from the working branch, " "including any un-exported patches, so use with caution." ) parser.set_defaults(func=main) add_global_arguments(parser) return parser
def create_subparsers(parent_parser, generators): subparsers = parent_parser.add_subparsers( title='generators', description='Available bloom platform generators:', dest='generator') for generator in generators: parser = subparsers.add_parser(generator.title, description=generator.description, help=generator.help) generator.prepare_arguments(parser) add_global_arguments(parser)
def add_parser(subparsers): """Returns a parser.ArgumentParser with all arguments defined""" parser = subparsers.add_parser('export', description="""\ Exports the commits that have been made on the current branch since the original source branch (source branch from git-bloom-branch) to a patches branch, which is named 'patches/<current branch name>', using git format-patch. """) parser.set_defaults(func=main) add_global_arguments(parser) return parser
def add_parser(subparsers): parser = subparsers.add_parser( 'import', description="""\ Imports the patches from the patches branch, which is named 'patches/<current branch name>', onto the current working branch. """ ) parser.set_defaults(func=main) add_global_arguments(parser) return parser
def create_subparsers(parent_parser, generators): subparsers = parent_parser.add_subparsers( title='generators', description='Available bloom platform generators:', dest='generator' ) for generator in generators: parser = subparsers.add_parser(generator.title, description=generator.description, help=generator.help) generator.prepare_arguments(parser) add_global_arguments(parser)
def add_parser(subparsers): """Returns a parser.ArgumentParser with all arguments defined""" parser = subparsers.add_parser( 'export', description="""\ Exports the commits that have been made on the current branch since the original source branch (source branch from git-bloom-branch) to a patches branch, which is named 'patches/<current branch name>', using git format-patch. """ ) parser.set_defaults(func=main) add_global_arguments(parser) return parser
def create_subparsers(parser, generator_cmds): metavar = '[' + ' | '.join(generator_cmds) + ']' subparser = parser.add_subparsers( title='generate commands', metavar=metavar, description='Call `bloom-generate {0} -h` for help on a each generate command.'.format(metavar), dest='generator_cmd' ) for generator_cmd in generator_cmds: desc = load_generator_description(generator_cmd) cmd_parser = subparser.add_parser(desc['title'], description=desc['description']) cmd_parser = desc['prepare_arguments'](cmd_parser) cmd_parser.set_defaults(func=desc['main']) add_global_arguments(cmd_parser)
def main(sysargs=None): # Check that the current directory is a serviceable git/bloom repo ensure_clean_working_env() ensure_git_root() # Get tracks tracks_dict = get_tracks_dict_raw() if not tracks_dict['tracks']: error("No tracks configured, first create a track with " "'git-bloom-config new <track_name>'", exit=True) # Do argparse stuff parser = get_argument_parser([str(t) for t in tracks_dict['tracks']]) parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) verify_track(args.track, tracks_dict['tracks'][args.track]) execute_track(args.track, tracks_dict['tracks'][args.track], args.release_increment, args.pretend, args.debug, args.unsafe) # Notify the user of success and next action suggestions print('\n\n') warning("Tip: Check to ensure that the debian tags created have the same " "version as the upstream version you are releasing.") info(fmt("@{gf}@!Everything went as expected, " "you should check that the new tags match your expectations, and " "then push to the release repo with:@|")) info(fmt(" git push --all && git push --tags " "@{kf}@!# You might have to add --force to the second command if you " "are over-writing existing flags"))
def main(sysargs=None): parser = get_parser() parser = add_global_arguments(parser) # List the generators generator_names = list_generators() # Create the generators generators = create_generators(generator_names) # Setup a subparser for each generator create_subparsers(parser, generators.values()) args = parser.parse_args(sysargs) handle_global_arguments(args) generator = generators[args.generator] # Check that the current directory is a serviceable git/bloom repo try: ensure_clean_working_env() ensure_git_root() except SystemExit: parser.print_usage() raise # Run the generator that was selected in a clone # The clone protects the release repo state from mid change errors with log_prefix('[git-bloom-generate {0}]: '.format(generator.title)): git_clone = GitClone() with git_clone: run_generator(generator, args) git_clone.commit()
def create_subparsers(parser, generator_cmds): metavar = '[' + ' | '.join(generator_cmds) + ']' subparser = parser.add_subparsers( title='generate commands', metavar=metavar, description= 'Call `bloom-generate {0} -h` for help on a each generate command.'. format(metavar), dest='generator_cmd') for generator_cmd in generator_cmds: desc = load_generator_description(generator_cmd) cmd_parser = subparser.add_parser(desc['title'], description=desc['description']) cmd_parser = desc['prepare_arguments'](cmd_parser) cmd_parser.set_defaults(func=desc['main']) add_global_arguments(cmd_parser)
def main(sysargs=None): parser = get_argument_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) # Check that the current directory is a serviceable git/bloom repo try: ensure_clean_working_env() ensure_git_root() except SystemExit: parser.print_usage() raise git_clone = GitClone() with git_clone: import_upstream( args.archive_path, args.patches_path, args.release_version, args.name, args.replace) git_clone.commit() info("I'm happy. You should be too.")
def main(sysargs=None): parser = get_parser() parser = add_global_arguments(parser) # List the generators generator_names = list_generators() # Create the generators generators = create_generators(generator_names) # Setup a subparser for each generator create_subparsers(parser, generators.values()) args = parser.parse_args(sysargs) handle_global_arguments(args) generator = generators[args.generator] # Run the generator that was selected in a clone # The clone protects the release repo state from mid change errors with log_prefix('[git-bloom-generate {0}]: '.format(generator.title)): git_clone = GitClone() try: with git_clone: ret = run_generator(generator, args) if ret > 0: return ret git_clone.commit() return ret except GeneratorError as err: return err.retcode
def main(sysargs=None): parser = get_argument_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) export_upstream(args.uri, args.tag, args.type, args.output_dir, args.display_uri, args.name)
def main(): # Assumptions: in a git repo, this command verb was passed, argv has enough sysargs = sys.argv[2:] parser = get_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) return rebase_patches()
def main(): # Assumptions: in a git repo, this command verb was passed, argv has enough sysargs = sys.argv[2:] parser = get_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) return trim(args.sub_directory, args.force, args.undo)
def add_parser(subparsers): parser = subparsers.add_parser( 'trim', description="""\ Moves a given sub directory into the root of the git repository. If you call trim on a patched branch (even --undo), bad things will happen...\ """ ) parser.set_defaults(func=main) add = parser.add_argument add('--sub-directory', '-s', metavar='SUB_DIRECTORY', help="the sub directory to move the root of the repository", default=None) add('--force', '-f', help="force the change of the SUB_DIRECTORY if set", action='store_true', default=False) add('--undo', '-u', help="reverses the the trim using 'git reset --hard'", action='store_true', default=False) add_global_arguments(parser) return parser
def add_parser(subparsers): parser = subparsers.add_parser( 'rebase', description="""\ This command sets the contents of the current branch to the contents of the parent (upstream) branch. It does this by replacing the current branch contents with parent contents: - delete current branch contents, copy over upstream branch contents - clear trim flag (so it can be reapplied) - update patches.conf {0}\ WARNING: make sure to export patches and commit local changes before rebasing\ {1} """.format(ansi('yellowf'), ansi('reset')), formatter_class=argparse.RawTextHelpFormatter) parser.set_defaults(func=main) add_global_arguments(parser) return parser
def main(sysargs=None): from bloom.config import upconvert_bloom_to_config_branch upconvert_bloom_to_config_branch() # Check that the current directory is a serviceable git/bloom repo ensure_clean_working_env() ensure_git_root() # Get tracks tracks_dict = get_tracks_dict_raw() if not tracks_dict['tracks']: error( "No tracks configured, first create a track with " "'git-bloom-config new <track_name>'", exit=True) # Do argparse stuff parser = get_argument_parser([str(t) for t in tracks_dict['tracks']]) parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) os.environ['BLOOM_TRACK'] = args.track verify_track(args.track, tracks_dict['tracks'][args.track]) git_clone = GitClone() with git_clone: quiet_git_clone_warning(True) disable_git_clone(True) execute_track(args.track, tracks_dict['tracks'][args.track], args.release_increment, args.pretend, args.debug, args.unsafe, interactive=args.interactive) disable_git_clone(False) quiet_git_clone_warning(False) git_clone.commit() # Notify the user of success and next action suggestions info('\n\n', use_prefix=False) warning("Tip: Check to ensure that the debian tags created have the same " "version as the upstream version you are releasing.") info( fmt("@{gf}@!Everything went as expected, " "you should check that the new tags match your expectations, and " "then push to the release repo with:@|")) info( fmt(" git push --all && git push --tags " "@{kf}@!# You might have to add --force to the second command if you " "are over-writing existing tags"))
def main(sysargs=None): parser = get_argument_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) if args.list_tracks: list_tracks(args.repository, args.ros_distro) return perform_release(args.repository, args.track, args.ros_distro, args.new_track, not args.non_interactive, args.pretend)
def add_parser(subparsers): parser = subparsers.add_parser( 'rebase', description="""\ This command sets the contents of the current branch to the contents of the parent (upstream) branch. It does this by replacing the current branch contents with parent contents: - delete current branch contents, copy over upstream branch contents - clear trim flag (so it can be reapplied) - update patches.conf {0}\ WARNING: make sure to export patches and commit local changes before rebasing\ {1} """.format(ansi('yellowf'), ansi('reset')), formatter_class=argparse.RawTextHelpFormatter ) parser.set_defaults(func=main) add_global_arguments(parser) return parser
def main(sysargs=None): parser = get_argument_parser() add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) retcode = "command not run" if get_root() is None: parser.print_help() error("This command must be run in a valid git repository.", exit=True) ensure_git_root() try: retcode = args.func(args) or 0 except CalledProcessError as err: # Problem calling out to git probably print_exc(traceback.format_exc()) error(str(err)) retcode = 2 except Exception as err: # Unhandled exception, print traceback print_exc(traceback.format_exc()) error(str(err)) retcode = 3 sys.exit(retcode)
def main(sysargs=None): if len(sysargs if sysargs is not None else sys.argv) == 1: retcode = ensure_clean_working_env() if retcode != 0: return retcode if branch_exists('bloom', False): show_current() info("See: 'git-bloom-config -h' on how to change the configs") return 0 else: info("No bloom branch found") parser = get_argument_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) # Check for freshly initialized repo ret = check_git_init() if ret != 0: return ret retcode = ensure_clean_working_env() if retcode != 0: return retcode # Summarize the requested operation summarize_arguments(args.upstream_repository, args.upstream_vcs_type, args.upstream_branch) # Validate the arguments and repository if not validate_args(args.upstream_vcs_type): return 1 # Store the current branch current_branch = get_current_branch() try: set_upstream(args.upstream_repository, args.upstream_vcs_type, args.upstream_branch) info("Upstream successively set.") return 0 finally: # Try to roll back to the branch the user was on before # this possibly failed. if current_branch: checkout(current_branch) return 1
def main(sysargs=None): parser = get_argument_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) if args.list_tracks: list_tracks(args.repository, args.ros_distro) return try: os.environ['BLOOM_TRACK'] = args.track disable_git_clone(True) quiet_git_clone_warning(True) perform_release(args.repository, args.track, args.ros_distro, args.new_track, not args.non_interactive, args.pretend) except (KeyboardInterrupt, EOFError) as exc: error("\nReceived '{0}', aborting.".format(type(exc).__name__))
def main(sysargs=None): parser = get_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) # Check that the current directory is a serviceable git/bloom repo try: ensure_clean_working_env() ensure_git_root() except SystemExit: parser.print_usage() raise # If the src argument isn't set, use the current branch if args.src is None: args.src = get_current_branch() # Execute the branching execute_branch(args.src, args.destination_branch, args.interactive)
def main(sysargs=None): parser = get_argument_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) if args.list_tracks: list_tracks(args.repository, args.ros_distro) return if args.no_web: os.environ['BLOOM_NO_WEBBROWSER'] = '1' try: os.environ['BLOOM_TRACK'] = args.track disable_git_clone(True) quiet_git_clone_warning(True) perform_release(args.repository, args.track, args.ros_distro, args.new_track, not args.non_interactive, args.pretend) except (KeyboardInterrupt, EOFError) as exc: error("\nReceived '{0}', aborting.".format(type(exc).__name__))
def main(sysargs=None): parser = get_argument_parser() parser = add_global_arguments(parser) args = parser.parse_args(sysargs) handle_global_arguments(args) # Check that the current directory is a serviceable git/bloom repo ret = ensure_clean_working_env() if ret != 0: parser.print_usage() return ret # Get the current git branch current_branch = get_current_branch() # Create a working temp directory tmp_dir = create_temporary_directory() cwd = os.getcwd() try: # Get off upstream branch if current_branch == 'upstream': checkout(get_commit_hash('upstream'), directory=cwd) retcode = import_upstream(cwd, tmp_dir, args) # Done! retcode = retcode if retcode is not None else 0 if retcode == 0: info("I'm happy. You should be too.") return retcode finally: # Change back to the original cwd os.chdir(cwd) # Clean up shutil.rmtree(tmp_dir) if current_branch and branch_exists(current_branch, True, cwd): checkout(current_branch, directory=cwd)
def main(sysargs=None): # Do argparse stuff parser = get_argument_parser() parser = add_global_arguments(parser) # List the generators generator_names = list_generators() # Create the generators generators = create_generators(generator_names) # Setup a subparser for each generator create_subparsers(parser, generators.values()) # Inject into sys.argv if '--prefix' not in sys.argv: sys.argv.extend(['--prefix', 'release']) args = parser.parse_args(sysargs) handle_global_arguments(args) # Set logging prefix push_log_prefix('[git-bloom-release]: ') # Run import upstream info("###") msg = "### Running 'git bloom-import-upstream --replace'... " info(msg) info("###") iu_args = ['--replace'] if args.debug: iu_args.append('-d') ret = iu_main(iu_args) msg += "returned (" + str(ret) + ")" if ret > 0: error(msg) return 0 if ret < 0: warning(msg) else: info(msg) print('\n') # Run release generator info("###") msg = "### Running 'git bloom-generate -y release --src upstream'... " info(msg) info("###") generator = generators['release'] args.interactive = False release_args = copy.deepcopy(args) release_args.src = 'upstream' release_args.name = None ret = execute_generator(generator, release_args) msg += "returned (" + str(ret) + ")" if ret > 0: error(msg) return 0 if ret < 0: warning(msg) else: info(msg) print('\n') # Run given generator info("###") msg = "### Running 'git bloom-generate -y {0}'... ".format(args.generator) info(msg) info("###") generator = generators[args.generator] ret = execute_generator(generator, args) msg += "returned (" + str(ret) + ")" if ret > 0: error(msg) return 0 if ret < 0: warning(msg) else: info(msg) print('\n') # Undo log prefix pop_log_prefix() # Notify the user of success and next action suggestions print('\n\n') warning("Tip: Check to ensure that the debian tags created have the same " "version as the upstream version you are releasing.") info(ansi('greenf') + ansi('boldon') + "Everything went as expected, " "you should check that the new tags match your expectations, and " "then push to the release repo with:" + ansi('reset')) info(" git push --all && git push --tags # You might have to add --force to the second command if you are over-writing existing flags") return 0
def get_argument_parser(): parser = argparse.ArgumentParser(description="Checks for updates") add_global_arguments(parser) return parser