def test_cfg_unknown_format(self): """Test that a runtime error is raised when an unknown format string is received """ with self.assertRaises(RuntimeError): create_externals_description(self._config, model_format='unknown')
def test_cfg_unknown_version(self): """Test that a runtime error is raised when an unknown file version is received """ self._config.set(DESCRIPTION_SECTION, VERSION_ITEM, '123.456.789') with self.assertRaises(RuntimeError): create_externals_description(self._config, model_format='cfg')
def test_cfg_v1_unknown_version(self): """Test that a config file with unknown schema version is rejected by create_externals_description. """ self._config.set(DESCRIPTION_SECTION, VERSION_ITEM, '100.0.3') with self.assertRaises(RuntimeError): create_externals_description(self._config, model_format='cfg')
def test_cfg_v1_ok(self): """Test that a correct cfg v1 object is created by create_externals_description """ self._config.set(DESCRIPTION_SECTION, VERSION_ITEM, '1.0.3') ext = create_externals_description(self._config, model_format='cfg') self.assertIsInstance(ext, ExternalsDescriptionConfigV1)
def test_cfg_component_dict(self): """Verify that create_externals_description works with a dictionary """ # create the top level externals file desc = self.setup_dict_config() # Check external with all repos external = create_externals_description(desc, model_format='dict') self.assertIsInstance(external, ExternalsDescriptionDict) self.assertTrue('simp_tag' in external) self.assertTrue('simp_branch' in external) self.assertTrue('simp_opt' in external) self.assertTrue('mixed_req' in external)
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
def test_cfg_opt_component_dict(self): """Verify that exclude component checkout works with a dictionary """ # create the top level externals file desc = self.setup_dict_config() # Test an excluded repo external = create_externals_description(desc, model_format='dict', components=['simp_tag', 'simp_opt']) self.assertIsInstance(external, ExternalsDescriptionDict) self.assertTrue('simp_tag' in external) self.assertFalse('simp_branch' in external) self.assertTrue('simp_opt' in external) self.assertFalse('mixed_req' in external)
def test_dict(self): """Test that a correct cfg v1 object is created by create_externals_description """ rdata = {ExternalsDescription.PROTOCOL: 'git', ExternalsDescription.REPO_URL: '/path/to/repo', ExternalsDescription.TAG: 'tagv1', } desc = { 'test': { ExternalsDescription.REQUIRED: False, ExternalsDescription.PATH: '../fake', ExternalsDescription.EXTERNALS: EMPTY_STR, ExternalsDescription.REPO: rdata, }, } ext = create_externals_description(desc, model_format='dict') self.assertIsInstance(ext, ExternalsDescriptionDict)
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