source: issm/oecreview/Archive/12678-13393/ISSM-12742-12743.diff@ 14312

Last change on this file since 14312 was 13394, checked in by Mathieu Morlighem, 13 years ago

Added 12678-13393

File size: 8.7 KB
RevLine 
[13394]1Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpin.py
2===================================================================
3--- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpin.py (revision 0)
4+++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpin.py (revision 12743)
5@@ -0,0 +1,79 @@
6+"""
7+SCPIN get packages from host, using scp on unix, and pscp on windows
8+
9+ usage: scpin(host,packages,path)
10+
11+
12+"""
13+
14+import socket
15+import platform
16+import subprocess
17+import os
18+import shutil
19+from MatlabFuncs import *
20+
21+def scpin(host, login,port,path, packages):
22+
23+ #first get hostname
24+ hostname=socket.gethostname().lower().split('.')[0]
25+
26+ #first be sure packages are not in the current directory, this could conflict with pscp on windows.
27+ #remove warnings in case the files do not exist
28+ for package in packages:
29+ try:
30+ os.remove(package)
31+ except OSError as e:
32+ pass
33+
34+ #if hostname and host are the same, do a simple copy
35+ if strcmpi(hostname,host):
36+
37+ for package in packages:
38+ try:
39+ shutil.copy(os.path.join(path,package),os.getcwd()) #keep going, even if success=0
40+ except OSError as e:
41+ pass
42+
43+ else:
44+
45+ if 'Windows' in platform.system():
46+ #use the putty project pscp.exe: it should be in the path.
47+
48+ #get ISSM_DIR variable
49+ if 'ISSM_DIR_WIN' in os.environ:
50+ ISSM_DIR=os.environ['ISSM_DIR_WIN'][1:-2]
51+ else:
52+ raise OSError("scpin error message: could not find ISSM_DIR_WIN environment variable.")
53+
54+ username=raw_input('Username: (quoted string) ')
55+ key=raw_input('Key: (quoted string) ')
56+
57+ for package in packages:
58+ try:
59+ subprocess.check_call('%s/externalpackages/ssh/pscp.exe -l "%s" -pw "%s" %s:%s %s' % (ISSM_DIR,username,key,host,os.path.join(path,package),os.getcwd()),shell=True)
60+ except CalledProcessError as e:
61+ raise CalledProcessError("scpin error message: could not call putty pscp.")
62+
63+ else:
64+ #just use standard unix scp
65+ #string to copy multiple files using scp:
66+ if len(packages)==1:
67+ string=packages[0]
68+ else:
69+ string='{'
70+ for package in packages:
71+ string+=packages[i]+','
72+ string=string[:-1]+'}'
73+
74+
75+ if port:
76+ subprocess.call('scp -P %d %s@localhost:%s %s' % (port,login,os.path.join(path,string),os.getcwd),shell=True)
77+ else:
78+ subprocess.call('scp %s@%s:%s %s' % (login,host,os.path.join(path,string),os.getcwd),shell=True)
79+
80+ #check scp worked
81+ for package in packages:
82+ if not os.path.exists(os.path.join('.',package)):
83+ raise OSError("scpin error message: could not call scp on *nix system.")
84+
85Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpout.py
86===================================================================
87--- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpout.py (revision 0)
88+++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpout.py (revision 12743)
89@@ -0,0 +1,61 @@
90+"""
91+SCPOUT send packages to a host, using scp on unix, and pscp on windows
92+
93+ usage: scpout(host,path,packages)
94+
95+
96+"""
97+
98+import socket
99+import platform
100+import subprocess
101+import os
102+import shutil
103+from MatlabFuncs import *
104+
105+def issmscpout(host,path,login,port,packages):
106+
107+ #get hostname
108+ hostname=socket.gethostname().lower().split('.')[0]
109+
110+ #if hostname and host are the same, do a simple copy
111+
112+ if strcmpi(host,hostname):
113+ for package in packages:
114+ here=os.getcwd()
115+ os.chdir(path)
116+ shutil.rmtree(package)
117+ subprocess.call('ln -s %s %s' % (os.path.join(here,package),path),shell=True)
118+ os.chdir(here)
119+ else:
120+ if 'Windows' in platform.system():
121+ #use the putty project pscp.exe: it should be in the path.
122+
123+ #get ISSM_DIR variable
124+ if 'ISSM_DIR_WIN' in os.environ:
125+ ISSM_DIR=os.environ['ISSM_DIR_WIN'][1:-2]
126+ else:
127+ raise OSError("scpout error message: could not find ISSM_DIR_WIN environment variable.")
128+
129+ username=raw_input('Username: (quoted string) ')
130+ key=raw_input('Key: (quoted string) ')
131+
132+ for package in packages:
133+ try:
134+ subprocess.check_call('%s/externalpackages/ssh/pscp.exe -l "%s" -pw "%s" %s %s:%s' % (ISSM_DIR,username,key,package,host,path),shell=True)
135+ except CalledProcessError as e:
136+ raise CalledProcessError("scpout error message: could not call putty pscp.")
137+
138+ else:
139+ #just use standard unix scp
140+ #create string of packages being sent
141+ string=''
142+ for package in packages:
143+ string+=' '+package
144+ string+=' '
145+
146+ if port:
147+ subprocess.call('scp -P %d %s %s@localhost:%s' % (port,string,login,path),shell=True)
148+ else:
149+ subprocess.call('scp %s %s@%s:%s' % (string,login,host,path),shell=True)
150+
151Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmssh.py
152===================================================================
153--- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmssh.py (revision 0)
154+++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmssh.py (revision 12743)
155@@ -0,0 +1,43 @@
156+"""
157+ISSMSSH - wrapper for OS independent ssh command.
158+
159+ usage:
160+ issmssh(host,command)
161+"""
162+
163+import socket
164+import platform
165+import subprocess
166+import os
167+from MatlabFuncs import *
168+
169+def issmssh(host,login,port,command):
170+
171+ #first get hostname
172+ hostname=socket.gethostname().lower().split('.')[0]
173+
174+ #if same as host, just run the command.
175+ if strcmpi(host,hostname):
176+ subprocess.call(command,shell=True)
177+ else:
178+ if 'Windows' in platform.system():
179+ #use the putty project plink.exe: it should be in the path.
180+
181+ #get ISSM_DIR variable
182+ if 'ISSM_DIR_WIN' in os.environ:
183+ ISSM_DIR=os.environ['ISSM_DIR_WIN'][1:-2]
184+ else:
185+ raise OSError("issmssh error message: could not find ISSM_DIR_WIN environment variable.")
186+
187+ username=raw_input('Username: (quoted string) ')
188+ key=raw_input('Key: (quoted string) ')
189+
190+ subprocess.call('%s/externalpackages/ssh/plink.exe -ssh -l "%s" -pw "%s" %s "%s"' % (ISSM_DIR,username,key,host,command),shell=True);
191+
192+ else:
193+ #just use standard unix ssh
194+ if port:
195+ subprocess.call('ssh -l %s -p %d localhost "%s"' % (login,port,command),shell=True)
196+ else:
197+ subprocess.call('ssh -l %s %s "%s"' % (login,host,command),shell=True)
198+
199Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/ispetsc.py
200===================================================================
201--- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/ispetsc.py (revision 12742)
202+++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/ispetsc.py (revision 12743)
203@@ -36,3 +36,4 @@
204 raise RuntimeError("could not determine whether PETSC was or was not compiled.")
205
206 return flag
207+
208Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpin.m
209===================================================================
210--- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpin.m (revision 12742)
211+++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpin.m (revision 12743)
212@@ -34,7 +34,7 @@
213 %get ISSM_DIR variable
214 [status,ISSM_DIR]=system('echo [%ISSM_DIR_WIN%]');
215 if status,
216- error('scpin error message: could not find ISSM_DIR_WIN envirnoment variable');
217+ error('scpin error message: could not find ISSM_DIR_WIN environment variable');
218 end
219 ISSM_DIR=ISSM_DIR(2:end-2);
220
221Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpout.m
222===================================================================
223--- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpout.m (revision 12742)
224+++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpout.m (revision 12743)
225@@ -25,7 +25,7 @@
226 %get ISSM_DIR variable
227 [status,ISSM_DIR]=system('echo [%ISSM_DIR_WIN%]');
228 if status,
229- error('scpout error message: could not find ISSM_DIR_WIN envirnoment variable');
230+ error('scpout error message: could not find ISSM_DIR_WIN environment variable');
231 end
232 ISSM_DIR=ISSM_DIR(2:end-2);
233
234Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmssh.m
235===================================================================
236--- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmssh.m (revision 12742)
237+++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmssh.m (revision 12743)
238@@ -17,7 +17,7 @@
239 %get ISSM_DIR variable
240 [status,ISSM_DIR]=system('echo [%ISSM_DIR_WIN%]');
241 if status,
242- error('issmssh error message: could not find ISSM_DIR_WIN envirnoment variable');
243+ error('issmssh error message: could not find ISSM_DIR_WIN environment variable');
244 end
245 ISSM_DIR=ISSM_DIR(2:end-2);
246
Note: See TracBrowser for help on using the repository browser.