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
  • u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpin.py

     
     1"""
     2SCPIN get packages from host, using scp on unix, and pscp on windows
     3 
     4    usage: scpin(host,packages,path)
     5 
     6 
     7"""
     8
     9import socket
     10import platform
     11import subprocess
     12import os
     13import shutil
     14from MatlabFuncs import *
     15
     16def scpin(host, login,port,path, packages):
     17
     18        #first get hostname
     19        hostname=socket.gethostname().lower().split('.')[0]
     20
     21        #first be sure packages are not in the current directory, this could conflict with pscp on windows.
     22        #remove warnings in case the files do not exist
     23        for package in packages:
     24                try:
     25                        os.remove(package)
     26                except OSError as e:
     27                        pass
     28
     29        #if hostname and host are the same, do a simple copy
     30        if strcmpi(hostname,host):
     31
     32                for package in packages:
     33                        try:
     34                                shutil.copy(os.path.join(path,package),os.getcwd())    #keep going, even if success=0
     35                        except OSError as e:
     36                                pass
     37
     38        else:
     39
     40                if 'Windows' in platform.system():
     41                        #use the putty project pscp.exe: it should be in the path.
     42               
     43                        #get ISSM_DIR variable
     44                        if 'ISSM_DIR_WIN' in os.environ:
     45                                ISSM_DIR=os.environ['ISSM_DIR_WIN'][1:-2]
     46                        else:
     47                                raise OSError("scpin error message: could not find ISSM_DIR_WIN environment variable.")
     48
     49                        username=raw_input('Username: (quoted string) ')
     50                        key=raw_input('Key: (quoted string) ')
     51
     52                        for package in packages:
     53                                try:
     54                                        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)
     55                                except CalledProcessError as e:
     56                                        raise CalledProcessError("scpin error message: could not call putty pscp.")
     57
     58                else:
     59                        #just use standard unix scp
     60                        #string to copy multiple files using scp:
     61                        if len(packages)==1:
     62                                string=packages[0]
     63                        else:
     64                                string='{'
     65                                for package in packages:
     66                                        string+=packages[i]+','
     67                                string=string[:-1]+'}'
     68
     69
     70                        if port:
     71                                subprocess.call('scp -P %d %s@localhost:%s %s' % (port,login,os.path.join(path,string),os.getcwd),shell=True)
     72                        else:
     73                                subprocess.call('scp %s@%s:%s %s' % (login,host,os.path.join(path,string),os.getcwd),shell=True)
     74               
     75                        #check scp worked
     76                        for package in packages:
     77                                if not os.path.exists(os.path.join('.',package)):
     78                                        raise OSError("scpin error message: could not call scp on *nix system.")
     79
  • u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpout.py

     
     1"""
     2SCPOUT send packages to a host, using scp on unix, and pscp on windows
     3 
     4    usage: scpout(host,path,packages)
     5 
     6 
     7"""
     8
     9import socket
     10import platform
     11import subprocess
     12import os
     13import shutil
     14from MatlabFuncs import *
     15
     16def issmscpout(host,path,login,port,packages):
     17
     18        #get hostname
     19        hostname=socket.gethostname().lower().split('.')[0]
     20
     21        #if hostname and host are the same, do a simple copy
     22
     23        if strcmpi(host,hostname):
     24                for package in packages:
     25                        here=os.getcwd()
     26                        os.chdir(path)
     27                        shutil.rmtree(package)
     28                        subprocess.call('ln -s %s %s' % (os.path.join(here,package),path),shell=True)
     29                        os.chdir(here)
     30        else:
     31                if 'Windows' in platform.system():
     32                        #use the putty project pscp.exe: it should be in the path.
     33               
     34                        #get ISSM_DIR variable
     35                        if 'ISSM_DIR_WIN' in os.environ:
     36                                ISSM_DIR=os.environ['ISSM_DIR_WIN'][1:-2]
     37                        else:
     38                                raise OSError("scpout error message: could not find ISSM_DIR_WIN environment variable.")
     39
     40                        username=raw_input('Username: (quoted string) ')
     41                        key=raw_input('Key: (quoted string) ')
     42
     43                        for package in packages:
     44                                try:
     45                                        subprocess.check_call('%s/externalpackages/ssh/pscp.exe -l "%s" -pw "%s" %s %s:%s' % (ISSM_DIR,username,key,package,host,path),shell=True)
     46                                except CalledProcessError as e:
     47                                        raise CalledProcessError("scpout error message: could not call putty pscp.")
     48
     49                else:
     50                        #just use standard unix scp
     51                        #create string of packages being sent
     52                        string=''
     53                        for package in packages:
     54                                string+=' '+package
     55                        string+=' '
     56               
     57                        if port:
     58                                subprocess.call('scp -P %d %s %s@localhost:%s' % (port,string,login,path),shell=True)
     59                        else:
     60                                subprocess.call('scp %s %s@%s:%s' % (string,login,host,path),shell=True)
     61
  • u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmssh.py

     
     1"""
     2ISSMSSH - wrapper for OS independent ssh command.
     3 
     4    usage:
     5       issmssh(host,command)
     6"""
     7
     8import socket
     9import platform
     10import subprocess
     11import os
     12from MatlabFuncs import *
     13
     14def issmssh(host,login,port,command):
     15
     16        #first get hostname
     17        hostname=socket.gethostname().lower().split('.')[0]
     18
     19        #if same as host, just run the command.
     20        if strcmpi(host,hostname):
     21                subprocess.call(command,shell=True)
     22        else:
     23                if 'Windows' in platform.system():
     24                        #use the putty project plink.exe: it should be in the path.
     25               
     26                        #get ISSM_DIR variable
     27                        if 'ISSM_DIR_WIN' in os.environ:
     28                                ISSM_DIR=os.environ['ISSM_DIR_WIN'][1:-2]
     29                        else:
     30                                raise OSError("issmssh error message: could not find ISSM_DIR_WIN environment variable.")
     31
     32                        username=raw_input('Username: (quoted string) ')
     33                        key=raw_input('Key: (quoted string) ')
     34
     35                        subprocess.call('%s/externalpackages/ssh/plink.exe -ssh -l "%s" -pw "%s" %s "%s"' % (ISSM_DIR,username,key,host,command),shell=True);
     36
     37                else:
     38                        #just use standard unix ssh
     39                        if port:
     40                                subprocess.call('ssh -l %s -p %d localhost "%s"' % (login,port,command),shell=True)
     41                        else:
     42                                subprocess.call('ssh -l %s %s "%s"' % (login,host,command),shell=True)
     43
  • u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/ispetsc.py

     
    3636                raise RuntimeError("could not determine whether PETSC was or was not compiled.")
    3737
    3838        return flag
     39
  • u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpin.m

     
    3434                %get ISSM_DIR variable
    3535                [status,ISSM_DIR]=system('echo [%ISSM_DIR_WIN%]');
    3636                if status,
    37                         error('scpin error message: could not find ISSM_DIR_WIN envirnoment variable');
     37                        error('scpin error message: could not find ISSM_DIR_WIN environment variable');
    3838                end
    3939                ISSM_DIR=ISSM_DIR(2:end-2);
    4040
  • u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmscpout.m

     
    2525                %get ISSM_DIR variable
    2626                [status,ISSM_DIR]=system('echo [%ISSM_DIR_WIN%]');
    2727                if status,
    28                         error('scpout error message: could not find ISSM_DIR_WIN envirnoment variable');
     28                        error('scpout error message: could not find ISSM_DIR_WIN environment variable');
    2929                end
    3030                ISSM_DIR=ISSM_DIR(2:end-2);
    3131
  • u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/m/utils/OS/issmssh.m

     
    1717                %get ISSM_DIR variable
    1818                [status,ISSM_DIR]=system('echo [%ISSM_DIR_WIN%]');
    1919                if status,
    20                         error('issmssh error message: could not find ISSM_DIR_WIN envirnoment variable');
     20                        error('issmssh error message: could not find ISSM_DIR_WIN environment variable');
    2121                end
    2222                ISSM_DIR=ISSM_DIR(2:end-2);
    2323
Note: See TracBrowser for help on using the repository browser.