mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-08 05:29:40 +00:00
e8f392c3f1
* Move the oled script's PiCmds module to common, and rename it SysCmds. * Use sys_cmds.get_ip_and_host() in web UI code. * Move the auth_active() method to device_utils * Rename device_utils to web_utils. Make auth_active() method take the group as argument. * Migrate all pi_cmds methods to the SysCmds common class. * Display hostname and ip in Web UI. * Resolve or suppress pylint warnings. * Resolve a pylint warning. * Resolve or suppress pylint warnings. * Import libraries at the top level for readability. In my testing on a Pi3B+, this leads to ~1.5k more memory being used by the python3 process. * Change page title as requested by akuker. * Reenable the import-outside-toplevel pylint rule. * Resolve pylint warnings. * Fix error following refactoring. * Minor UI tweaks. * Cleanup. * Break out bridge config validation into a utility method. * Move the dropzonejs method into the web_utils package * Move get_logs method into SysCmds class. * Improve get logs UI. * Resolve pylint warning. * Standardize class instance name.
49 lines
2.6 KiB
Python
49 lines
2.6 KiB
Python
"""Module for mapping between rascsi return codes and translated strings"""
|
|
|
|
from rascsi.return_codes import ReturnCodes
|
|
from flask_babel import _, lazy_gettext
|
|
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
class ReturnCodeMapper:
|
|
"""Class for mapping between rascsi return codes and translated strings"""
|
|
|
|
MESSAGES = {
|
|
ReturnCodes.DELETEFILE_SUCCESS: _("File deleted: %(file_path)s"),
|
|
ReturnCodes.DELETEFILE_FILE_NOT_FOUND: _("File to delete not found: %(file_path)s"),
|
|
ReturnCodes.RENAMEFILE_SUCCESS: _("File moved to: %(target_path)s"),
|
|
ReturnCodes.RENAMEFILE_UNABLE_TO_MOVE: _("Unable to move file to: %(target_path)s"),
|
|
ReturnCodes.DOWNLOADFILETOISO_SUCCESS: _("Created CD-ROM ISO image with "
|
|
"arguments \"%(value)s\""),
|
|
ReturnCodes.DOWNLOADTODIR_SUCCESS: _("%(file_name)s downloaded to %(save_dir)s"),
|
|
ReturnCodes.WRITECONFIG_SUCCESS: _("Saved configuration file to %(file_name)s"),
|
|
ReturnCodes.WRITECONFIG_COULD_NOT_WRITE: _("Could not write to file: %(file_name)s"),
|
|
ReturnCodes.READCONFIG_SUCCESS: _("Loaded configurations from: %(file_name)s"),
|
|
ReturnCodes.READCONFIG_COULD_NOT_READ: _("Could not read configuration "
|
|
"file: %(file_name)s"),
|
|
ReturnCodes.READCONFIG_INVALID_CONFIG_FILE_FORMAT: _("Invalid configuration file format"),
|
|
ReturnCodes.WRITEDRIVEPROPS_SUCCESS: _("Created properties file: %(file_path)s"),
|
|
ReturnCodes.WRITEDRIVEPROPS_COULD_NOT_WRITE: _("Could not write to properties "
|
|
"file: %(file_path)s"),
|
|
ReturnCodes.READDRIVEPROPS_SUCCESS: _("Read properties from file: %(file_path)s"),
|
|
ReturnCodes.READDRIVEPROPS_COULD_NOT_READ: _("Could not read properties from "
|
|
"file: %(file_path)s"),
|
|
ReturnCodes.ATTACHIMAGE_COULD_NOT_ATTACH: _("Cannot insert an image for %(device_type)s "
|
|
"into a %(current_device_type)s device"),
|
|
}
|
|
|
|
@staticmethod
|
|
def add_msg(payload):
|
|
"""adds a msg key to a given payload with a rascsi module return code
|
|
with a translated return code message string. """
|
|
if "return_code" not in payload:
|
|
return payload
|
|
|
|
parameters = payload["parameters"]
|
|
|
|
payload["msg"] = lazy_gettext(
|
|
ReturnCodeMapper.MESSAGES[payload["return_code"]],
|
|
**parameters,
|
|
)
|
|
return payload
|