33import subprocess
44import tempfile
55import platform
6- < << << << HEAD
7- import time
8- == == == =
9- >> >> >> > master
106
117# we support both pg8000 and psycopg2
128try :
@@ -57,11 +53,8 @@ def __init__(self, conn_params: ConnectionParams):
5753 self .ssh_cmd += ["-p" , self .port ]
5854 self .remote = True
5955 self .username = conn_params .username or self .get_user ()
60- < << << << HEAD
61- == == == =
6256 self .ssh_dest = f"{ self .username } @{ self .host } " if self .username else "{self.host}"
6357 self .add_known_host (self .host )
64- >> >> >> > default - ssh - user
6558 self .tunnel_process = None
6659 self .tunnel_port = None
6760
@@ -251,15 +244,9 @@ def mkdtemp(self, prefix=None):
251244 - prefix (str): The prefix of the temporary directory name.
252245 """
253246 if prefix :
254- < << << << HEAD
255- command = ["ssh" + f"{ self .username } @{ self .host } " ] + self .ssh_cmd + [f"mktemp -d { prefix } XXXXX" ]
256- else :
257- command = ["ssh" , f"{ self .username } @{ self .host } " ] + self .ssh_cmd + ["mktemp -d" ]
258- == == == =
259247 command = ["ssh" ] + self .ssh_cmd + [self .ssh_dest , f"mktemp -d { prefix } XXXXX" ]
260248 else :
261249 command = ["ssh" ] + self .ssh_cmd + [self .ssh_dest , "mktemp -d" ]
262- >> >> >> > default - ssh - user
263250
264251 result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
265252
@@ -306,11 +293,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
306293 scp_ssh_cmd = ['-P' if x == '-p' else x for x in self .ssh_cmd ]
307294
308295 if not truncate :
309- < << << << HEAD
310- scp_cmd = ['scp' ] + scp_ssh_cmd + [f"{ self .username } @{ self .host } :{ filename } " , tmp_file .name ]
311- == == == =
312296 scp_cmd = ['scp' ] + self .ssh_cmd + [f"{ self .ssh_dest } :{ filename } " , tmp_file .name ]
313- >> >> >> > default - ssh - user
314297 subprocess .run (scp_cmd , check = False ) # The file might not exist yet
315298 tmp_file .seek (0 , os .SEEK_END )
316299
@@ -326,19 +309,11 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
326309 tmp_file .write (data )
327310
328311 tmp_file .flush ()
329- < << << << HEAD
330- scp_cmd = ['scp' ] + scp_ssh_cmd + [tmp_file .name , f"{ self .username } @{ self .host } :{ filename } " ]
331- subprocess .run (scp_cmd , check = True )
332-
333- remote_directory = os .path .dirname (filename )
334- mkdir_cmd = ['ssh' , f"{ self .username } @{ self .host } " ] + self .ssh_cmd + [f"mkdir -p { remote_directory } " ]
335- == == == =
336312 scp_cmd = ['scp' ] + self .ssh_cmd + [tmp_file .name , f"{ self .ssh_dest } :{ filename } " ]
337313 subprocess .run (scp_cmd , check = True )
338314
339315 remote_directory = os .path .dirname (filename )
340316 mkdir_cmd = ['ssh' ] + self .ssh_cmd + [self .ssh_dest , f"mkdir -p { remote_directory } " ]
341- >> >> >> > default - ssh - user
342317 subprocess .run (mkdir_cmd , check = True )
343318
344319 os .remove (tmp_file .name )
0 commit comments