7
7
from cmind .automation import Automation
8
8
from cmind import utils
9
9
10
+
10
11
class CAutomation (Automation ):
11
12
"""
12
13
CM "automation" automation actions
@@ -35,12 +36,12 @@ def print_input(self, i):
35
36
"""
36
37
37
38
import json
38
- print (json .dumps (i , indent = 2 ))
39
-
40
- return {'return' :0 }
39
+ print (json .dumps (i , indent = 2 ))
41
40
41
+ return {'return' : 0 }
42
42
43
43
############################################################
44
+
44
45
def add (self , i ):
45
46
"""
46
47
Add CM automation.
@@ -66,36 +67,40 @@ def add(self, i):
66
67
67
68
console = i .get ('out' ) == 'con'
68
69
69
- parsed_artifact = i .get ('parsed_artifact' ,[])
70
+ parsed_artifact = i .get ('parsed_artifact' , [])
70
71
71
- artifact_obj = parsed_artifact [0 ] if len (parsed_artifact )> 0 else ('' ,'' )
72
+ artifact_obj = parsed_artifact [0 ] if len (
73
+ parsed_artifact ) > 0 else ('' , '' )
72
74
73
75
module_name = 'module.py'
74
76
75
77
tags_list = utils .convert_tags_to_list (i )
76
- if 'automation' not in tags_list : tags_list .append ('automation' )
78
+ if 'automation' not in tags_list :
79
+ tags_list .append ('automation' )
77
80
78
81
# Add placeholder (use common action)
79
- i ['out' ]= 'con'
80
- i ['common' ]= True
82
+ i ['out' ] = 'con'
83
+ i ['common' ] = True
81
84
82
- i ['meta' ]= {'automation_alias' :self .meta ['alias' ],
83
- 'automation_uid' :self .meta ['uid' ],
84
- 'tags' :tags_list }
85
+ i ['meta' ] = {'automation_alias' : self .meta ['alias' ],
86
+ 'automation_uid' : self .meta ['uid' ],
87
+ 'tags' : tags_list }
85
88
86
- if 'tags' in i : del (i ['tags' ])
89
+ if 'tags' in i :
90
+ del (i ['tags' ])
87
91
88
92
automation = i ['automation' ]
89
- if automation != '.' and ',' not in automation :
93
+ if automation != '.' and ',' not in automation :
90
94
i ['automation' ] = automation + ',' + self .meta ['uid' ]
91
95
92
- r_obj = self .cmind .access (i )
93
- if r_obj ['return' ]> 0 : return r_obj
96
+ r_obj = self .cmind .access (i )
97
+ if r_obj ['return' ] > 0 :
98
+ return r_obj
94
99
95
100
new_automation_path = r_obj ['path' ]
96
101
97
102
if console :
98
- print ('Created automation in {}' .format (new_automation_path ))
103
+ print ('Created automation in {}' .format (new_automation_path ))
99
104
100
105
# Create Python module holder
101
106
module_holder_path = new_automation_path
@@ -106,12 +111,12 @@ def add(self, i):
106
111
# Copy module files
107
112
for f in ['module_dummy.py' ]:
108
113
f1 = os .path .join (self .path , f )
109
- f2 = os .path .join (new_automation_path , f .replace ('_dummy' ,'' ))
114
+ f2 = os .path .join (new_automation_path , f .replace ('_dummy' , '' ))
110
115
111
116
if console :
112
- print (' * Copying {} to {}' .format (f1 , f2 ))
117
+ print (' * Copying {} to {}' .format (f1 , f2 ))
113
118
114
- shutil .copyfile (f1 ,f2 )
119
+ shutil .copyfile (f1 , f2 )
115
120
116
121
return r_obj
117
122
@@ -137,33 +142,37 @@ def add_cmx(self, i):
137
142
138
143
# Prepare to call common function
139
144
r = utils .process_input (i )
140
- if r ['return' ]> 0 : return r
145
+ if r ['return' ] > 0 :
146
+ return r
141
147
142
148
# Take only out from original control
143
- i ['control' ]= {'out' :i ['control' ]['out' ],
144
- 'common' :True }
149
+ i ['control' ] = {'out' : i ['control' ]['out' ],
150
+ 'common' : True }
145
151
146
152
tags_list = utils .convert_tags_to_list (i )
147
- if 'automation' not in tags_list : tags_list .append ('automation' )
153
+ if 'automation' not in tags_list :
154
+ tags_list .append ('automation' )
148
155
149
- i ['meta' ]= {'automation_alias' :self .meta ['alias' ],
150
- 'automation_uid' :self .meta ['uid' ],
151
- 'tags' :tags_list }
156
+ i ['meta' ] = {'automation_alias' : self .meta ['alias' ],
157
+ 'automation_uid' : self .meta ['uid' ],
158
+ 'tags' : tags_list }
152
159
153
- if 'tags' in i : del (i ['tags' ])
160
+ if 'tags' in i :
161
+ del (i ['tags' ])
154
162
155
163
# Use yaml by default
156
164
if 'yaml' not in i :
157
165
i ['yaml' ] = True
158
166
159
167
# Pass to common action
160
168
r_obj = self .cmind .x (i )
161
- if r_obj ['return' ]> 0 : return r_obj
169
+ if r_obj ['return' ] > 0 :
170
+ return r_obj
162
171
163
172
new_automation_path = r_obj ['path' ]
164
173
165
174
if console :
166
- print ('Created automation in {}' .format (new_automation_path ))
175
+ print ('Created automation in {}' .format (new_automation_path ))
167
176
168
177
module_name = 'modulex.py'
169
178
@@ -176,18 +185,17 @@ def add_cmx(self, i):
176
185
# Copy module files
177
186
for f in ['modulex_dummy.py' ]:
178
187
f1 = os .path .join (self .path , f )
179
- f2 = os .path .join (new_automation_path , f .replace ('_dummy' ,'' ))
188
+ f2 = os .path .join (new_automation_path , f .replace ('_dummy' , '' ))
180
189
181
190
if console :
182
- print (' * Copying {} to {}' .format (f1 , f2 ))
191
+ print (' * Copying {} to {}' .format (f1 , f2 ))
183
192
184
- shutil .copyfile (f1 ,f2 )
193
+ shutil .copyfile (f1 , f2 )
185
194
186
195
return r_obj
187
196
188
-
189
-
190
197
############################################################
198
+
191
199
def doc (self , i ):
192
200
"""
193
201
Add CM automation.
0 commit comments