WiP first version

This commit is contained in:
Jakub Kropáček 2024-05-25 23:43:15 +02:00
parent e511027a7d
commit 10f748a6cc
7 changed files with 81 additions and 1 deletions

0
many_repos/__init__.py Normal file
View file

29
many_repos/clone.py Normal file
View file

@ -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())

9
many_repos/common.py Normal file
View file

@ -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`).',
)

25
many_repos/config.py Normal file
View file

@ -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")})

3
many_repos/errors.py Normal file
View file

@ -0,0 +1,3 @@
class ConfigNotFound(Exception):
"Raised when non-existing config was tried to be used"
pass

7
poetry.lock generated Normal file
View file

@ -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"

View file

@ -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 <kropikuba@gmail.com>"]
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"