3
3
import subprocess
4
4
import tempfile
5
5
import platform
6
- < << << << HEAD
7
- import time
8
- == == == =
9
- >> >> >> > master
10
6
11
7
# we support both pg8000 and psycopg2
12
8
try :
@@ -57,11 +53,8 @@ def __init__(self, conn_params: ConnectionParams):
57
53
self .ssh_cmd += ["-p" , self .port ]
58
54
self .remote = True
59
55
self .username = conn_params .username or self .get_user ()
60
- < << << << HEAD
61
- == == == =
62
56
self .ssh_dest = f"{ self .username } @{ self .host } " if self .username else "{self.host}"
63
57
self .add_known_host (self .host )
64
- >> >> >> > default - ssh - user
65
58
self .tunnel_process = None
66
59
self .tunnel_port = None
67
60
@@ -251,15 +244,9 @@ def mkdtemp(self, prefix=None):
251
244
- prefix (str): The prefix of the temporary directory name.
252
245
"""
253
246
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
- == == == =
259
247
command = ["ssh" ] + self .ssh_cmd + [self .ssh_dest , f"mktemp -d { prefix } XXXXX" ]
260
248
else :
261
249
command = ["ssh" ] + self .ssh_cmd + [self .ssh_dest , "mktemp -d" ]
262
- >> >> >> > default - ssh - user
263
250
264
251
result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
265
252
@@ -306,11 +293,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
306
293
scp_ssh_cmd = ['-P' if x == '-p' else x for x in self .ssh_cmd ]
307
294
308
295
if not truncate :
309
- < << << << HEAD
310
- scp_cmd = ['scp' ] + scp_ssh_cmd + [f"{ self .username } @{ self .host } :{ filename } " , tmp_file .name ]
311
- == == == =
312
296
scp_cmd = ['scp' ] + self .ssh_cmd + [f"{ self .ssh_dest } :{ filename } " , tmp_file .name ]
313
- >> >> >> > default - ssh - user
314
297
subprocess .run (scp_cmd , check = False ) # The file might not exist yet
315
298
tmp_file .seek (0 , os .SEEK_END )
316
299
@@ -326,19 +309,11 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
326
309
tmp_file .write (data )
327
310
328
311
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
- == == == =
336
312
scp_cmd = ['scp' ] + self .ssh_cmd + [tmp_file .name , f"{ self .ssh_dest } :{ filename } " ]
337
313
subprocess .run (scp_cmd , check = True )
338
314
339
315
remote_directory = os .path .dirname (filename )
340
316
mkdir_cmd = ['ssh' ] + self .ssh_cmd + [self .ssh_dest , f"mkdir -p { remote_directory } " ]
341
- >> >> >> > default - ssh - user
342
317
subprocess .run (mkdir_cmd , check = True )
343
318
344
319
os .remove (tmp_file .name )
0 commit comments