@@ -46,9 +46,9 @@ def __init__(self, conn_params: ConnectionParams):
46
46
self .host = conn_params .host
47
47
self .ssh_key = conn_params .ssh_key
48
48
if self .ssh_key :
49
- self .ssh_cmd = ["-i" , self .ssh_key ]
49
+ self .ssh_args = ["-i" , self .ssh_key ]
50
50
else :
51
- self .ssh_cmd = []
51
+ self .ssh_args = []
52
52
self .remote = True
53
53
self .username = conn_params .username
54
54
self .ssh_dest = f"{ self .username } @{ self .host } " if self .username else self .host
@@ -96,9 +96,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
96
96
"""
97
97
ssh_cmd = []
98
98
if isinstance (cmd , str ):
99
- ssh_cmd = ['ssh' , self .ssh_dest ] + self .ssh_cmd + [ cmd ]
99
+ ssh_cmd = ['ssh' ] + self .ssh_args + [ self .ssh_dest + cmd ]
100
100
elif isinstance (cmd , list ):
101
- ssh_cmd = ['ssh' , self .ssh_dest ] + self .ssh_cmd + cmd
101
+ ssh_cmd = ['ssh' ] + self .ssh_args + [ self .ssh_dest ] + cmd
102
102
process = subprocess .Popen (ssh_cmd , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
103
103
if get_process :
104
104
return process
@@ -243,9 +243,9 @@ def mkdtemp(self, prefix=None):
243
243
- prefix (str): The prefix of the temporary directory name.
244
244
"""
245
245
if prefix :
246
- command = ["ssh" ] + self .ssh_cmd + [self .ssh_dest , f"mktemp -d { prefix } XXXXX" ]
246
+ command = ["ssh" ] + self .ssh_args + [self .ssh_dest , f"mktemp -d { prefix } XXXXX" ]
247
247
else :
248
- command = ["ssh" ] + self .ssh_cmd + [self .ssh_dest , "mktemp -d" ]
248
+ command = ["ssh" ] + self .ssh_args + [self .ssh_dest , "mktemp -d" ]
249
249
250
250
result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
251
251
@@ -289,7 +289,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
289
289
290
290
with tempfile .NamedTemporaryFile (mode = mode , delete = False ) as tmp_file :
291
291
if not truncate :
292
- scp_cmd = ['scp' ] + self .ssh_cmd + [f"{ self .ssh_dest } :{ filename } " , tmp_file .name ]
292
+ scp_cmd = ['scp' ] + self .ssh_args + [f"{ self .ssh_dest } :{ filename } " , tmp_file .name ]
293
293
subprocess .run (scp_cmd , check = False ) # The file might not exist yet
294
294
tmp_file .seek (0 , os .SEEK_END )
295
295
@@ -305,11 +305,11 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
305
305
tmp_file .write (data )
306
306
307
307
tmp_file .flush ()
308
- scp_cmd = ['scp' ] + self .ssh_cmd + [tmp_file .name , f"{ self .ssh_dest } :{ filename } " ]
308
+ scp_cmd = ['scp' ] + self .ssh_args + [tmp_file .name , f"{ self .ssh_dest } :{ filename } " ]
309
309
subprocess .run (scp_cmd , check = True )
310
310
311
311
remote_directory = os .path .dirname (filename )
312
- mkdir_cmd = ['ssh' ] + self .ssh_cmd + [self .ssh_dest , f"mkdir -p { remote_directory } " ]
312
+ mkdir_cmd = ['ssh' ] + self .ssh_args + [self .ssh_dest , f"mkdir -p { remote_directory } " ]
313
313
subprocess .run (mkdir_cmd , check = True )
314
314
315
315
os .remove (tmp_file .name )
@@ -374,7 +374,7 @@ def get_pid(self):
374
374
return int (self .exec_command ("echo $$" , encoding = get_default_encoding ()))
375
375
376
376
def get_process_children (self , pid ):
377
- command = ["ssh" ] + self .ssh_cmd + [self .ssh_dest , f"pgrep -P { pid } " ]
377
+ command = ["ssh" ] + self .ssh_args + [self .ssh_dest , f"pgrep -P { pid } " ]
378
378
379
379
result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
380
380
0 commit comments