-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.py
More file actions
44 lines (37 loc) · 1.22 KB
/
action.py
File metadata and controls
44 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from registry import operations, operations_id_overrides
class Action:
"""
action: 'window[0,900]'
op: 'window'
optargs: '[0,900]'
action.id_name: 'window0-900'
"""
def __init__(self, action_string):
self.action_string = action_string
# Determine op and params
params = None
if '[' in action_string:
op, _, params = action_string.rpartition('[')
params = params.rstrip(']').split(',')
else:
op = action_string
self.op = op
self.params = params
# Determine id name (used to identify folder where to store neural nets)
if op in operations_id_overrides:
self.id_name = operations_id_overrides[op]
else:
translation_table = str.maketrans({
'[': None,
']': None,
',': '-'
})
self.id_name = action_string.translate(translation_table)
def __repr__(self):
return "Action('%s')" % self.action_string
@classmethod
def get_actions_from_conf(cls, conf):
actions = []
for action_string in conf.actions:
actions.append(Action(action_string))
return actions