def execute_cmd_in_dir(under_test_dir, args): """Extecute the checkout command in the appropriate repo dir with the specified additional args Note that we are calling the command line processing and main routines and not using a subprocess call so that we get code coverage results! """ cwd = os.getcwd() checkout_path = os.path.abspath('{0}/../../checkout_externals') os.chdir(under_test_dir) cmdline = [ '--externals', CFG_NAME, ] cmdline += args repo_root = 'MANIC_TEST_BARE_REPO_ROOT={root}'.format( root=os.environ[MANIC_TEST_BARE_REPO_ROOT]) manual_cmd = ('Test cmd:\npushd {cwd}; {env} {checkout} {args}'.format( cwd=under_test_dir, env=repo_root, checkout=checkout_path, args=' '.join(cmdline))) printlog(manual_cmd) options = checkout.commandline_arguments(cmdline) overall_status, tree_status = checkout.main(options) os.chdir(cwd) return overall_status, tree_status
def main(args): """ Function to call when module is called from the command line. Parse externals file and load required repositories or all repositories if the --all option is passed. """ if not args.no_logging: logging.basicConfig(filename=LOG_FILE_NAME, format='%(levelname)s : %(asctime)s : %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.DEBUG) program_name = os.path.basename(sys.argv[0]) logging.info('Beginning of %s', program_name) load_all = False if args.optional: load_all = True root_dir = os.path.abspath(os.getcwd()) external_data = read_externals_description_file(root_dir, args.externals) external = create_externals_description(external_data) source_tree = SourceTree(root_dir, external) printlog('Checking status of externals: ', end='') tree_status = source_tree.status() printlog('') if args.status: # user requested status-only for comp in sorted(tree_status.keys()): tree_status[comp].log_status_message(args.verbose) else: # checkout / update the external repositories. safe_to_update = check_safe_to_update_repos(tree_status) if not safe_to_update: # print status for comp in sorted(tree_status.keys()): tree_status[comp].log_status_message(args.verbose) # exit gracefully msg = """The external repositories labeled with 'M' above are not in a clean state. The following are two options for how to proceed: (1) Go into each external that is not in a clean state and issue either an 'svn status' or a 'git status' command. Either revert or commit your changes so that all externals are in a clean state. (Note, though, that it is okay to have untracked files in your working directory.) Then rerun {program_name}. (2) Alternatively, you do not have to rely on {program_name}. Instead, you can manually update out-of-sync externals (labeled with 's' above) as described in the configuration file {config_file}. """.format(program_name=program_name, config_file=args.externals) printlog('-' * 70) printlog(msg) printlog('-' * 70) else: source_tree.checkout(args.verbose, load_all) printlog('') logging.info('%s completed without exceptions.', program_name) # NOTE(bja, 2017-11) tree status is used by the systems tests return 0, tree_status
def main(args): """ Function to call when module is called from the command line. Parse externals file and load required repositories or all repositories if the --all option is passed. Returns a tuple (overall_status, tree_status). overall_status is 0 on success, non-zero on failure. tree_status gives the full status *before* executing the checkout command - i.e., the status that it used to determine if it's safe to proceed with the checkout. """ if args.do_logging: logging.basicConfig(filename=LOG_FILE_NAME, format='%(levelname)s : %(asctime)s : %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.DEBUG) program_name = os.path.basename(sys.argv[0]) logging.info('Beginning of %s', program_name) load_all = False if args.optional: load_all = True root_dir = os.path.abspath(os.getcwd()) external_data = read_externals_description_file(root_dir, args.externals) external = create_externals_description( external_data, components=args.components, exclude=args.exclude) for comp in args.components: if comp not in external.keys(): fatal_error( "No component {} found in {}".format( comp, args.externals)) source_tree = SourceTree(root_dir, external, svn_ignore_ancestry=args.svn_ignore_ancestry) printlog('Checking status of externals: ', end='') tree_status = source_tree.status() printlog('') if args.status: # user requested status-only for comp in sorted(tree_status.keys()): tree_status[comp].log_status_message(args.verbose) else: # checkout / update the external repositories. safe_to_update = check_safe_to_update_repos(tree_status) if not safe_to_update: # print status for comp in sorted(tree_status.keys()): tree_status[comp].log_status_message(args.verbose) # exit gracefully msg = """The external repositories labeled with 'M' above are not in a clean state. The following are two options for how to proceed: (1) Go into each external that is not in a clean state and issue either an 'svn status' or a 'git status' command. Either revert or commit your changes so that all externals are in a clean state. (Note, though, that it is okay to have untracked files in your working directory.) Then rerun {program_name}. (2) Alternatively, you do not have to rely on {program_name}. Instead, you can manually update out-of-sync externals (labeled with 's' above) as described in the configuration file {config_file}. The external repositories labeled with '?' above are not under version control using the expected protocol. If you are sure you want to switch protocols, and you don't have any work you need to save from this directory, then run "rm -rf [directory]" before re-running the checkout_externals tool. """.format(program_name=program_name, config_file=args.externals) printlog('-' * 70) printlog(msg) printlog('-' * 70) else: if not args.components: source_tree.checkout(args.verbose, load_all) for comp in args.components: source_tree.checkout(args.verbose, load_all, load_comp=comp) printlog('') logging.info('%s completed without exceptions.', program_name) # NOTE(bja, 2017-11) tree status is used by the systems tests return 0, tree_status
def main(args): """ Function to call when module is called from the command line. Parse externals file and load required repositories or all repositories if the --all option is passed. Returns a tuple (overall_status, tree_status). overall_status is 0 on success, non-zero on failure. tree_status gives the full status *before* executing the checkout command - i.e., the status that it used to determine if it's safe to proceed with the checkout. """ if args.do_logging: logging.basicConfig(filename=LOG_FILE_NAME, format='%(levelname)s : %(asctime)s : %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.DEBUG) program_name = os.path.basename(sys.argv[0]) logging.info('Beginning of %s', program_name) load_all = False if args.optional: load_all = True root_dir = os.path.abspath(os.getcwd()) external_data = read_externals_description_file(root_dir, args.externals) external = create_externals_description( external_data, components=args.components) for comp in args.components: if comp not in external.keys(): fatal_error( "No component {} found in {}".format( comp, args.externals)) source_tree = SourceTree(root_dir, external) printlog('Checking status of externals: ', end='') tree_status = source_tree.status() printlog('') if args.status: # user requested status-only for comp in sorted(tree_status.keys()): tree_status[comp].log_status_message(args.verbose) else: # checkout / update the external repositories. safe_to_update = check_safe_to_update_repos(tree_status) if not safe_to_update: # print status for comp in sorted(tree_status.keys()): tree_status[comp].log_status_message(args.verbose) # exit gracefully msg = """The external repositories labeled with 'M' above are not in a clean state. The following are two options for how to proceed: (1) Go into each external that is not in a clean state and issue either an 'svn status' or a 'git status' command. Either revert or commit your changes so that all externals are in a clean state. (Note, though, that it is okay to have untracked files in your working directory.) Then rerun {program_name}. (2) Alternatively, you do not have to rely on {program_name}. Instead, you can manually update out-of-sync externals (labeled with 's' above) as described in the configuration file {config_file}. The external repositories labeled with '?' above are not under version control using the expected protocol. If you are sure you want to switch protocols, and you don't have any work you need to save from this directory, then run "rm -rf [directory]" before re-running the checkout_externals tool. """.format(program_name=program_name, config_file=args.externals) printlog('-' * 70) printlog(msg) printlog('-' * 70) else: if not args.components: source_tree.checkout(args.verbose, load_all) for comp in args.components: source_tree.checkout(args.verbose, load_all, load_comp=comp) printlog('') logging.info('%s completed without exceptions.', program_name) # NOTE(bja, 2017-11) tree status is used by the systems tests return 0, tree_status
def main(args): """ Function to call when module is called from the command line. Parse externals file and load required repositories or all repositories if the --all option is passed. """ logging.info('Begining of checkout_externals') load_all = False if args.optional: load_all = True root_dir = os.path.abspath(os.getcwd()) external_data = read_externals_description_file(root_dir, args.externals) external = create_externals_description(external_data) source_tree = SourceTree(root_dir, external) printlog('Checking status of externals: ', end='') tree_status = source_tree.status() printlog('') if args.status: # user requested status-only for comp in sorted(tree_status.keys()): msg = str(tree_status[comp]) printlog(msg) if args.verbose: # user requested verbose status dump of the git/svn status commands source_tree.verbose_status() else: # checkout / update the external repositories. safe_to_update = check_safe_to_update_repos(tree_status) if not safe_to_update: # print status for comp in sorted(tree_status.keys()): msg = str(tree_status[comp]) printlog(msg) # exit gracefully msg = textwrap.fill( 'Some external repositories that are not in a clean ' 'state. Please ensure all external repositories are clean ' 'before updating.') printlog('-' * 70) printlog(msg) printlog('-' * 70) else: source_tree.checkout(load_all) printlog('') logging.info('checkout_externals completed without exceptions.') # NOTE(bja, 2017-11) tree status is used by the systems tests return 0, tree_status