def test_no_file_error(self):
        """Test that a runtime error is raised when the file does not exist

        """
        root_dir = os.getcwd()
        filename = 'this-file-should-not-exist'
        with self.assertRaises(RuntimeError):
            read_externals_description_file(root_dir, filename)
    def test_no_dir_error(self):
        """Test that a runtime error is raised when the file does not exist

        """
        root_dir = '/path/to/some/repo'
        filename = 'externals.cfg'
        with self.assertRaises(RuntimeError):
            read_externals_description_file(root_dir, filename)
Ejemplo n.º 3
0
    def test_no_dir_error(self):
        """Test that a runtime error is raised when the file does not exist

        """
        root_dir = '/path/to/some/repo'
        filename = 'externals.cfg'
        with self.assertRaises(RuntimeError):
            read_externals_description_file(root_dir, filename)
Ejemplo n.º 4
0
    def test_no_file_error(self):
        """Test that a runtime error is raised when the file does not exist

        """
        root_dir = os.getcwd()
        filename = 'this-file-should-not-exist'
        with self.assertRaises(RuntimeError):
            read_externals_description_file(root_dir, filename)
    def test_no_invalid_error(self):
        """Test that a runtime error is raised when the file format is invalid

        """
        root_dir = os.getcwd()
        filename = 'externals.cfg'
        file_path = os.path.join(root_dir, filename)
        file_path = os.path.abspath(file_path)
        contents = """
<source_tree version='1.0.0'>
invalid file format
</sourc_tree>"""
        with open(file_path, 'w') as fhandle:
            fhandle.write(contents)
        with self.assertRaises(RuntimeError):
            read_externals_description_file(root_dir, filename)
        os.remove(file_path)
Ejemplo n.º 6
0
    def test_no_invalid_error(self):
        """Test that a runtime error is raised when the file format is invalid

        """
        root_dir = os.getcwd()
        filename = 'externals.cfg'
        file_path = os.path.join(root_dir, filename)
        file_path = os.path.abspath(file_path)
        contents = """
<source_tree version='1.0.0'>
invalid file format
</sourc_tree>"""
        with open(file_path, 'w') as fhandle:
            fhandle.write(contents)
        with self.assertRaises(RuntimeError):
            read_externals_description_file(root_dir, filename)
        os.remove(file_path)
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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