Fix error preventing ReturnCodeMapper using payloads without parameters, formatting to avoid wrapping of messages

This commit is contained in:
nucleogenic 2022-08-05 00:28:22 +01:00
parent 4e622a9ea9
commit 078d0fc99f
No known key found for this signature in database
GPG Key ID: 04A5E4E319C4271D

View File

@ -9,25 +9,35 @@ class ReturnCodeMapper:
"""Class for mapping between rascsi return codes and translated strings""" """Class for mapping between rascsi return codes and translated strings"""
MESSAGES = { MESSAGES = {
ReturnCodes.DELETEFILE_SUCCESS: _("File deleted: %(file_path)s"), ReturnCodes.DELETEFILE_SUCCESS:
ReturnCodes.DELETEFILE_FILE_NOT_FOUND: _("File to delete not found: %(file_path)s"), _("File deleted: %(file_path)s"),
ReturnCodes.RENAMEFILE_SUCCESS: _("File moved to: %(target_path)s"), ReturnCodes.DELETEFILE_FILE_NOT_FOUND:
ReturnCodes.RENAMEFILE_UNABLE_TO_MOVE: _("Unable to move file to: %(target_path)s"), _("File to delete not found: %(file_path)s"),
ReturnCodes.DOWNLOADFILETOISO_SUCCESS: _("Created CD-ROM ISO image with " ReturnCodes.RENAMEFILE_SUCCESS:
"arguments \"%(value)s\""), _("File moved to: %(target_path)s"),
ReturnCodes.DOWNLOADTODIR_SUCCESS: _("%(file_name)s downloaded to %(save_dir)s"), ReturnCodes.RENAMEFILE_UNABLE_TO_MOVE:
ReturnCodes.WRITEFILE_SUCCESS: _("File created: %(target_path)s"), _("Unable to move file to: %(target_path)s"),
ReturnCodes.WRITEFILE_COULD_NOT_WRITE: _("Could not create file: %(target_path)s"), ReturnCodes.DOWNLOADFILETOISO_SUCCESS:
ReturnCodes.READCONFIG_SUCCESS: _("Loaded configurations from: %(file_name)s"), _("Created CD-ROM ISO image with arguments \"%(value)s\""),
ReturnCodes.READCONFIG_COULD_NOT_READ: _("Could not read configuration " ReturnCodes.DOWNLOADTODIR_SUCCESS:
"file: %(file_name)s"), _("%(file_name)s downloaded to %(save_dir)s"),
ReturnCodes.READCONFIG_INVALID_CONFIG_FILE_FORMAT: _("Invalid configuration file format"), ReturnCodes.WRITEFILE_SUCCESS:
ReturnCodes.READDRIVEPROPS_SUCCESS: _("Read properties from file: %(file_path)s"), _("File created: %(target_path)s"),
ReturnCodes.READDRIVEPROPS_COULD_NOT_READ: _("Could not read properties from " ReturnCodes.WRITEFILE_COULD_NOT_WRITE:
"file: %(file_path)s"), _("Could not create file: %(target_path)s"),
ReturnCodes.ATTACHIMAGE_COULD_NOT_ATTACH: _("Cannot insert an image for %(device_type)s " ReturnCodes.READCONFIG_SUCCESS:
"into a %(current_device_type)s device"), _("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.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 @staticmethod
def add_msg(payload): def add_msg(payload):
@ -36,10 +46,14 @@ class ReturnCodeMapper:
if "return_code" not in payload: if "return_code" not in payload:
return payload return payload
parameters = payload["parameters"] parameters = payload.get("parameters")
payload["msg"] = lazy_gettext( if parameters:
payload["msg"] = lazy_gettext(
ReturnCodeMapper.MESSAGES[payload["return_code"]], ReturnCodeMapper.MESSAGES[payload["return_code"]],
**parameters, **parameters,
) )
else:
payload["msg"] = lazy_gettext(ReturnCodeMapper.MESSAGES[payload["return_code"]])
return payload return payload