feat(installer): send the progress messages as translation keys
This module process cannot know the language picked on the first screen: the progress spoke translates the keys at display time instead.
This commit is contained in:
1 file changed
+23
-5
+23
-5
@@ -23,6 +23,7 @@
|
|||||||
# that into one step per installation phase and a message that says which
|
# that into one step per installation phase and a message that says which
|
||||||
# script is running and what it is doing.
|
# script is running and what it is doing.
|
||||||
#
|
#
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
@@ -47,6 +48,18 @@ FWS_PROGRESS_POLL = 0.5
|
|||||||
FWS_TITLE_PATTERN = re.compile(r"^#\s*FWS-TITLE:\s*(.+?)\s*$", re.MULTILINE)
|
FWS_TITLE_PATTERN = re.compile(r"^#\s*FWS-TITLE:\s*(.+?)\s*$", re.MULTILINE)
|
||||||
|
|
||||||
|
|
||||||
|
def _fws_message(key, **fields):
|
||||||
|
"""Progress message carrying a translation key and its named fields.
|
||||||
|
|
||||||
|
Nothing is composed or translated in this module process: the texts are
|
||||||
|
FWS's, not Anaconda's gettext ones, and the progress spoke translates them
|
||||||
|
at display time in the language picked on the first screen. The message
|
||||||
|
reads "<key> <JSON fields>"; a field may itself be such a message or a key
|
||||||
|
published by a script, the spoke renders those first.
|
||||||
|
"""
|
||||||
|
return "%s %s" % (key, json.dumps(fields, ensure_ascii=False))
|
||||||
|
|
||||||
|
|
||||||
class _ProgressWatcher(threading.Thread):
|
class _ProgressWatcher(threading.Thread):
|
||||||
"""Follow the progress published by the running kickstart script.
|
"""Follow the progress published by the running kickstart script.
|
||||||
|
|
||||||
@@ -149,11 +162,15 @@ class RunScriptsTask(Task):
|
|||||||
:param label: what is being done, in the installer language
|
:param label: what is being done, in the installer language
|
||||||
"""
|
"""
|
||||||
index, total, title = self._current_script
|
index, total, title = self._current_script
|
||||||
message = "%s — %s %%" % (label, percent)
|
|
||||||
if total > 1:
|
if total > 1:
|
||||||
message = "Script %d/%d · %s" % (index, total, message)
|
message = _fws_message("fws:progress.script_phase", index=index,
|
||||||
|
total=total, label=label, percent=percent)
|
||||||
elif title:
|
elif title:
|
||||||
message = "%s · %s" % (title, message)
|
message = _fws_message("fws:progress.titled_phase", title=title,
|
||||||
|
label=label, percent=percent)
|
||||||
|
else:
|
||||||
|
message = _fws_message("fws:progress.phase", label=label,
|
||||||
|
percent=percent)
|
||||||
|
|
||||||
step = min(self.steps, int(percent * self.steps / 100))
|
step = min(self.steps, int(percent * self.steps / 100))
|
||||||
log.debug("FWS install progress: %s (step %s/%s)", message, step, self.steps)
|
log.debug("FWS install progress: %s (step %s/%s)", message, step, self.steps)
|
||||||
@@ -166,7 +183,7 @@ class RunScriptsTask(Task):
|
|||||||
match = FWS_TITLE_PATTERN.search(getattr(script, "script", "") or "")
|
match = FWS_TITLE_PATTERN.search(getattr(script, "script", "") or "")
|
||||||
if match:
|
if match:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
return "Script %d" % index
|
return _fws_message("fws:progress.untitled_script", index=index)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Execute the task."""
|
"""Execute the task."""
|
||||||
@@ -179,7 +196,8 @@ class RunScriptsTask(Task):
|
|||||||
# percentages published by the script itself, so it never runs
|
# percentages published by the script itself, so it never runs
|
||||||
# ahead of what has actually been done.
|
# ahead of what has actually been done.
|
||||||
self.report_progress(
|
self.report_progress(
|
||||||
"Script %d/%d · %s" % (index, total, self._current_script[2])
|
_fws_message("fws:progress.script_start", index=index,
|
||||||
|
total=total, title=self._current_script[2])
|
||||||
)
|
)
|
||||||
|
|
||||||
watcher = _ProgressWatcher(self)
|
watcher = _ProgressWatcher(self)
|
||||||
|
|||||||
Reference in new issue
Block a user