Example #1
0
def push(resync: bool):
    monorepo = read_monorepo_config()

    for folder_name, repo_location in monorepo.repos.items():
        if is_repo_unchanged(monorepo, folder_name) and not resync:
            print(
                green(repo_location, bold=True),
                green("->"),
                green(folder_name, bold=True),
                green("UNCHANGED", bold=True),
            )
            continue

        print(
            yellow(repo_location, bold=True),
            yellow("->"),
            yellow(folder_name, bold=True),
            yellow("PUSH", bold=True),
        )

        initial_commit = get_current_commit(
            project_folder=monorepo.project_folder)
        push_monorepo_project(monorepo, folder_name, repo_location)

        current_commit = get_current_commit(
            project_folder=monorepo.project_folder)

        # we need to update the last commit file with the new value
        # the commit is the current_commit, since this is already pushed
        write_synchronized_commits(monorepo,
                                   repo=folder_name,
                                   commit=current_commit)
Example #2
0
def main(fname):
    direction_map = load_input(fname)

    print("The Answer to Part A is: {}".format(tc.green(
        part_a(direction_map))))

    processing_time = (datetime.datetime.now() -
                       start_time).total_seconds() * 1000
    print("Time taken to get answer: {:.3f} ms".format(processing_time))

    print("The Answer to Part B is: {}".format(tc.green(
        part_b(direction_map))))

    processing_time = (datetime.datetime.now() -
                       start_time).total_seconds() * 1000
    print("Time taken to get answer: {:.3f} ms".format(processing_time))
Example #3
0
def validate_folders_to_update(
    monorepo: GitMonorepoConfig, folders: List[str], required: bool
) -> None:
    pull_folders = set(folders)
    pull_folders.difference_update(monorepo.repos)
    if pull_folders:
        print(
            red("Error:"),
            red(", ".join(pull_folders), bold=True),
            red("not found in monorepo projects."),
        )
        sys.exit(1)

    if not folders and required:
        print(green("Nothing changed locally.", bold=True), green("Nothing to do."))
        sys.exit(0)
Example #4
0
def list_folder(file_resolver: FileResolver) -> None:
    for entry in file_resolver.listdir():
        if entry.is_dir:
            print(
                blue(entry.name, bold=True) +
                gray(f" ({entry.owning_project})", bold=True))
        elif entry.is_exe:
            print(
                green(entry.name, bold=True) +
                gray(f" ({entry.owning_project})", bold=True))
        else:
            print(entry.name + gray(f" ({entry.owning_project})", bold=True))
Example #5
0
def display_current_folder(file_resolver: FileResolver,
                           indent: int = 0) -> None:
    for entry in file_resolver.listdir():
        if entry.is_dir:
            print("  " * indent + blue(entry.name, bold=True) +
                  gray(f" ({entry.owning_project})", bold=True))
            display_current_folder(file_resolver.subentry(entry), indent + 1)
        elif entry.is_exe:
            print("  " * indent + green(entry.name, bold=True) +
                  gray(f" ({entry.owning_project})", bold=True))
        else:
            print("  " * indent + entry.name +
                  gray(f" ({entry.owning_project})", bold=True))
Example #6
0
def green(text: str, bold=False, underline=False) -> str:
    if not config.current.boolean.color:
        return text

    return termcolor_util.green(text, bold=bold, underline=underline)
Example #7
0
def main() -> None:
    colorama.init()

    parser = argparse.ArgumentParser(description='Versions processor')

    parser.add_argument(
        '--display',
        '-d',
        metavar='NAME',
        nargs=1,
        help='Display the version of a single tracked version.')
    parser.add_argument(
        '--all',
        '-a',
        '--list',
        action='store_true',
        help='Display all the tracked versions and their values.')
    parser.add_argument('--set',
                        '-s',
                        nargs='+',
                        metavar="NAME=VAL",
                        help='Set values overriding what\'s in the yml files.')
    parser.add_argument('--load',
                        '-l',
                        metavar="FILE",
                        help='Override versions from the given yml file.')
    parser.add_argument(
        '-t',
        '--tag-name',
        '--tag',
        action='store_true',
        help="Get the current name to use in general tags. If the "
        "branch name can't be detected from the git repo, the "
        "$BRANCH_NAME environment variable will be used.")
    parser.add_argument(
        '--ignore-missing-parents',
        action='store_true',
        help="Ignore missing parents, and simply don't patch the "
        "values. Upstream values are still being patched if existing.")
    parser.add_argument(
        '--version',
        action='store_true',
        help='Show the currently installed program version (master)')

    argv: ProgramArguments = cast(ProgramArguments,
                                  parser.parse_args(sys.argv[1:]))

    if argv.version:
        print(cyan("version-manager: master"))
        sys.exit(0)

    if argv.tag_name:
        print_current_tag_version()
        sys.exit(0)

    default_settings_file = path.realpath(
        path.join(os.getcwd(), 'versions.json'))
    override_parameters = get_parameters_from_file(argv.load)
    override_parameters = get_parameter_values(override_parameters, argv.set)
    versions_to_process = read_settings_file(default_settings_file,
                                             override_parameters,
                                             argv.ignore_missing_parents)

    # Display a single tracked version
    if argv.display:
        print_single_tracked_version(argv.display[0], versions_to_process)
        sys.exit(0)

    # Display all tracked versions.
    if argv.all:
        print_all_tracked_versions(versions_to_process)
        sys.exit(0)

    eprint(cyan("Running on %s" % sys.version))

    files_to_process: Dict[str, List[Pattern]] = dict()

    for tracked_version in versions_to_process:
        for file_name, version_pattern in tracked_version.files.items():
            resolved_names = glob.glob(file_name)

            if not resolved_names:
                print(red('Unable to find any files for glob %s.' % file_name))
                sys.exit(2)

            for resolved_name in resolved_names:
                if resolved_name in files_to_process:
                    file_patterns = files_to_process[resolved_name]
                else:
                    file_patterns = []
                    files_to_process[resolved_name] = file_patterns

                file_patterns.append(version_pattern)

    for resolved_name, version_patterns in files_to_process.items():
        with open(resolved_name, 'r', encoding='utf-8') as resolved_file:
            content = resolved_file.read()
            new_content = content

        print(cyan("Patching %s:" % resolved_name))

        for version_pattern in version_patterns:
            tracked_version = version_pattern.tracked_version
            print(
                green('* %s@%s' %
                      (tracked_version.name, tracked_version.version)))

            new_content = version_pattern.apply_pattern(new_content)

            if version_pattern.match_count != version_pattern.expected_count:
                print(
                    red('Got %d matches instead of %d.' %
                        (version_pattern.match_count,
                         version_pattern.expected_count)))
                sys.exit(3)

        if content == new_content:
            print(
                cyan("Content for %s is not changed. Won't patch it." %
                     resolved_name))
            continue

        with open(resolved_name, 'w', encoding='utf-8') as output:
            output.write(new_content)

        print(yellow('Updated %s' % resolved_name))

    colorama.deinit()
    sys.exit(0)
Example #8
0
def list_folder_in_project(
    projects_folder: str,
    folder_to_list: str,
    loaded_project_parameters: Optional[Dict[str, Union[str, List[str]]]],
) -> None:
    # While it's possible to have multiple templates in the project, when listing the
    # current folder, only the first template will be used.

    if not loaded_project_parameters:
        print(red("Unable to find a project. .ars file is missing."))
        sys.exit(1)

    if "templates" not in loaded_project_parameters:
        print(red("The .ars file doesn't contain any templates."))
        sys.exit(2)

    if not loaded_project_parameters["templates"]:
        print(red("The .ars file templates section is empty."))
        sys.exit(3)

    project_name = loaded_project_parameters["templates"][0]

    project_definition: ProjectDefinition = read_project_definition(
        projects_folder, project_name)
    path_mappings: Dict[str, FileEntry] = dict()
    process_folder(
        folder_to_list,
        project_definition.file_resolver().subentry(path=folder_to_list),
        loaded_project_parameters,
        path_mappings,
    )

    local_files = os.listdir(folder_to_list)

    def is_dir(name: str) -> bool:
        return os.path.isdir(os.path.join(folder_to_list, name))

    local_files.sort(key=lambda it: (not is_dir(it), it.lower()))

    for file in local_files:
        local_path_name = os.path.normpath(os.path.join(folder_to_list, file))
        if local_path_name in path_mappings:
            file_entry = path_mappings[local_path_name]

            if file_entry.is_dir:
                print(
                    blue(file, bold=True),
                    gray(f"({file_entry.owning_project})", bold=True),
                )
            elif file_entry.is_exe:
                print(
                    green(file, bold=True),
                    gray(f"({file_entry.owning_project})", bold=True),
                )
            else:
                print(file, gray(f"({file_entry.owning_project})", bold=True))
        else:
            if os.path.isdir(local_path_name):
                print(blue(file, bold=True), red(f"(local)", bold=False))
            elif os.access(local_path_name, os.X_OK):
                print(green(file, bold=True), red(f"(local)", bold=False))
            else:
                print(file, red(f"(local)", bold=False))