|
1 | | -__all__ = ["BEHAVIOUR", "EXECUTION", "OPERATION", "INTERFACE", "COMPARISONS"] |
| 1 | +from automatabpp.automatabpp import * |
2 | 2 |
|
3 | | -import logging |
4 | | -automata_bpp_logger = logging.getLogger(__name__) |
5 | | - |
6 | | -from . machines.machines import Machines |
7 | | -from . xml.xmlread import read_graphml |
8 | | -from . commandqueue.commandqueue import CommandQueue |
9 | | -from . constants import GRAPHS_DIRECTORY, START_COMMAND_NAME, STOP_COMMAND_NAME |
10 | | -from . comparisons.comparisons import COMPARISONS |
11 | | - |
12 | | -from functools import wraps |
| 3 | +__version__ = "1.0.0" |
13 | 4 |
|
14 | 5 | __doc__ = """ docfile """ |
15 | | - |
16 | | - |
17 | | -class BEHAVIOUR: |
18 | | - |
19 | | - @staticmethod |
20 | | - def set_default_graph_directory(new_path: str): |
21 | | - global GRAPHS_DIRECTORY |
22 | | - GRAPHS_DIRECTORY = new_path |
23 | | - |
24 | | - @staticmethod |
25 | | - def load_behaviour_from_graph(graph_file_path: str, machine_name: str): |
26 | | - if graph_file_path[-8:] == ".graphml": |
27 | | - read_graphml("{}/{}".format(GRAPHS_DIRECTORY, graph_file_path), machine_name) |
28 | | - else: |
29 | | - automata_bpp_logger.warning("Unknown format for reading the graph file: {}".format(graph_file_path)) |
30 | | - |
31 | | - |
32 | | -class EXECUTION: |
33 | | - |
34 | | - @staticmethod |
35 | | - def state(func): |
36 | | - current_machine = Machines().GetCurrentDefinedMachine() |
37 | | - if current_machine is not None: |
38 | | - current_machine.SetExecuteStateFunction(func.__name__, func) |
39 | | - return func |
40 | | - |
41 | | - |
42 | | -class OPERATION: |
43 | | - |
44 | | - @staticmethod |
45 | | - def start_fsm(): |
46 | | - Machines().ExecuteCommand(START_COMMAND_NAME) |
47 | | - |
48 | | - @staticmethod |
49 | | - def stop_fsm(): |
50 | | - Machines().ExecuteCommand(STOP_COMMAND_NAME) |
51 | | - Machines().ReturnToStart() |
52 | | - CommandQueue().EmptyAllCommands() |
53 | | - |
54 | | - @staticmethod |
55 | | - def reset_fsm(): |
56 | | - OPERATION.stop_fsm() |
57 | | - OPERATION.start_fsm() |
58 | | - |
59 | | - @staticmethod |
60 | | - def run_fsm(cmd=None): |
61 | | - if cmd is None: |
62 | | - Machines().ExecuteAllCommands() |
63 | | - else: |
64 | | - Machines().ExecuteCommand(cmd) |
65 | | - |
66 | | - |
67 | | -class INTERFACE: |
68 | | - |
69 | | - @staticmethod |
70 | | - def run_command_if_lambda_on_result_true(lambda_func: callable, command: str): |
71 | | - def wrapper_out(func): |
72 | | - @wraps(func) |
73 | | - def wrapper_in(*args, **kwargs): |
74 | | - result = func(*args, **kwargs) |
75 | | - if lambda_func(result): |
76 | | - Machines().ExecuteCommand(command) |
77 | | - return result |
78 | | - return wrapper_in |
79 | | - return wrapper_out |
0 commit comments