From 10f748a6cc31aabbf916172adde8f0c972c3b148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Krop=C3=A1=C4=8Dek?= Date: Sat, 25 May 2024 23:43:15 +0200 Subject: [PATCH] WiP first version --- many_repos/__init__.py | 0 many_repos/clone.py | 29 +++++++++++++++++++++++++++++ many_repos/common.py | 9 +++++++++ many_repos/config.py | 25 +++++++++++++++++++++++++ many_repos/errors.py | 3 +++ poetry.lock | 7 +++++++ pyproject.toml | 9 ++++++++- 7 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 many_repos/__init__.py create mode 100644 many_repos/clone.py create mode 100644 many_repos/common.py create mode 100644 many_repos/config.py create mode 100644 many_repos/errors.py create mode 100644 poetry.lock diff --git a/many_repos/__init__.py b/many_repos/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/many_repos/clone.py b/many_repos/clone.py new file mode 100644 index 0000000..b105c69 --- /dev/null +++ b/many_repos/clone.py @@ -0,0 +1,29 @@ +import argparse + +from typing import Sequence + +from many_repos.config import load_config +from many_repos import common + +def _add_specific_args(parser: argparse.ArgumentParser): + parser.add_argument("-s", "--source", action="append") + + +def main(argv: Sequence[str] | None = None) -> int: + parser = argparse.ArgumentParser( + description=( + "Clone all repositores into `output_dir` from every source, unless specified " + "otherwise using one or multiple `--source SOURCE` / `-s SOURCE` ." + ) + ) + + _add_specific_args(parser) + common.add_common_args(parser) + + args = parser.parse_args(argv) + + config = load_config(args.config_filename) + return 0 + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/many_repos/common.py b/many_repos/common.py new file mode 100644 index 0000000..d57d430 --- /dev/null +++ b/many_repos/common.py @@ -0,0 +1,9 @@ +import argparse +import os + +def add_common_args(parser: argparse.ArgumentParser): + parser.add_argument( + '-C', '--config-filename', + default=os.getenv("MANY_REPOS_CONFIG_PATH") or "repos.toml", + help='use a non-default config file (default `%(default)s`).', + ) diff --git a/many_repos/config.py b/many_repos/config.py new file mode 100644 index 0000000..f157755 --- /dev/null +++ b/many_repos/config.py @@ -0,0 +1,25 @@ +import tomllib + +from pathlib import Path +from typing import NamedTuple + +from many_repos import errors + +class Source(NamedTuple): + source_type: str + username: str + token: str + +class Config(NamedTuple): + output_dir: str | Path + sources: dict[str, Source] | None + +def load_config(config_path: str | Path) -> Config: + config_path = Path(config_path) + if not config_path.exists(): + raise errors.ConfigNotFound(f"Config at path {config_path} not found!") + + with config_path.open() as fp: + parsed_config = tomllib.load(fp) + + return Config(output_dir="~/repos/", sources={"gitlab": Source(source_type="gitlab", username="justscreamy", token="urgay")}) diff --git a/many_repos/errors.py b/many_repos/errors.py new file mode 100644 index 0000000..50efe62 --- /dev/null +++ b/many_repos/errors.py @@ -0,0 +1,3 @@ +class ConfigNotFound(Exception): + "Raised when non-existing config was tried to be used" + pass diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..1034779 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +package = [] + +[metadata] +lock-version = "2.0" +python-versions = "^3.12" +content-hash = "34e39677d8527182346093002688d17a5d2fc204b9eb3e094b2e6ac519028228" diff --git a/pyproject.toml b/pyproject.toml index 384f452..737d05e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,17 @@ [tool.poetry] name = "many-repos" version = "0.1.0" -description = "Simple tool to clone and update all your repositories between many version control systems, with simple toml config" +description = "Simple tool to manage your local repositories." authors = ["Jakub Kropáček "] license = "MIT" readme = "README.md" +homepage = "https://gitlab.com/JustScreaMy/many-repos" +packages = [ + { include = "many_repos" }, +] + +[tool.poetry.scripts] +many-repos-clone = "many_repos.clone:main" [tool.poetry.dependencies] python = "^3.12"