Make simple/<package>/index.html symlink to index.v1_html

Closes: #1
This commit is contained in:
taoky 2024-08-10 19:32:34 +08:00
parent a913965c22
commit b5fca47101

View File

@ -621,7 +621,7 @@ class SyncBase:
def write_meta_to_simple(self, package_simple_path: Path, meta: dict) -> None:
simple_html_contents = PyPI.generate_html_simple_page(meta)
simple_json_contents = PyPI.generate_json_simple_page(meta)
for html_filename in ("index.html", "index.v1_html"):
for html_filename in ("index.v1_html",):
html_path = package_simple_path / html_filename
with overwrite(html_path) as f:
f.write(simple_html_contents)
@ -629,6 +629,11 @@ class SyncBase:
json_path = package_simple_path / json_filename
with overwrite(json_path) as f:
f.write(simple_json_contents)
index_html_path = package_simple_path / "index.html"
if not index_html_path.is_symlink():
if index_html_path.exists():
index_html_path.unlink()
index_html_path.symlink_to("index.v1_html")
def finalize(self) -> None:
local_names = self.local_db.keys()
@ -1051,7 +1056,9 @@ def genlocal(ctx: click.Context) -> None:
serial = get_local_serial(package_metapath)
if serial:
local[package_name] = serial
logger.info("%d out of %d packages have valid serial number", len(local), len(dir_items))
logger.info(
"%d out of %d packages have valid serial number", len(local), len(dir_items)
)
local_db.nuke(commit=False)
local_db.batch_set(local)
local_db.dump_json()
@ -1093,7 +1100,11 @@ def verify(
simple_dirs = {i.name for i in (basedir / "simple").iterdir() if i.is_dir()}
json_files = {i.name for i in (basedir / "json").iterdir() if i.is_file()}
not_in_local = (simple_dirs | json_files) - local_names
logger.info("%d out of %d local packages NOT in local db", len(not_in_local), len(local_names))
logger.info(
"%d out of %d local packages NOT in local db",
len(not_in_local),
len(local_names),
)
for package_name in not_in_local:
logger.info("package %s not in local db", package_name)
if remove_not_in_local:
@ -1127,7 +1138,9 @@ def verify(
)
syncer.finalize()
logger.info("====== Step 4. Remove any unreferenced files in `packages` folder ======")
logger.info(
"====== Step 4. Remove any unreferenced files in `packages` folder ======"
)
ref_set = set()
for sname in tqdm(simple_dirs, desc="Iterating simple/ directory"):
sd = basedir / "simple" / sname
@ -1148,7 +1161,7 @@ def verify(
if str(file) not in ref_set:
logger.info("removing unreferenced file %s", file)
file.unlink()
logger.info("Verification finished. Success: %s", success)
if not success: