Send Global back to the VT, keep a US keyboard in the CJK console and translate the media diagnosis
This commit is contained in:
1 parent
555093811f
commit
02c803cb40
5 files changed
+103
-37
No files matched your search
@@ -1,7 +1,6 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# China installs read in Chinese: every text the configurator and the install
|
||||
# dashboard pass to omarchy_text needs an OMARCHY_ZH entry, or it shows in English.
|
||||
# Every installer text needs an OMARCHY_ZH entry, or a China install shows it in English.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -39,6 +38,13 @@ for action in "View full log" "Drop to shell" "Reboot" "Power off" "Upload log f
|
||||
done
|
||||
printf 'ok - labels passed through variables have Chinese entries\n'
|
||||
|
||||
mapfile -t diagnosis < <(grep -x ' *echo "[^"$]*"' "$ROOT/configs/airootfs/usr/local/bin/omarchy-install-diagnose-media" | sed 's/^ *echo "//; s/"$//')
|
||||
((${#diagnosis[@]} >= 10)) || fail "the media diagnosis sentences are found" "found ${#diagnosis[@]}"
|
||||
for line in "${diagnosis[@]}"; do
|
||||
[[ -n ${OMARCHY_ZH[$line]:-} ]] || fail "every media diagnosis sentence has a Chinese entry" "missing: $line"
|
||||
done
|
||||
printf 'ok - every media diagnosis sentence has a Chinese entry\n'
|
||||
|
||||
[[ $(OMARCHY_INSTALL_LANG=zh omarchy_text "Confirm overwriting %s" /dev/vda) == "确认覆盖 /dev/vda" ]] ||
|
||||
fail "Chinese text keeps its printf arguments"
|
||||
[[ $(omarchy_text "Confirm overwriting %s" /dev/vda) == "Confirm overwriting /dev/vda" ]] ||
|
||||
|
||||
@@ -74,40 +74,69 @@ class RegionTest(unittest.TestCase):
|
||||
chroot = next(call.args[0] for call in run.call_args_list if call.args[0][0] == "arch-chroot")
|
||||
self.assertIn(f"OMARCHY_REGION={region}", chroot)
|
||||
|
||||
def run_keyboard_form(self, script: str) -> str:
|
||||
def run_keyboard_form(self, script: str, **env: str) -> subprocess.CompletedProcess:
|
||||
configurator = (ROOT / "configs/airootfs/root/configurator").read_text()
|
||||
language = re.search(r"^apply_region_language\(\) \{\n.*?^\}", configurator, re.M | re.S)
|
||||
form = re.search(r"^keyboard_form\(\) \{\n.*?^\}", configurator, re.M | re.S)
|
||||
init = re.search(r'^region="global"$', configurator, re.M)
|
||||
init = re.search(r'^region="\$\{OMARCHY_INSTALL_REGION:-global\}"$', configurator, re.M)
|
||||
self.assertIsNotNone(language)
|
||||
self.assertIsNotNone(form)
|
||||
self.assertIsNotNone(init)
|
||||
harness = "\n".join([
|
||||
"set -euo pipefail",
|
||||
"OMARCHY_FORM_BACK=1; OMARCHY_FORM_SIGNAL=130; defer_provisioning=false",
|
||||
"clear_logo() { :; }; say() { :; }; abort() { exit 99; }; tty() { echo /dev/pts/0; }",
|
||||
"omarchy_text() { printf '%s' \"$1\"; }",
|
||||
"answers=(" + script + "); step=0",
|
||||
"answer() { local a=${answers[step]}; step=$((step + 1)); [[ $a == ok:* ]] && eval \"${a#ok:}\" && return 0; return ${a#rc:}; }",
|
||||
"omarchy_prompt_region() { echo \"region-preselect=$region\"; answer; }",
|
||||
"omarchy_prompt_keyboard() { answer; }",
|
||||
"omarchy_prompt_keyboard() { echo keyboard-prompt; answer; }",
|
||||
"confirm_prepare_for_another_owner() { answer; }",
|
||||
init.group(),
|
||||
language.group(),
|
||||
form.group(),
|
||||
"keyboard_form",
|
||||
'echo "region=$region defer=$defer_provisioning"',
|
||||
'echo "region=$region defer=$defer_provisioning keyboard=${keyboard:-} lang=${OMARCHY_INSTALL_LANG:-}"',
|
||||
])
|
||||
return subprocess.run(["bash", "-c", harness], check=True, capture_output=True, text=True).stdout
|
||||
return subprocess.run(["bash", "-c", harness], capture_output=True, text=True,
|
||||
env={"PATH": os.environ["PATH"], **env})
|
||||
|
||||
def lines(self, result: subprocess.CompletedProcess) -> list[str]:
|
||||
return [line for line in result.stdout.splitlines() if line]
|
||||
|
||||
def test_ctrl_c_before_choosing_defers_as_global(self):
|
||||
out = self.run_keyboard_form("rc:130 ok:true")
|
||||
self.assertIn("region=global defer=true", out)
|
||||
self.assertIn("region=global defer=true", out.stdout)
|
||||
|
||||
def test_back_from_keyboard_keeps_the_chosen_region(self):
|
||||
out = self.run_keyboard_form("ok:region=china rc:1 ok:true ok:keyboard=us")
|
||||
self.assertEqual([line for line in out.splitlines() if line], [
|
||||
self.assertEqual(self.lines(out), [
|
||||
"region-preselect=global",
|
||||
"keyboard-prompt",
|
||||
"region-preselect=china",
|
||||
"region=china defer=false",
|
||||
"keyboard-prompt",
|
||||
"region=china defer=false keyboard=us lang=",
|
||||
])
|
||||
|
||||
def test_china_on_the_vt_hands_over_to_the_cjk_console(self):
|
||||
out = self.run_keyboard_form("ok:region=china", OMARCHY_CJK_RELAUNCH="10")
|
||||
self.assertEqual(out.returncode, 10)
|
||||
self.assertEqual(self.lines(out), ["region-preselect=global"])
|
||||
|
||||
def test_cjk_console_reads_chinese_with_a_us_keyboard(self):
|
||||
out = self.run_keyboard_form("ok:true", OMARCHY_CJK_CONSOLE="1", OMARCHY_VT_RETURN="11",
|
||||
OMARCHY_INSTALL_REGION="china")
|
||||
self.assertEqual(out.returncode, 0)
|
||||
self.assertEqual(self.lines(out), [
|
||||
"region-preselect=china",
|
||||
"region=china defer=false keyboard=us lang=zh",
|
||||
])
|
||||
|
||||
def test_global_in_the_cjk_console_returns_to_the_vt(self):
|
||||
out = self.run_keyboard_form("ok:region=global", OMARCHY_CJK_CONSOLE="1", OMARCHY_VT_RETURN="11",
|
||||
OMARCHY_INSTALL_REGION="china")
|
||||
self.assertEqual(out.returncode, 11)
|
||||
self.assertNotIn("keyboard-prompt", out.stdout)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user