Add utils.create_package_stubs for debugging

This commit is contained in:
taoky 2024-09-04 00:26:05 +08:00
parent 40c9edba50
commit 7d78d998ba
2 changed files with 35 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.mypy_cache
__pycache__/
simple/
local.json
local.db

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
# This script is used to create EMPTY package files USED FOR DEBUG ONLY!
# It requires a full simple/ and db (genlocal-ed)
# Call like: python -m utils.create_package_stubs /path/to/pypi/
from shadowmire import LocalVersionKV, get_package_urls_size_from_index_json
from pathlib import Path
import sys
from tqdm import tqdm
from os.path import (
normpath,
) # fast path computation, instead of accessing real files like pathlib
if __name__ == "__main__":
pass
try:
repo = sys.argv[1]
except IndexError:
print("Please give repo basedir as argv[1].")
sys.exit(-1)
basedir = Path(repo).resolve()
local_db = LocalVersionKV(basedir / "local.db", basedir / "local.json")
local_names = set(local_db.keys())
simple_dir = basedir / "simple"
for package_name in tqdm(local_names, desc="Creating stub"):
package_simple_path = simple_dir / package_name
json_simple = package_simple_path / "index.v1_json"
hrefsize_json = get_package_urls_size_from_index_json(json_simple)
for href, _ in hrefsize_json:
dest = Path(normpath(package_simple_path / href))
dest.parent.mkdir(parents=True, exist_ok=True)
if not dest.exists():
dest.touch()