|
3 | 3 | importos
|
4 | 4 | importsubprocess
|
5 | 5 | importtempfile
|
| 6 | +importplatform |
6 | 7 |
|
7 | 8 | # we support both pg8000 and psycopg2
|
8 | 9 | try:
|
@@ -42,7 +43,8 @@ def cmdline(self):
|
42 | 43 |
|
43 | 44 | classRemoteOperations(OsOperations):
|
44 | 45 | def__init__(self,conn_params:ConnectionParams):
|
45 |
| -ifos.name!="posix": |
| 46 | + |
| 47 | +ifnotplatform.system().lower()=="linux": |
46 | 48 | raiseEnvironmentError("Remote operations are supported only on Linux!")
|
47 | 49 |
|
48 | 50 | super().__init__(conn_params.username)
|
@@ -76,16 +78,14 @@ def close_ssh_tunnel(self):
|
76 | 78 | print("No active tunnel to close.")
|
77 | 79 |
|
78 | 80 | defadd_known_host(self,host):
|
79 |
| -cmd='ssh-keyscan -H %s >> /home/%s/.ssh/known_hosts'% (host,os.getlogin()) |
| 81 | +known_hosts_path=os.path.expanduser("~/.ssh/known_hosts") |
| 82 | +cmd='ssh-keyscan -H %s >> %s'% (host,known_hosts_path) |
| 83 | + |
80 | 84 | try:
|
81 |
| -subprocess.check_call( |
82 |
| -cmd, |
83 |
| -shell=True, |
84 |
| - ) |
| 85 | +subprocess.check_call(cmd,shell=True) |
85 | 86 | logging.info("Successfully added %s to known_hosts."%host)
|
86 | 87 | exceptsubprocess.CalledProcessErrorase:
|
87 |
| -raiseExecUtilException(message="Failed to add %s to known_hosts. Error: %s"% (host,str(e)),command=cmd, |
88 |
| -exit_code=e.returncode,out=e.stderr) |
| 88 | +raiseException("Failed to add %s to known_hosts. Error: %s"% (host,str(e))) |
89 | 89 |
|
90 | 90 | defexec_command(self,cmd,wait_exit=False,verbose=False,expect_error=False,
|
91 | 91 | encoding=None,shell=True,text=False,input=None,stdin=None,stdout=None,
|
|