1 | import os,XDR,shutil |
---|
2 | |
---|
3 | from avbp import plugin_avbp |
---|
4 | from avtp import plugin_avtp |
---|
5 | from avsp import plugin_avsp |
---|
6 | from prissma import plugin_prissma |
---|
7 | |
---|
8 | |
---|
9 | DISTANT_UNIX_DIRECTORY = "C3Sm_projects" |
---|
10 | |
---|
11 | class distant_unix(XDR.Plugin): |
---|
12 | def __init__(self,typePlugin): |
---|
13 | """ This method built a new instance of plugin. |
---|
14 | First it constructs the plugin thanks to mother class : XDR.Plugin""" |
---|
15 | # Il ne faut surtout pas supprimer cette ligne |
---|
16 | XDR.Plugin.__init__(self, typePlugin) |
---|
17 | |
---|
18 | |
---|
19 | self.login = self.getPluginParam("login") |
---|
20 | self.machine = self.getPluginParam("machine") |
---|
21 | self.distantDirectory = self.getPluginParam("directory") |
---|
22 | self.dir2send = [] |
---|
23 | |
---|
24 | |
---|
25 | # test connexion |
---|
26 | sshCommand = 'echo "Ssh connection is ok..." ' |
---|
27 | print "Running command : "+sshCommand |
---|
28 | test = XDR.ssh(self.machine,self.login, sshCommand, options=" -qo PasswordAuthentication=no") |
---|
29 | |
---|
30 | # create the DISTANT_UNIX_DIRECTORY on the distant machine |
---|
31 | sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+DISTANT_UNIX_DIRECTORY+""" ] ; then mkdir """+DISTANT_UNIX_DIRECTORY+""" ; fi" """ |
---|
32 | #XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'") |
---|
33 | XDR.ssh(self.machine,self.login, sshCommand, options="") |
---|
34 | |
---|
35 | |
---|
36 | self.distantDirectory = os.path.join(self.distantDirectory,DISTANT_UNIX_DIRECTORY) |
---|
37 | |
---|
38 | # then create the project_name folder if needed |
---|
39 | project_name = XDR.getValue("name","project","meta") |
---|
40 | sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+project_name+""" ] ; then mkdir """+project_name+""" ; fi" """ |
---|
41 | XDR.ssh(self.machine,self.login, sshCommand, options="") |
---|
42 | |
---|
43 | |
---|
44 | self.distantDirectory = os.path.join(self.distantDirectory,project_name) |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | #def sendDirectory(self,directory): |
---|
49 | # |
---|
50 | # local_directory = os.path.abspath(directory) |
---|
51 | # directory_basename = os.path.basename(local_directory) |
---|
52 | # |
---|
53 | # if os.path.exists(local_directory): |
---|
54 | # pass |
---|
55 | # else: |
---|
56 | # raise Exception("Error : "+directory+" doesn't exist") |
---|
57 | # |
---|
58 | # self.dir2send.append(directory) |
---|
59 | # print "Adding "+directory +" to the list of folders for the archive" |
---|
60 | # print self.dir2send |
---|
61 | # |
---|
62 | # #local_directory = os.path.abspath(directory) |
---|
63 | # #dist_directory = os.path.basename(local_directory) |
---|
64 | # # |
---|
65 | # #if os.path.exists(local_directory): |
---|
66 | # # print "Plugin : distant_unix sending directory "+local_directory +" at "+ self.distantDirectory |
---|
67 | # # |
---|
68 | # #else: |
---|
69 | # # raise Exception("Error : "+directory+" doesn't exist") |
---|
70 | # # |
---|
71 | # # |
---|
72 | # #XDR.execute("scp -r "+local_directory+" "+self.login+"@"+self.machine+":"+self.distantDirectory+"/") |
---|
73 | # ##XDR.execute("rsync -a "+local_directory+" "+self.login+"@"+self.machine+":"+self.distantDirectory) |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | @XDR.supported_applications(['tool_avsp52','tool_avbp621','tool_avtp2','tool_icritles','tool_prissma','projeteur','projeteur','hip_current','hip_script','mps_script','coolant','dummy']) |
---|
78 | |
---|
79 | def executeDistantCommand(self,command,execDirectory,appli,flags=[]): |
---|
80 | |
---|
81 | print "Plugin : Running executeDistantCommand "+command+" in "+execDirectory+"("+appli+")" |
---|
82 | |
---|
83 | |
---|
84 | ######## |
---|
85 | # INITS |
---|
86 | ######## |
---|
87 | command_exe = command |
---|
88 | supported_applis = [] |
---|
89 | local_directory = os.getcwd() |
---|
90 | project_name = XDR.getValue("name","project","meta") |
---|
91 | |
---|
92 | hostname = "KALI" |
---|
93 | pythonexec= "/usr/bin/python" |
---|
94 | |
---|
95 | |
---|
96 | hip_cur_version = "/home/rolex/HIP/1.41.0/hip-1.41.0-"+hostname |
---|
97 | |
---|
98 | ################################################################################################################################## |
---|
99 | ################################################################################################################################## |
---|
100 | ################################################################################################################################## |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | ######## |
---|
107 | # AVSP # |
---|
108 | ######## |
---|
109 | if appli == "tool_avsp52": |
---|
110 | avsp_home = "/home/rolex/QUIET_5.3/AVSP_HOME" |
---|
111 | # Temporary, bug with axisym duplication in HIP v1.41.0 |
---|
112 | hip_cur_version = "/home/rolex/HIP/1.40.1/hip-1.40.1-"+hostname |
---|
113 | avsptool = plugin_avsp(avsp_home,hostname,hip_cur_version,pythonexec,execDirectory) |
---|
114 | command_exe = avsptool.switch_avsp_tools(appli,command) |
---|
115 | |
---|
116 | |
---|
117 | ####### |
---|
118 | # HIP # |
---|
119 | ####### |
---|
120 | if appli == "hip_current": |
---|
121 | if command.startswith("-c3sm_auto_hip-"): |
---|
122 | command_exe = command.replace("-c3sm_auto_hip-",hip_cur_version) |
---|
123 | elif command == "-c3s_auto_hip_scripttxt-": |
---|
124 | command_exe= hip_cur_version+" < ./script.txt" |
---|
125 | |
---|
126 | if appli == "hip_script": |
---|
127 | command_exe = hip_cur_version+" < " + command |
---|
128 | |
---|
129 | |
---|
130 | ############# |
---|
131 | # PROJETEUR # |
---|
132 | ############# |
---|
133 | if appli == "projeteur": |
---|
134 | if command == "-c3s_auto_hip_dumpskin-": |
---|
135 | XDR.replace_pattern_in_file(os.path.join(execDirectory,"script_skin.py"),"-c3sm_auto_hip-",hip_cur_version) |
---|
136 | XDR.replace_pattern_in_file(os.path.join(execDirectory,"script_skin.py"),"-c3sm_auto_h5dump-","h5dump") |
---|
137 | command_exe = "/usr/bin/python ./script_skin.py" |
---|
138 | |
---|
139 | ########### |
---|
140 | # COOLANT # |
---|
141 | ########### |
---|
142 | if appli == "coolant": |
---|
143 | coolant_version = "/home/rolex/exe_coolant_rolex/coolant09.x.LINUX" |
---|
144 | if command == "-c3sm_auto_coolant-": |
---|
145 | command_exe = coolant_version+ " < ./input_coolant.dat" |
---|
146 | |
---|
147 | ######## |
---|
148 | # AVBP # |
---|
149 | ######## |
---|
150 | if appli == "tool_avbp621": |
---|
151 | avbp_home = "/home/rolex/AVBP_V6.X/AVBP_D6.2.1" |
---|
152 | avbptool = plugin_avbp(avbp_home,hostname,hip_cur_version,pythonexec,execDirectory) |
---|
153 | command_exe = avbptool.switch_avbp_tools(appli,command) |
---|
154 | |
---|
155 | ############ |
---|
156 | # ICRITLES # |
---|
157 | ############ |
---|
158 | if appli == "tool_icritles": |
---|
159 | if command == "-c3sm_auto_icritles-": |
---|
160 | avbp_home = "/home/rolex/AVBP_V6.X/AVBP_D6.2.1" |
---|
161 | command_exe = avbp_home+"/HOST/"+hostname+"/TOOLEXEC/i_crit_les.e_"+hostname |
---|
162 | |
---|
163 | ######## |
---|
164 | # MPS # |
---|
165 | ######## |
---|
166 | if appli == "mps_script": |
---|
167 | if command.startswith("-c3sm_auto"): |
---|
168 | if command == "-c3sm_auto_mps-" : |
---|
169 | datafile = os.path.join(self.distantDirectory,execDirectory,"aerotherm.xml") |
---|
170 | # execDirectory = "/home/rolex/multiphysics_setup" |
---|
171 | command_exe = "cd /home/rolex/multiphysics_setup ; mpview -aerotherm_xml "+datafile |
---|
172 | |
---|
173 | |
---|
174 | ######## |
---|
175 | # AVTP # |
---|
176 | ######## |
---|
177 | if appli == "tool_avtp2": |
---|
178 | avtp_home = "/home/rolex/AVTP/AVTP_V2.X" |
---|
179 | avtptool = plugin_avtp(avtp_home,hostname,hip_cur_version,pythonexec,execDirectory) |
---|
180 | command_exe = avtptool.switch_avtp_tools(appli,command) |
---|
181 | |
---|
182 | |
---|
183 | ########### |
---|
184 | # PRISSMA # |
---|
185 | ########### |
---|
186 | if appli == "tool_prissma": |
---|
187 | avbp_home = "/home/rolex/AVBP_V6.X/AVBP_D6.2.1" |
---|
188 | prissma_home = "/home/avtp_wkdir/PRISSMA/trunk/" |
---|
189 | prissmatool = plugin_prissma(prissma_home,avbp_home,hostname,hip_cur_version,pythonexec,execDirectory) |
---|
190 | command_exe = prissmatool.switch_prissma_tools(appli,command) |
---|
191 | |
---|
192 | ################################################################################################################################## |
---|
193 | ################################################################################################################################## |
---|
194 | ################################################################################################################################## |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | if command_exe.startswith("-c3sm_auto_"): |
---|
199 | XDR.error("command was not understood: "+command_exe ) |
---|
200 | |
---|
201 | |
---|
202 | ##################### |
---|
203 | # SENDING DIRECTORY # |
---|
204 | ##################### |
---|
205 | print "Final composition of c3sm_archive:" |
---|
206 | print self.dir2send |
---|
207 | XDR.ssh_send(self.machine,self.login, self.distantDirectory, self.dir2send, options="") |
---|
208 | |
---|
209 | |
---|
210 | ##################### |
---|
211 | # EXECUTING COMMAND # |
---|
212 | ##################### |
---|
213 | sshCommand = "cd "+self.distantDirectory+"/"+execDirectory+"; "+command_exe |
---|
214 | # NB : -X allows here an interactive action |
---|
215 | output = XDR.ssh(self.machine,self.login, sshCommand, options="-X") |
---|
216 | |
---|
217 | # back to the initial directory |
---|
218 | os.chdir(local_directory) |
---|
219 | return output |
---|
220 | |
---|
221 | def retrieveDirectory(self,directory): |
---|
222 | |
---|
223 | local_directory = os.path.abspath(directory) |
---|
224 | dist_directory = os.path.basename(local_directory) |
---|
225 | # Retrieve Directory |
---|
226 | if os.path.exists(local_directory): |
---|
227 | shutil.rmtree(local_directory) |
---|
228 | |
---|
229 | #XDR.ssh_retrieve(self.machine,self.login, self.distantDirectory+"/"+dist_directory, os.path.dirname(local_directory), options="") |
---|
230 | #scpCommand = "scp -r "+self.login+"@"+self.machine+":"+self.distantDirectory+"/"+dist_directory+" "+os.path.dirname(local_directory) |
---|
231 | # DANGEROUS , Il faudrait desaliaser le rsync au cas ou l'utilisateur l'aurait surcharge" |
---|
232 | scpCommand = "rsync -a "+self.login+"@"+self.machine+":"+self.distantDirectory+"/"+dist_directory+" "+os.path.dirname(local_directory) |
---|
233 | XDR.execute(scpCommand) |
---|
234 | |
---|
235 | |
---|
236 | def removeDirectory(self,directory): |
---|
237 | sshCommand = "/bin/rm -rf "+self.distantDirectory+"/"+directory |
---|
238 | output = XDR.ssh(self.machine,self.login, sshCommand, options="-X") |
---|
239 | #XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'") |
---|
240 | |
---|
241 | |
---|
242 | |
---|