def check_config_version():  # noqa
    if not _shared_config_dir():
        return

    original_file = os.path.join(_shared_config_dir(), "config.yaml")
    if not os.path.exists(original_file):
        return

    original_version = _get_root_config_field(original_file, "version")
    if not original_version:
        sys.stderr.write("No version found in original file %s\n" % original_file)
        return

    copied_file = os.path.join(Paths().config_dir(), "config.yaml")
    copied_version = _get_root_config_field(copied_file, "version")
    if not copied_version:
        sys.stderr.write("No version found in user managed file %s\n" % copied_file)
        return

    if _partial_sem_version(copied_version) < _partial_sem_version(original_version):
        sys.stdout.write(
            bordered(
                'Configuration needs update (%s < %s). Tip: use "dodo diff ."\n'
                % (
                    copied_version,
                    original_version,
                )
            )
        )
        sys.stdout.write("\n")
def check_setuptools():
    if not Dodo.run([_python_path(), "-c", "import setuptools"]):
        _report_error("\n" + bordered(
            "Error: your python version does not have setuptools installed.\n"
            + "Check the settings.python option in %s" %
            Paths().global_config_filename()))
        sys.exit(1)
def check_config_changes():  # noqa
    if os.path.exists(os.path.join(Paths().config_dir(), ".git")):
        with local.cwd(Paths().config_dir()):
            changes = local["git"]("status", "--short")
            if changes:
                sys.stdout.write(
                    bordered(
                        'Configuration has changes (tip: use "dodo commit-config"):\n'
                        + changes
                    )
                )
                sys.stdout.write("\n")
def check_dodo_commands_version():  # noqa
    required_version = _get_root_config_field(
        _config_filename(), "required_dodo_commands_version"
    )
    if required_version:
        actual_version = get_version()
        if Version(actual_version) < Version(required_version):
            sys.stdout.write(
                bordered(
                    'The dodo_commands package needs to be upgraded (%s < %s). Tip: use "dodo upgrade"'
                    % (
                        actual_version,
                        required_version,
                    ),
                )
            )
            sys.stdout.write("\n")
from dodo_commands import Dodo
from dodo_commands.framework.util import bordered


def _args():
    parser = ArgumentParser()
    parser.add_argument('--checkout')
    parser.add_argument('--prune', action='store_true')
    args = Dodo.parse_args(parser)
    return args


if Dodo.is_main(__name__):
    args = _args()
    src_dir = Dodo.get_config('/ROOT/src_dir')
    for repo in (os.listdir(src_dir) + ['.']):
        repo_dir = os.path.join(src_dir, repo)
        if os.path.exists(os.path.join(repo_dir, '.git')):
            with local.cwd(repo_dir):
                if args.prune:
                    print(git('remote', 'prune', 'origin'))

                print(bordered(repo))
                if args.checkout:
                    try:
                        git('checkout', args.checkout)
                    except:
                        print('Could not checkout to %s' % args.checkout)
                        pass
                print(git('rev-parse', '--abbrev-ref', 'HEAD'))