Skip to content
Snippets Groups Projects
Commit 149b4d0a authored by Moritz Maas's avatar Moritz Maas
Browse files

fix: test version responses before continuing

parent aa720929
Branches dev-moritz
No related tags found
No related merge requests found
......@@ -260,10 +260,10 @@ class Command(ABC):
_LINE_SEPARATOR = "\n"
_ERROR_ARG_COUNT = "Invalid number of arguments provided."
_ERROR_EXECUTION_FAIL = "Execution of '{}' failed."
_ERROR_FILE_NOT_FOUND = "'{}' is not a valid file."
_ERROR_HARDWARE_FAIL = "Execution of hardware command failed."
_ERROR_INVALID_ARG = "'{}' is not a valid argument."
_ERROR_EXECUTION_FAIL = "Execution of '{}' failed."
_SUCCESS_TERMINATED = "Successfully terminated execution of '{}'."
_SUCCESS_RUN = "Successfully ran '{}'."
......@@ -343,8 +343,7 @@ Options: -d, --debug Log debug messages.
system = SystemParser.parse(BeautifulSoup(file, self._BS_BUILDER))
except (XMLParseError, ExecutionError) as e:
message: str = self._ERROR_UPPAAL_XML.format(args[0])
if hasattr(e, "message"):
message += e.message
message += " " + e.args[0]
return CommandResult(message, CommandResultType.FAILURE)
pkl_file = args[0].replace(self._XML_FILE_KEY, self._PKL_FILE_KEY)
with open(pkl_file, "wb") as file:
......@@ -585,11 +584,15 @@ Options: -d, --debug Log debug messages.
Executor.stop()
return CommandResult(self._SUCCESS_TERMINATED.format(args[0]),
CommandResultType.SUCCESS)
except (HardwareCallError, ExecutionError) as e:
except HardwareCallError as e:
message: str = self._ERROR_HARDWARE_FAIL.format(args[0])
if hasattr(e, "message"):
message = e.message
return CommandResult(message, CommandResultType.FAILURE)
except ExecutionError as e:
message: str = self._ERROR_EXECUTION_FAIL.format(args[0])
message += " " + e.args[0]
return CommandResult(message, CommandResultType.FAILURE)
return CommandResult(self._SUCCESS_RUN.format(args[0]), CommandResultType.SUCCESS)
......@@ -600,7 +603,7 @@ class VersionCommand(Command):
__slots__ = ("_version_manager", "_command_handler", "_controller")
_HELP_MESSAGE = """Usage: (version | v) (list | run <id> | fav <id> | delete <id>)
_HELP_MESSAGE = """Usage: (version | v) (list | run <id> | fav <id> | del <id> [-s | --skip])
[-d | --debug] [-h | --help]
The version command manages parsed versions of UPPAAL systems.
......@@ -608,13 +611,17 @@ The version command manages parsed versions of UPPAAL systems.
Commands: list List all versions in current project.
run Run an existing version.
fav Prevent existing version from being automatically deleted.
delete Delete existing version.
del Delete existing version.
Options: -d, --debug Log debug messages.
Options: -s, --skip Skip the deletion confirmation dialogue for favorite versions.
-d, --debug Log debug messages.
-h, --help Show this message."""
_LOGGERS = ["version_control", "controller", "uppaal_model", "jetracer"]
_SKIP_FLAG = "-s"
_SKIP_FLAG_ALT = "--skip"
_SUCCESS_FAVORITE = "Version {} is now a favorite."
_SUCCESS_DEFAVORITE = "Version {} is now no longer a favorite."
_SUCCESS_DELETE = "Deleted version {} from project."
......@@ -644,7 +651,7 @@ Options: -d, --debug Log debug messages.
"list": self._execute_list,
"run": self._execute_run,
"fav": self._execute_fav,
"delete": self._execute_delete,
"del": self._execute_delete,
"stop": self._execute_stop
}
......@@ -680,11 +687,17 @@ Options: -d, --debug Log debug messages.
Executor.stop()
return CommandResult(self._SUCCESS_TERMINATED.format(args[0]),
CommandResultType.SUCCESS)
except (HardwareCallError, ExecutionError) as e:
message: str = self._ERROR_HARDWARE_FAIL.format(args[0])
except HardwareCallError as e:
message: str = self._ERROR_HARDWARE_FAIL
if hasattr(e, "message"):
message = e.message
return CommandResult(message, CommandResultType.FAILURE)
except ExecutionError as e:
message: str = self._ERROR_EXECUTION_FAIL.format(response.payload.name)
message += " " + e.args[0]
return CommandResult(message, CommandResultType.FAILURE)
return CommandResult(self._SUCCESS_RUN.format(response.payload.name),
CommandResultType.SUCCESS)
def _execute_stop(self, args: List[str]) -> CommandResult:
if not len(args) == 0:
......@@ -713,12 +726,16 @@ Options: -d, --debug Log debug messages.
[response])
def _execute_delete(self, args: List[str]) -> CommandResult:
if not 0 < len(args) < 3:
if not 1 <= len(args) <= 2:
return CommandResult(self._ERROR_ARG_COUNT, CommandResultType.FAILURE)
try:
if (((len(args) == 1 or args[1] != "-skip")
and self._version_manager.get_version(int(args[0])).payload.favorite)
and not self._command_handler.get_confirmation(
response: VersionResponse = self._version_manager.get_version(int(args[0]))
if response.type == ResponseType.ERROR:
return CommandResult(response.message, CommandResultType.FAILURE, [response])
if (self._SKIP_FLAG not in args
and self._SKIP_FLAG_ALT not in args
and self._version_manager.get_version(int(args[0])).payload.favorite
and not self._command_handler.get_confirmation(
self._DELETE_CONFIRMATION_REQUEST)):
return CommandResult(self._ABORT_DELETE, CommandResultType.SUCCESS, None)
response: VersionResponse = self._version_manager.delete_version(int(args[0]))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment