1 | import os,XDR,time,shutil |
---|
2 | |
---|
3 | RUNAPPLIDIR=r'\\winappl\calcul2000\Runappli\Simu\V04R02' |
---|
4 | |
---|
5 | class snecma_windows2zephyr(XDR.Plugin): |
---|
6 | |
---|
7 | def __init__(self,typePlugin): |
---|
8 | XDR.Plugin.__init__(self, typePlugin) |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | @XDR.supported_applications(["tool_avsp52","hip_current","hip_script","yales2"]) |
---|
13 | def executeDistantCommand(self,command,exec_directory,appli,flags=[]): |
---|
14 | print "Plugin : Using Robot Unix : "+command+" ("+appli+")" |
---|
15 | |
---|
16 | |
---|
17 | ######## |
---|
18 | # INITS |
---|
19 | ######## |
---|
20 | command_exe = command |
---|
21 | supported_applis = [] |
---|
22 | local_directory = os.getcwd() |
---|
23 | project_name = XDR.getValue("name","project","meta") |
---|
24 | |
---|
25 | |
---|
26 | ############################################################################## |
---|
27 | ############################################################################## |
---|
28 | ############################################################################## |
---|
29 | |
---|
30 | ######## |
---|
31 | # AVSP # |
---|
32 | ######## |
---|
33 | if appli == "tool_avsp52": |
---|
34 | toolAVSPhome = "/appl/APPLI_SNECMA/AVSP/test/5.2/AVSP_HOME/HOST/ZEPHYR/TOOLEXEC" |
---|
35 | if command == "-c3sm_auto_avbp2avsp_exec-": |
---|
36 | command_exe = toolAVSPhome + "/avbp2avsp_ZEPHYR.exe" |
---|
37 | if command == "-c3sm_auto_avspinitsol_exec-": |
---|
38 | command_exe = toolAVSPhome + "/avspinitsol_ZEPHYR.exe" |
---|
39 | if command == "-c3sm_auto_preproc_mlpf_exec-": |
---|
40 | command_exe = toolAVSPhome + "/preproc_mlpf_ZEPHYR.exe" |
---|
41 | if command == "-c3sm_auto_zinn_exec-": |
---|
42 | command_exe = toolAVSPhome + "/Zinn_nozzle_ZEPHYR.exe" |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | ####### |
---|
47 | # HIP # |
---|
48 | ####### |
---|
49 | if appli == "hip_current": |
---|
50 | homehip="/appl/APPLI_SNECMA/HIP/test/" |
---|
51 | hip_cur_version = homehip + "1.39.3" + "/hip.exe" |
---|
52 | if command.startswith("-c3sm_auto_hip-"): |
---|
53 | command_exe = command.replace("-c3sm_auto_hip-",hip_cur_version) |
---|
54 | elif command == "-c3s_auto_hip_scripttxt-": |
---|
55 | command_exe= hip_cur_version+" < ./script.txt" |
---|
56 | |
---|
57 | if appli == "hip_script": |
---|
58 | homehip="/appl/APPLI_SNECMA/HIP/test/" |
---|
59 | hip_cur_version = homehip + "1.39.3" + "/hip.exe" |
---|
60 | command_exe = hip_cur_version+ " < " + command |
---|
61 | |
---|
62 | ######## |
---|
63 | # YALES2 # |
---|
64 | ######## |
---|
65 | |
---|
66 | if appli == "yales2" : |
---|
67 | if command == "-load_chemtable-": |
---|
68 | temp_path = exec_directory |
---|
69 | table_path = '/data/Recherches/METHODES_LES/_Chambre/TAF/YALES2/TABLES_CHIMIQUES/' |
---|
70 | XDR.replace_pattern_in_file(os.path.join(temp_path,"batch_chemtable"),"-table_path-",table_path) |
---|
71 | ##### |
---|
72 | # Prepare command |
---|
73 | command_exe = "chmod +x ./batch_chemtable; dos2unix ./batch_chemtable; ./batch_chemtable" |
---|
74 | |
---|
75 | |
---|
76 | ############################################################################## |
---|
77 | ############################################################################## |
---|
78 | ############################################################################## |
---|
79 | |
---|
80 | if command_exe.startswith("-c3sm_auto_"): |
---|
81 | XDR.error("command was not understood: "+command_exe ) |
---|
82 | |
---|
83 | |
---|
84 | # get the user name |
---|
85 | username = os.getenv('USERNAME') |
---|
86 | |
---|
87 | # get the original path |
---|
88 | oldDir = os.path.abspath(os.getcwd()) |
---|
89 | |
---|
90 | # build the path to the tool |
---|
91 | fullexec_directory = os.path.join(oldDir,exec_directory) |
---|
92 | |
---|
93 | |
---|
94 | # convert into UNIX path |
---|
95 | fullexec_directory_unix = self.convert_unc_filename(fullexec_directory) |
---|
96 | |
---|
97 | # open the user's robot input file, and set the operating directory |
---|
98 | user_robot_file = os.path.join(r"\\windata\128_Recherches\METHODES_LES\_Chambre\TAF\C3SM", username, "robot.in") |
---|
99 | inputfile = open(user_robot_file, 'w') |
---|
100 | inputfile.writelines(fullexec_directory_unix) |
---|
101 | inputfile.close() |
---|
102 | |
---|
103 | |
---|
104 | os.chdir(exec_directory) |
---|
105 | print "Robot archive created in "+fullexec_directory |
---|
106 | |
---|
107 | # create the batch |
---|
108 | batchname = os.path.join(fullexec_directory,"batch_c3sm.todo") |
---|
109 | batchname_done = os.path.join(fullexec_directory,"batch_c3sm.done") |
---|
110 | batchname_run = os.path.join(fullexec_directory,"batch_c3sm.run") |
---|
111 | batchname_fail = os.path.join(fullexec_directory,"batch_c3sm.fail") |
---|
112 | |
---|
113 | |
---|
114 | batchContent = "#!/bin/sh \n" |
---|
115 | batchContent+=command_exe |
---|
116 | batchFile = open(batchname,'w') |
---|
117 | batchFile.write(batchContent) |
---|
118 | batchFile.close() |
---|
119 | |
---|
120 | # ONCE THE BATCH is created, the robot should work on it withing 5 sec |
---|
121 | status = "waiting" |
---|
122 | # check is job is processed |
---|
123 | max_delay = 15 |
---|
124 | delay = 0 |
---|
125 | while status=="waiting": |
---|
126 | time.sleep(0.01) |
---|
127 | print "Waiting for the robot :"+batchname_run |
---|
128 | if os.path.exists(batchname_run): |
---|
129 | status="running" |
---|
130 | if os.path.exists(batchname_done): |
---|
131 | status="done" |
---|
132 | print "First loop" |
---|
133 | |
---|
134 | time.sleep(2) |
---|
135 | delay += 2 |
---|
136 | if delay >= max_delay : |
---|
137 | print "Warning : "+str(max_delay)+" sec without answer from the robot \n Please, check if your robot is up and running on Zephyr" |
---|
138 | status="no_robot" |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | # check if job is done, max 30 min |
---|
143 | max_delay = 1800 |
---|
144 | while status=="running" : |
---|
145 | time.sleep(0.01) |
---|
146 | print "Waiting for the end of the run :" |
---|
147 | if os.path.exists(batchname_done): |
---|
148 | status="done" |
---|
149 | if os.path.exists(batchname_fail): |
---|
150 | status="fail" |
---|
151 | error("Robot tried to execute the tool and failed...") |
---|
152 | print "Second loop" |
---|
153 | time.sleep(2) |
---|
154 | delay += 2 |
---|
155 | |
---|
156 | if delay >= max_delay : |
---|
157 | print "Warning : "+str(max_delay)+" sec without answer from the robot \n Run beyond the time limit of robot" |
---|
158 | status="too_long" |
---|
159 | |
---|
160 | print "Final status : "+status |
---|
161 | print "Final delay : "+str(delay) +" sec." |
---|
162 | |
---|
163 | |
---|
164 | # clean the robot input file to stop him from searching |
---|
165 | inputfile = open(user_robot_file, 'w') |
---|
166 | inputfile.close() |
---|
167 | try: |
---|
168 | os.remove(batchname_done) |
---|
169 | except Exception: |
---|
170 | pass |
---|
171 | |
---|
172 | # come back to old directory |
---|
173 | os.chdir(oldDir) |
---|
174 | |
---|
175 | def retrieveDirectory(self,directory): |
---|
176 | # Do nothing as we are local |
---|
177 | pass |
---|
178 | |
---|
179 | def removeDirectory(self,directory): |
---|
180 | pass |
---|
181 | |
---|
182 | def convert_unc_filename(self,filepath): |
---|
183 | import sys,os |
---|
184 | |
---|
185 | if os.path.isdir(RUNAPPLIDIR): |
---|
186 | p=os.path.join(RUNAPPLIDIR,'PyModules') |
---|
187 | if not p in sys.path: sys.path.append(p) |
---|
188 | import Filesystem |
---|
189 | Filesystem.FILE=os.path.join(RUNAPPLIDIR,'Env','UNC.txt') |
---|
190 | unix_filename = Filesystem.convert_unc_filename(filepath,strict=1) |
---|
191 | if not unix_filename: |
---|
192 | XDR.error("Le chemin '%s' n'existe pas sous unix.\nVerifier que votre projet est construit sur \\\\windata"%filepath) |
---|
193 | else: |
---|
194 | XDR.error("Le repertoire '%s' n'existe plus.\nContacter le garant pour qu'il mette a jour la ligne 3 du plugin %%C3SM_HOME%%\\library\\DATA\\pluginscripts\\snecma_windows2zephyr.py"%RUNAPPLIDIR) |
---|
195 | return unix_filename |
---|
196 | |
---|
197 | def convert_nfs_filename(self,filepath): |
---|
198 | import sys,os |
---|
199 | |
---|
200 | if os.path.isdir(RUNAPPLIDIR): |
---|
201 | p=os.path.join(RUNAPPLIDIR,'PyModules') |
---|
202 | if not p in sys.path: sys.path.append(p) |
---|
203 | import Filesystem |
---|
204 | Filesystem.FILE=os.path.join(RUNAPPLIDIR,'Env','UNC.txt') |
---|
205 | windows_filename = Filesystem.convert_nfs_filename(filepath) |
---|
206 | if not windows_filename: |
---|
207 | XDR.error("Le chemin '%s' n'existe pas sous unix.\nVerifier que votre projet est construit sur \\\\windata"%filepath) |
---|
208 | else: |
---|
209 | XDR.error("Le repertoire '%s' n'existe plus.\nContacter le garant pour qu'il mette a jour la ligne 3 du plugin %%C3SM_HOME%%\\library\\DATA\\pluginscripts\\snecma_windows2zephyr.py"%RUNAPPLIDIR) |
---|
210 | return windows_filename |
---|
211 | |
---|