Commit 3b3cd906 authored by Thomas de Grenier de Latour's avatar Thomas de Grenier de Latour
Browse files

type=Path for --xxx-from args

parent a0814195
Loading
Loading
Loading
Loading
+19 −16
Original line number Diff line number Diff line
@@ -739,15 +739,14 @@ def dirname(path: Optional[str]) -> Optional[str]:
def to_url(api_url: str) -> str:
    return api_url[0:-7] if api_url.endswith("/api/v4") else api_url

def read_paths_list_from_file(file_path: str) -> list[str]:
def read_paths_list_from_file(file_path: Path) -> list[str]:
    # read a list of paths from a file (one per line), ignoring comments,
    # blank lines and leading/trailing spaces
    with open(file_path, "r") as f:
        lines = (line.partition('#')[0] for line in f)
        lines = [line.strip() for line in lines if line.strip()]
        return lines
        return [line.strip() for line in lines if line.strip()]

def simple_json_to_dict(json_str: str, source: str) -> dict[str,Union[int,str]]:
def simple_json_to_dict(json_str: str, source: Union[str,Path]) -> dict[str,Union[int,str]]:
    options = json.loads(json_str)
    assert (
        isinstance(options, (dict))
@@ -820,6 +819,7 @@ def run() -> None:
    parser.add_argument(
        "--exclude-from",
        default=os.getenv("EXCLUDE_FROM"),
        type=Path,
        help="a file which lists paths to exclude (one per line); incompatible with --exclude",
    )
    parser.add_argument(
@@ -831,6 +831,7 @@ def run() -> None:
    parser.add_argument(
        "--include-from",
        default=os.getenv("INCLUDE_FROM"),
        type=Path,
        help="a file which lists paths to include (one per line); incompatible with --include",
    )
    parser.add_argument(
@@ -871,6 +872,7 @@ def run() -> None:
    parser.add_argument(
        "--new-group-options-from",
        default=os.getenv("NEW_GROUP_OPTIONS_FROM"),
        type=Path,
        help="a JSON file with extra options for groups creation; incompatible with --new-group-options",
    )
    parser.add_argument(
@@ -881,6 +883,7 @@ def run() -> None:
    parser.add_argument(
        "--new-project-options-from",
        default=os.getenv("NEW_PROJECT_OPTIONS_FROM"),
        type=Path,
        help="a JSON file with extra options for projects creation; incompatible with --new-project-options",
    )
    parser.add_argument(
@@ -923,39 +926,39 @@ def run() -> None:
        not args.exclude or not args.exclude_from
    ), "Cannot use both --exclude and --exclude-from"
    assert (
        not args.exclude_from or Path(args.exclude_from).is_file()
    ), "No such file: " + args.exclude_from
        not args.exclude_from or args.exclude_from.is_file()
    ), f"No such file: {args.exclude_from}"
    assert (
        not args.include or not args.include_from
    ), "Cannot use both --include and --include-from"
    assert (
        not args.include_from or Path(args.include_from).is_file()
    ), "No such file: " + args.include_from
        not args.include_from or args.include_from.is_file()
    ), f"No such file: {args.include_from}"
    assert (
        not args.new_group_options or not args.new_group_options_from
    ), "Cannot use both --new-group-options and --new-group-options-from"
    assert (
        not args.new_group_options_from or Path(args.new_group_options_from).is_file()
    ), "No such file: " + args.new_group_options_from
        not args.new_group_options_from or args.new_group_options_from.is_file()
    ), f"No such file: {args.new_group_options_from}"
    assert (
        not args.new_project_options or not args.new_project_options_from
    ), "Cannot use both --new-project-options and --new-project-options-from"
    assert (
        not args.new_project_options_from or Path(args.new_project_options_from).is_file()
    ), "No such file: " + args.new_project_options_from
        not args.new_project_options_from or args.new_project_options_from.is_file()
    ), f"No such file: {args.new_project_options_from}"

    new_group_options = {}
    new_group_options: dict[str, Union[int,str]] = {}
    if args.new_group_options:
        new_group_options = simple_json_to_dict(args.new_group_options, "--new-group-options")
    elif args.new_group_options_from:
        new_group_options = simple_json_to_dict(Path(args.new_group_options_from).read_text(), args.new_group_options_from)
        new_group_options = simple_json_to_dict(args.new_group_options_from.read_text(), str(args.new_group_options_from))

    # default options for new project: disable issues and MR
    new_project_options = { "issues_access_level": "disabled", "merge_requests_access_level": "disabled" }
    new_project_options: dict[str, Union[int,str]] = { "issues_access_level": "disabled", "merge_requests_access_level": "disabled" }
    if args.new_project_options:
        new_project_options = simple_json_to_dict(args.new_project_options, "--new-project-options")
    elif args.new_project_options_from:
        new_project_options = simple_json_to_dict(Path(args.new_project_options_from).read_text(), args.new_project_options_from)
        new_project_options = simple_json_to_dict(args.new_project_options_from.read_text(), args.new_project_options_from)

    exclude_list = []
    if args.exclude: