refactor: one writer for the instructions note

This commit is contained in:
Abdessamad Derraz committed 2026-11-24 01:14:04 +01:00
1 parent dfc1860d0d
commit e51dc14d7b
4 files changed
+15 -22

No files matched your search

+7
View File
@@ -147,6 +147,13 @@ def is_pack_note(name: str) -> bool:
)
def instructions_note(file_entry: dict) -> tuple[str, str]:
"""The member name and text of the note written in a user_provided slot's place."""
name = file_entry["name"]
instructions = file_entry.get("instructions", "Please provide this file manually.")
return f"INSTRUCTIONS_{name}.txt", f"File needed: {name}\n\n{instructions}\n"
@dataclass
class Placed:
"""The destinations a build has taken, and the folders they open.
+3 -6
View File
@@ -31,6 +31,7 @@ from packs.archive import (
Placed,
add_pack_member,
add_zip_to_pack,
instructions_note,
same_bytes,
write_generated_member,
writing_pack,
@@ -195,13 +196,9 @@ class _EmulatorPackBuild:
# Instructions, not a file: written beside the slot the
# user fills, and counted apart from what the pack holds.
self.placed.take(dest)
instr = provided.get("instructions", "Please provide this file manually.")
instr_name, text = instructions_note(provided)
folder = dest.rsplit("/", 1)[0] + "/" if "/" in dest else ""
write_generated_member(
self.zf,
f"{folder}INSTRUCTIONS_{provided['name']}.txt",
f"File needed: {provided['name']}\n\n{instr}\n",
)
write_generated_member(self.zf, f"{folder}{instr_name}", text)
# verify --emulator counts an unsourceable one as such.
(self.unsourceable_files if provided.get("unsourceable") else self.instruction_files).append(
provided["name"]
+2 -7
View File
@@ -16,7 +16,7 @@ from model.profiles import installed_data_refs_in, load_emulator_profiles
from model.registry import load_data_dir_registry, platform_registry_at
from model.systems import platform_system_names
from packs import slots
from packs.archive import CASE_FOLDING_OS, PACK_DOCUMENTS, Placed
from packs.archive import CASE_FOLDING_OS, PACK_DOCUMENTS, Placed, instructions_note
from packs.datatrees import (
data_directory_members,
in_data_cache,
@@ -334,12 +334,7 @@ class _ManifestBuild:
)
# The pack writes the instructions in the slot's place
# and holds it: one more member than the files listed.
instructions = file_entry.get(
"instructions", "Please provide this file manually."
)
self.pack_only_sizes.append(len(
f"File needed: {file_entry['name']}\n\n{instructions}\n".encode()
))
self.pack_only_sizes.append(len(instructions_note(file_entry)[1].encode()))
self.placed.take(full_dest)
def _list_declared(
+3 -9
View File
@@ -28,6 +28,7 @@ from packs.archive import (
add_pack_member,
add_zip_to_pack,
extract_zip_to_archive,
instructions_note,
same_bytes,
write_generated_member,
writing_pack,
@@ -612,18 +613,11 @@ class _PlatformPackBuild:
base_dest = self.plan.base_dest
self.placed.take(full_dest)
self.file_status.setdefault(full_dest, "ok")
instructions = file_entry.get(
"instructions", "Please provide this file manually."
)
instr_name = f"INSTRUCTIONS_{file_entry['name']}.txt"
instr_name, text = instructions_note(file_entry)
instr_path = (
f"{base_dest}/{instr_name}" if base_dest else instr_name
)
write_generated_member(
self.zf,
self._flat(instr_path),
f"File needed: {file_entry['name']}\n\n{instructions}\n",
)
write_generated_member(self.zf, self._flat(instr_path), text)
self.total_files += 1
def _pack_external(self, file_entry: dict, full_dest: str) -> None: