Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(sourcing): 补头像脚本声明 pid 锁参数,对照表链接按本机端口拼

longmeidaof3ca9429c83b
diff --git a/scripts/fill_portrait_gaps.py b/scripts/fill_portrait_gaps.py
index 0b327f4d0..2e290e234 100644
--- a/scripts/fill_portrait_gaps.py
+++ b/scripts/fill_portrait_gaps.py
@@ -38,7 +38,8 @@ if str(SRC_DIR) not in sys.path:
from peach import avatar_picker # noqa: E402
from peach.avatar_provider import acceptable_avatar # noqa: E402
-from peach.config import DATABASE_PATH, GENERATED_DIR # noqa: E402
+from peach.config import (DATABASE_PATH, GENERATED_DIR, SERVE_PORT, # noqa: E402
+ STATE_DIR)
from peach.jobs import job_main # noqa: E402
from peach.previews import entity_image_key # noqa: E402
from peach.review_csv import write_rows # noqa: E402
@@ -246,12 +247,13 @@ def build_parser() -> argparse.ArgumentParser:
default=GENERATED_DIR / "portrait-gaps.csv")
parser.add_argument("--sheet", type=Path, required=True,
help="对照表目录,候选图存在它下面的 candidates/")
- parser.add_argument("--base-url", default="https://peach-win.local",
+ parser.add_argument("--base-url", default=f"http://localhost:{SERVE_PORT}",
help="对照表里链接指向的实例")
parser.add_argument("--limit", type=int, default=0)
parser.add_argument("--min-long-side", type=int, default=MIN_LONG_SIDE)
parser.add_argument("--min-short-side", type=int, default=MIN_SHORT_SIDE)
parser.add_argument("--apply", action="store_true", help="真的装图;默认只看不装")
+ parser.add_argument("--lock", type=Path, default=STATE_DIR / ".portrait-gaps.lock")
return parser
diff --git a/tests/test_portrait_gaps.py b/tests/test_portrait_gaps.py
index 7b11e2857..5624ae6c8 100644
--- a/tests/test_portrait_gaps.py
+++ b/tests/test_portrait_gaps.py
@@ -108,7 +108,8 @@ class PortraitGapTests(unittest.TestCase):
["--db", str(self.database), "--avatar-root", str(self.avatars),
"--providers-root", str(self.providers),
"--out", str(self.root / "gaps.csv"),
- "--sheet", str(self.root / "sheet"), *extra])
+ "--sheet", str(self.root / "sheet"),
+ "--base-url", "http://localhost:9999", *extra])
def run_script(self, *extra, size: tuple[int, int] = (600, 900)):
import peach.http as peach_http
@@ -170,7 +171,7 @@ class PortraitGapTests(unittest.TestCase):
connection.close()
self.run_script("--apply")
page = (self.root / "sheet" / "index.html").read_text(encoding="utf-8")
- self.assertIn("https://peach-win.local/item/41", page)
+ self.assertIn("http://localhost:9999/item/41", page)
self.assertIn("ABC-001", page)
def test_someone_who_already_has_a_portrait_is_not_a_target(self):
@@ -184,6 +185,11 @@ class PortraitGapTests(unittest.TestCase):
connection.close()
self.assertNotIn("吉良いろは", names)
+ def test_the_entry_hands_job_main_everything_it_takes(self):
+ """`job_main` 要用 `--lock` 把 pid 锁包住整个 run。缺了它是启动就崩。"""
+ args = self.module.build_parser().parse_args(["--sheet", "s"])
+ self.assertTrue(args.lock)
+
def test_the_people_with_the_most_works_come_first(self):
"""对照表要人一个个认,排在前面的该是库里真出现过几次的那些。"""
connection = sqlite3.connect(f"file:{self.database}?mode=ro", uri=True)