mirror of
https://github.com/taoky/shadowmire.git
synced 2025-07-11 20:08:50 +00:00
Set repo with argument/config (no longer use env)
This commit is contained in:
@ -35,10 +35,10 @@ Obviously, `list_packages_with_serial()`'s alternative is the `local.json`, whic
|
|||||||
If you just need to fetch all indexes (and then use a cache solution for packages):
|
If you just need to fetch all indexes (and then use a cache solution for packages):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
REPO=/path/to/pypi ./shadowmire.py sync
|
./shadowmire.py --repo /path/to/pypi sync
|
||||||
```
|
```
|
||||||
|
|
||||||
If `REPO` env is not set, it defaults to current working directory.
|
If `--repo` argument is not set, it defaults to current working directory.
|
||||||
|
|
||||||
If you need to download all packages, add `--sync-packages`.
|
If you need to download all packages, add `--sync-packages`.
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
[options]
|
[options]
|
||||||
|
# repo = "/example/path"
|
||||||
sync_packages = true
|
sync_packages = true
|
||||||
# shadowmire_upstream = http://example.com/pypi/web/
|
# shadowmire_upstream = "http://example.com/pypi/web/"
|
||||||
exclude = [
|
exclude = [
|
||||||
"[a-z]"
|
"[a-z]"
|
||||||
]
|
]
|
||||||
|
@ -900,6 +900,10 @@ def sync_shared_args(func: Callable[..., Any]) -> Callable[..., Any]:
|
|||||||
def read_config(
|
def read_config(
|
||||||
ctx: click.Context, param: click.Option, filename: Optional[str]
|
ctx: click.Context, param: click.Option, filename: Optional[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
|
# Set default repo as cwd
|
||||||
|
ctx.default_map = {}
|
||||||
|
ctx.default_map["repo"] = "."
|
||||||
|
|
||||||
if filename is None:
|
if filename is None:
|
||||||
return
|
return
|
||||||
with open(filename, "rb") as f:
|
with open(filename, "rb") as f:
|
||||||
@ -908,12 +912,14 @@ def read_config(
|
|||||||
options = dict(data["options"])
|
options = dict(data["options"])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
options = {}
|
options = {}
|
||||||
ctx.default_map = {
|
if options.get("repo"):
|
||||||
"sync": options,
|
ctx.default_map["repo"] = options["repo"]
|
||||||
"verify": options,
|
del options["repo"]
|
||||||
"do-update": options,
|
|
||||||
"do-remove": options,
|
ctx.default_map["sync"] = options
|
||||||
}
|
ctx.default_map["verify"] = options
|
||||||
|
ctx.default_map["do-update"] = options
|
||||||
|
ctx.default_map["do-remove"] = options
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@ -924,8 +930,9 @@ def read_config(
|
|||||||
callback=read_config,
|
callback=read_config,
|
||||||
expose_value=False,
|
expose_value=False,
|
||||||
)
|
)
|
||||||
|
@click.option("--repo", type=click.Path(file_okay=False), help="Repo (basedir) path")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(ctx: click.Context) -> None:
|
def cli(ctx: click.Context, repo: str) -> None:
|
||||||
log_level = logging.DEBUG if os.environ.get("DEBUG") else logging.INFO
|
log_level = logging.DEBUG if os.environ.get("DEBUG") else logging.INFO
|
||||||
logging.basicConfig(level=log_level)
|
logging.basicConfig(level=log_level)
|
||||||
ctx.ensure_object(dict)
|
ctx.ensure_object(dict)
|
||||||
@ -937,7 +944,7 @@ def cli(ctx: click.Context) -> None:
|
|||||||
logger.warning("Don't blame me if you were banned!")
|
logger.warning("Don't blame me if you were banned!")
|
||||||
|
|
||||||
# Make sure basedir is absolute
|
# Make sure basedir is absolute
|
||||||
basedir = Path(os.environ.get("REPO", ".")).resolve()
|
basedir = Path(repo).resolve()
|
||||||
local_db = LocalVersionKV(basedir / "local.db", basedir / "local.json")
|
local_db = LocalVersionKV(basedir / "local.db", basedir / "local.json")
|
||||||
|
|
||||||
ctx.obj["basedir"] = basedir
|
ctx.obj["basedir"] = basedir
|
||||||
|
Reference in New Issue
Block a user