Skip to content

Commit cadae83

Browse files
authored
2 parents 79e41d8 + 56abe33 commit cadae83

File tree

9 files changed

+172
-150
lines changed

9 files changed

+172
-150
lines changed

src/Action.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class Action:
2-
def __init__(self, expression :str):
2+
def __init__(self, expression: str):
33
self.expression = expression
4-
4+
55
@staticmethod
66
def to_string():
77
result_s = ""
8-
return result_s
8+
return result_s

src/Actions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
class Actions:
2-
def __init__(self, actions = None):
2+
def __init__(self, actions=None):
33
if actions is None:
44
actions = []
55
self.actions_list = actions
6+
67
@staticmethod
78
def to_string():
89
result_s = ""
9-
return result_s
10+
return result_s

src/Condition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class Condition:
2-
def __init__(self, expression :str, result : str ):
2+
def __init__(self, expression: str, result: str):
33
self.expression = expression
44
self.result = result
5-
5+
66
@staticmethod
77
def to_string():
88
result_s = ""
9-
return result_s
9+
return result_s

src/Conditions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class Conditions:
2-
def __init__(self, conditions = None ):
2+
def __init__(self, conditions=None):
33
if conditions is None:
44
conditions = []
55
self.conditions_list = conditions
66

77
@staticmethod
88
def to_string():
99
result_s = ""
10-
return result_s
10+
return result_s

src/Event.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import Actions
22
import Conditions
33

4+
45
class Event:
5-
def __init__(self, name :str, to_state: str, pre_conditions: Conditions, post_conditions: Conditions, pre_actions: Actions, post_actions: Actions):
6+
def __init__(self, name: str, to_state: str, pre_conditions: Conditions, post_conditions: Conditions, pre_actions: Actions, post_actions: Actions):
67
self.name = name
78
self.to_state = to_state
89
self.pre_conditions = pre_conditions
910
self.post_conditions = post_conditions
1011
self.pre_actions = pre_actions
1112
self.post_actions = post_actions
12-
13+
1314
def to_string(self):
1415
result_s = "Event: \n"
1516
result_s += "\tName: " + self.name + "\n"
1617
result_s += "\tToState: " + self.to_state + "\n"
1718
result_s += "\tPreConditions: " + self.pre_conditions.to_string() + "\n"
1819
result_s += "\tPostConditions: " + self.post_conditions.to_string() + "\n"
1920
result_s += "\tPreActions: " + self.pre_actions.to_string() + "\n"
20-
result_s += "\tPostActions: " + self.post_actions.to_string() + "\n"
21-
return result_s
21+
result_s += "\tPostActions: " + self.post_actions.to_string() + "\n"
22+
return result_s

src/ReadStateMachine.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import defusedxml.ElementTree as ET
88

99

10-
def ReadStateMachineFile(xml_file : str):
10+
def ReadStateMachineFile(xml_file: str):
1111
states = {}
1212
initial_state = ""
1313
tree = ET.parse(xml_file)
1414
root = tree.getroot()
1515
for states_child in root:
1616
#print(states_child.tag, states_child.attrib)
1717
# States Element
18-
if states_child.tag == "State" :
18+
if states_child.tag == "State":
1919
#print("State element")
2020
# State Element
2121
state_name = ""
@@ -27,13 +27,13 @@ def ReadStateMachineFile(xml_file : str):
2727
# State->Event Element
2828
event_name = ""
2929
to_state = ""
30-
pre_conditions = None # dummy
31-
post_conditions = None # dummy
32-
pre_actions = None #dummy
33-
post_actions = None #dummy
34-
30+
pre_conditions = None # dummy
31+
post_conditions = None # dummy
32+
pre_actions = None # dummy
33+
post_actions = None # dummy
34+
3535
for event_child in state_child:
36-
36+
3737
#print(event_child.tag, event_child.attrib)
3838
if event_child.tag == "Name":
3939
#print("Name element = ", event_child.text)
@@ -47,7 +47,7 @@ def ReadStateMachineFile(xml_file : str):
4747
# State->Event->PreConditions Element
4848
pre_condition_elements = []
4949
for preconditions_child in event_child:
50-
#print(preconditions_child.text)
50+
# print(preconditions_child.text)
5151
# State->Event->PreConditions->Condition Element
5252
if preconditions_child.tag == "Condition":
5353
expression = ""
@@ -57,13 +57,14 @@ def ReadStateMachineFile(xml_file : str):
5757
expression = condition_child.text
5858
elif condition_child.tag == "Result":
5959
result = condition_child.text
60-
pre_condition_elements.append(Condition(expression,result))
60+
pre_condition_elements.append(
61+
Condition(expression, result))
6162
pre_conditions = Conditions(pre_condition_elements)
6263
elif event_child.tag == "PostConditions":
6364
# State->Event->PostConditions Element
6465
post_condition_elements = []
6566
for postconditions_child in event_child:
66-
#print(postconditions_child.text)
67+
# print(postconditions_child.text)
6768
# State->Event->PostConditions->Condition Element
6869
if postconditions_child.tag == "Condition":
6970
expression = ""
@@ -73,48 +74,53 @@ def ReadStateMachineFile(xml_file : str):
7374
expression = condition_child.text
7475
elif condition_child.tag == "Result":
7576
result = condition_child.text
76-
post_condition_elements.append(Condition(expression,result))
77-
post_conditions = Conditions(post_condition_elements)
77+
post_condition_elements.append(
78+
Condition(expression, result))
79+
post_conditions = Conditions(
80+
post_condition_elements)
7881
elif event_child.tag == "PreActions":
7982
# State->Event->PreActions Element
8083
pre_action_elements = []
8184
for preactions_child in event_child:
82-
#print(preactions_child.text)
85+
# print(preactions_child.text)
8386
# State->Event->PreActions->Action Element
8487
if preactions_child.tag == "Action":
85-
expression = ""
88+
expression = ""
8689
for action_child in preactions_child:
8790
if action_child.tag == "Expression":
8891
expression = action_child.text
89-
pre_action_elements.append(Action(expression))
92+
pre_action_elements.append(
93+
Action(expression))
9094
pre_actions = Actions(pre_action_elements)
9195

9296
elif event_child.tag == "PostActions":
9397
# State->Event->PostActions Element
9498
post_action_elements = []
9599
for postactions_child in event_child:
96-
#print(postactions_child.text)
100+
# print(postactions_child.text)
97101
# State->Event->PostActions->Action Element
98102
if postactions_child.tag == "Action":
99-
expression = ""
103+
expression = ""
100104
for action_child in postactions_child:
101105
if action_child.tag == "Expression":
102106
expression = action_child.text
103-
post_action_elements.append(Action(expression))
107+
post_action_elements.append(
108+
Action(expression))
104109
post_actions = Actions(post_action_elements)
105-
106-
events[event_name] = Event(event_name,to_state,pre_conditions,post_conditions,pre_actions,post_actions)
107-
#print(event.to_string())
110+
111+
events[event_name] = Event(
112+
event_name, to_state, pre_conditions, post_conditions, pre_actions, post_actions)
113+
# print(event.to_string())
108114
elif state_child.tag == "Name":
109115
#print("Name element = ", state_child.text)
110116
# State->Name Element
111117
state_name = state_child.text
112-
118+
113119
states[state_name] = State(state_name, events)
114-
115-
elif states_child.tag == "Initial_State" :
120+
121+
elif states_child.tag == "Initial_State":
116122
#print ("Initial_State element = ", states_child.text)
117123
# Initial_State Element
118-
initial_state = states_child.text
119-
120-
return states, initial_state
124+
initial_state = states_child.text
125+
126+
return states, initial_state

src/State.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
class State:
2-
def __init__(self, name: str, events = None):
2+
def __init__(self, name: str, events=None):
33
if events is None:
44
events = {}
55
self.name = name
66
self.events = events
7-
7+
88
def to_string(self):
99
result_s = "State:\n"
1010
result_s += " Name: " + self.name + "\n"
1111
result_s += " Events: \n"
1212
for event in self.events.items():
1313
result_s += " " + event[1].to_string() + "\n"
14-
return result_s
14+
return result_s

0 commit comments

Comments
 (0)