mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 02:27:52 -06:00
refactor: one predicate for the pack notes
This commit is contained in:
1 parent
66c83b06b0
commit
cf7e13808f
7 files changed
+30
-32
No files matched your search
@@ -3,18 +3,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from core.paths import EMULATORS_DIR
|
||||
from model.registry import load_data_dir_registry
|
||||
from packs.paths import MEDIA_MARKER
|
||||
|
||||
# Members the builder writes for the reader or the device rather than for a
|
||||
# core: the documents, and the empty marker an Android pack carries.
|
||||
PACK_NOTES = re.compile(
|
||||
r"(^README\.txt$|^manifest\.json$|(^|/)(INSTRUCTIONS|RENAMED)_[^/]*\.txt$"
|
||||
rf"|(^|/){re.escape(MEDIA_MARKER)}$)"
|
||||
)
|
||||
|
||||
|
||||
def tree_members(
|
||||
|
||||
@@ -6,6 +6,7 @@ from pathlib import Path
|
||||
|
||||
from core.paths import PLATFORMS_DIR
|
||||
from orchestrate import compare
|
||||
from packs.archive import is_pack_note
|
||||
from orchestrate.labels import STEP_LABELS, step_title
|
||||
from orchestrate.reports import (
|
||||
match_key,
|
||||
@@ -138,7 +139,7 @@ def check_pack_destinations(
|
||||
written = {
|
||||
info.filename for info in zf.infolist()
|
||||
if not info.is_dir()
|
||||
and not compare.PACK_NOTES.search(info.filename)
|
||||
and not is_pack_note(info.filename)
|
||||
and not (
|
||||
trees.get(info.filename) == info.file_size
|
||||
and info.filename not in credited
|
||||
|
||||
@@ -6,8 +6,9 @@ import contextlib
|
||||
import io
|
||||
|
||||
from core.paths import DB_FILE, EMULATORS_DIR, PLATFORMS_DIR
|
||||
from orchestrate.compare import PACK_NOTES, comparison_inputs, set_difference_lines
|
||||
from orchestrate.compare import comparison_inputs, set_difference_lines
|
||||
from orchestrate.labels import STEP_LABELS, step_title
|
||||
from packs.archive import is_pack_note
|
||||
|
||||
# How each pack_narrowings() dimension of a platform pack is compared by
|
||||
# check_narrowed_packs, or why it is not. A test reads the builder's
|
||||
@@ -142,7 +143,7 @@ def check_narrowed_packs(
|
||||
trees = set(record.trees) - credited
|
||||
written = {
|
||||
m for m in record.members
|
||||
if not PACK_NOTES.search(m) and m not in trees
|
||||
if not is_pack_note(m) and m not in trees
|
||||
}
|
||||
lines = set_difference_lines(name, credited, written)
|
||||
if lines:
|
||||
|
||||
@@ -8,8 +8,9 @@ from collections.abc import Callable
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from core.paths import DB_FILE, EMULATORS_DIR, PLATFORMS_DIR
|
||||
from orchestrate.compare import PACK_NOTES, comparison_inputs
|
||||
from orchestrate.compare import comparison_inputs
|
||||
from orchestrate.labels import STEP_LABELS, step_title
|
||||
from packs.archive import is_pack_note
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from packs.archive import PackRecord
|
||||
@@ -23,10 +24,10 @@ def split_differences(
|
||||
A path in a part and not in the full pack, a path of the full pack in no
|
||||
part, and a path a part fills with other bytes than the full pack.
|
||||
"""
|
||||
full_members = {m for m in full.members if not PACK_NOTES.search(m)}
|
||||
full_members = {m for m in full.members if not is_pack_note(m)}
|
||||
union = {
|
||||
m for record in parts.values() for m in record.members
|
||||
if not PACK_NOTES.search(m)
|
||||
if not is_pack_note(m)
|
||||
}
|
||||
lines = [f"in a part, not in the full pack: {m}" for m in sorted(union - full_members)]
|
||||
lines += [f"in the full pack, in no part: {m}" for m in sorted(full_members - union)]
|
||||
|
||||
@@ -12,7 +12,7 @@ from dataclasses import dataclass, field
|
||||
from core.artifacts import atomic_scratch
|
||||
from core.hashing import compute_hashes
|
||||
from core.paths import comparable_destination, sanitize_pack_path
|
||||
from packs.paths import has_path_conflict, register_path, placement_block
|
||||
from packs.paths import MEDIA_MARKER, has_path_conflict, register_path, placement_block
|
||||
|
||||
|
||||
# The minimum ZIP timestamp, carried by every pack member so a pack is a
|
||||
@@ -127,6 +127,20 @@ def writing_pack(zip_path: str) -> Iterator[zipfile.ZipFile]:
|
||||
PACK_DOCUMENTS = ("README.txt", "manifest.json")
|
||||
|
||||
|
||||
def is_pack_note(name: str) -> bool:
|
||||
"""Whether a member is a note the builder composes, not a collected file."""
|
||||
# The builder writes its notes beside the slot they explain
|
||||
# (bios/INSTRUCTIONS_x.txt, games/keen6/INSTRUCTIONS_y.txt), so
|
||||
# they are told by their own name, not by a root prefix. The empty
|
||||
# marker an Android pack carries is written for the device.
|
||||
base = name.rsplit("/", 1)[-1]
|
||||
return (
|
||||
base.startswith(("INSTRUCTIONS_", "RENAMED_"))
|
||||
or base == MEDIA_MARKER
|
||||
or name in PACK_DOCUMENTS
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Placed:
|
||||
"""The destinations a build has taken, and the folders they open.
|
||||
|
||||
@@ -11,6 +11,7 @@ from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, TypedDict
|
||||
|
||||
from core.artifacts import build_timestamp
|
||||
from packs.archive import PACK_DOCUMENTS, is_pack_note
|
||||
from packs.paths import MEDIA_MARKER, has_path_conflict
|
||||
from core.ziptools import build_zip_contents_index, is_archive_path, zip_members
|
||||
from core.ziptools import safe_member_parts
|
||||
@@ -141,18 +142,6 @@ def _data_indexes(data_registry: dict | None) -> tuple[dict[str, list[str]], dic
|
||||
return _data_index, _data_path_index
|
||||
|
||||
|
||||
def _is_pack_note(name: str) -> bool:
|
||||
"""Whether a member is a note the builder composes, not a collected file."""
|
||||
# The builder writes its notes beside the slot they explain
|
||||
# (bios/INSTRUCTIONS_x.txt, games/keen6/INSTRUCTIONS_y.txt), so
|
||||
# they are told by their own name, not by a root prefix.
|
||||
base = name.rsplit("/", 1)[-1]
|
||||
return base.startswith(("INSTRUCTIONS_", "RENAMED_")) or base == MEDIA_MARKER or name in (
|
||||
"manifest.json",
|
||||
"README.txt",
|
||||
)
|
||||
|
||||
|
||||
def _member_digests(zf: zipfile.ZipFile, info: zipfile.ZipInfo) -> tuple[str, str, int]:
|
||||
"""(sha1, md5, size) of a pack member."""
|
||||
with zf.open(info) as f:
|
||||
@@ -241,7 +230,7 @@ def verify_pack(
|
||||
|
||||
with zipfile.ZipFile(zip_path, "r") as zf:
|
||||
for info in zf.infolist():
|
||||
if info.is_dir() or _is_pack_note(info.filename):
|
||||
if info.is_dir() or is_pack_note(info.filename):
|
||||
continue
|
||||
name = info.filename
|
||||
sha1, md5, size = _member_digests(zf, info)
|
||||
@@ -512,7 +501,7 @@ def _structural_errors(zf: zipfile.ZipFile, zip_set: set) -> list[str]:
|
||||
for info in zf.infolist()
|
||||
if info.file_size == 0 and not info.is_dir()
|
||||
and "GraphicMods" not in info.filename
|
||||
and info.filename not in ("manifest.json", "README.txt")
|
||||
and info.filename not in PACK_DOCUMENTS
|
||||
and info.filename.rsplit("/", 1)[-1] != MEDIA_MARKER
|
||||
)
|
||||
|
||||
@@ -748,7 +737,7 @@ def _pack_view(zf: zipfile.ZipFile, config: dict, base_dest: str) -> _PackView:
|
||||
is_flat = bool(base_dest) and not any(
|
||||
n.startswith(base_dest + "/")
|
||||
for n in zip_set
|
||||
if n not in ("README.txt", "manifest.json", MEDIA_MARKER) and not n.endswith("/")
|
||||
if n not in (*PACK_DOCUMENTS, MEDIA_MARKER) and not n.endswith("/")
|
||||
)
|
||||
# Mirror the builder's path-conflict logic: a declaration whose path
|
||||
# collides file-vs-directory with a packed member was skipped by the
|
||||
|
||||
Reference in new issue
Block a user