From e51dc14d7b938e936b59b25bc39fc476c65cd199 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 24 Nov 2026 00:56:02 +0100 Subject: [PATCH] refactor: one writer for the instructions note --- scripts/packs/archive.py | 7 +++++++ scripts/packs/emulatorpack.py | 9 +++------ scripts/packs/manifest.py | 9 ++------- scripts/packs/platformpack.py | 12 +++--------- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/scripts/packs/archive.py b/scripts/packs/archive.py index 7f1a4d671..0bb29564c 100644 --- a/scripts/packs/archive.py +++ b/scripts/packs/archive.py @@ -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. diff --git a/scripts/packs/emulatorpack.py b/scripts/packs/emulatorpack.py index 7637fced2..f667fdee0 100644 --- a/scripts/packs/emulatorpack.py +++ b/scripts/packs/emulatorpack.py @@ -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"] diff --git a/scripts/packs/manifest.py b/scripts/packs/manifest.py index 11046e292..59f00e896 100644 --- a/scripts/packs/manifest.py +++ b/scripts/packs/manifest.py @@ -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( diff --git a/scripts/packs/platformpack.py b/scripts/packs/platformpack.py index 3158451e8..ea49e5e3c 100644 --- a/scripts/packs/platformpack.py +++ b/scripts/packs/platformpack.py @@ -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: