Skip to content

Commit b4f0196

Browse files
committed
shadowmire.py: update to taoky/shadowmire@b9c6ac5
Signed-off-by: Harry Chen <i@harrychen.xyz>
1 parent 1683a1d commit b4f0196

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

shadowmire.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,20 @@ def check_and_update(
491491
continue
492492
package_simple_path = self.simple_dir / package_name
493493
html_simple = package_simple_path / "index.html"
494+
htmlv1_simple = package_simple_path / "index.v1_html"
494495
json_simple = package_simple_path / "index.v1_json"
495-
if not (html_simple.exists() and json_simple.exists()):
496+
if not (
497+
html_simple.exists() and json_simple.exists() and htmlv1_simple.exists()
498+
):
496499
logger.info(
497-
"add %s as it does not have index.html or index.v1_json",
500+
"add %s as it does not have index.html, index.v1_html or index.v1_json",
498501
package_name,
499502
)
500503
to_update.append(package_name)
501504
continue
505+
if not html_simple.is_symlink():
506+
html_simple.unlink()
507+
html_simple.symlink_to("index.v1_html")
502508
hrefs_html = get_package_urls_from_index_html(html_simple)
503509
hrefsize_json = get_package_urls_size_from_index_json(json_simple)
504510
if (
@@ -621,14 +627,19 @@ def do_update(
621627
def write_meta_to_simple(self, package_simple_path: Path, meta: dict) -> None:
622628
simple_html_contents = PyPI.generate_html_simple_page(meta)
623629
simple_json_contents = PyPI.generate_json_simple_page(meta)
624-
for html_filename in ("index.html", "index.v1_html"):
630+
for html_filename in ("index.v1_html",):
625631
html_path = package_simple_path / html_filename
626632
with overwrite(html_path) as f:
627633
f.write(simple_html_contents)
628634
for json_filename in ("index.v1_json",):
629635
json_path = package_simple_path / json_filename
630636
with overwrite(json_path) as f:
631637
f.write(simple_json_contents)
638+
index_html_path = package_simple_path / "index.html"
639+
if not index_html_path.is_symlink():
640+
if index_html_path.exists():
641+
index_html_path.unlink()
642+
index_html_path.symlink_to("index.v1_html")
632643

633644
def finalize(self) -> None:
634645
local_names = self.local_db.keys()
@@ -1051,7 +1062,9 @@ def genlocal(ctx: click.Context) -> None:
10511062
serial = get_local_serial(package_metapath)
10521063
if serial:
10531064
local[package_name] = serial
1054-
logger.info("%d out of {} packages have valid serial number", len(local), len(dir_items))
1065+
logger.info(
1066+
"%d out of %d packages have valid serial number", len(local), len(dir_items)
1067+
)
10551068
local_db.nuke(commit=False)
10561069
local_db.batch_set(local)
10571070
local_db.dump_json()
@@ -1093,7 +1106,11 @@ def verify(
10931106
simple_dirs = {i.name for i in (basedir / "simple").iterdir() if i.is_dir()}
10941107
json_files = {i.name for i in (basedir / "json").iterdir() if i.is_file()}
10951108
not_in_local = (simple_dirs | json_files) - local_names
1096-
logger.info("%d out of %d local packages NOT in local db", len(not_in_local), len(local_names))
1109+
logger.info(
1110+
"%d out of %d local packages NOT in local db",
1111+
len(not_in_local),
1112+
len(local_names),
1113+
)
10971114
for package_name in not_in_local:
10981115
logger.info("package %s not in local db", package_name)
10991116
if remove_not_in_local:
@@ -1127,7 +1144,9 @@ def verify(
11271144
)
11281145
syncer.finalize()
11291146

1130-
logger.info("====== Step 4. Remove any unreferenced files in `packages` folder ======")
1147+
logger.info(
1148+
"====== Step 4. Remove any unreferenced files in `packages` folder ======"
1149+
)
11311150
ref_set = set()
11321151
for sname in tqdm(simple_dirs, desc="Iterating simple/ directory"):
11331152
sd = basedir / "simple" / sname
@@ -1148,7 +1167,7 @@ def verify(
11481167
if str(file) not in ref_set:
11491168
logger.info("removing unreferenced file %s", file)
11501169
file.unlink()
1151-
1170+
11521171
logger.info("Verification finished. Success: %s", success)
11531172

11541173
if not success:

0 commit comments

Comments
 (0)