Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08d6b04

Browse files
committed
Make use of the default SSH user
1 parentb4268f8 commit08d6b04

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

‎testgres/operations/remote_ops.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def __init__(self, conn_params: ConnectionParams):
5151
self.ssh_cmd= []
5252
self.remote=True
5353
self.username=conn_params.usernameorself.get_user()
54+
self.ssh_dest=f"{self.username}@{self.host}"ifself.usernameelse"{self.host}"
5455
self.add_known_host(self.host)
5556
self.tunnel_process=None
5657

@@ -95,9 +96,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
9596
"""
9697
ssh_cmd= []
9798
ifisinstance(cmd,str):
98-
ssh_cmd= ['ssh',f"{self.username}@{self.host}"]+self.ssh_cmd+ [cmd]
99+
ssh_cmd= ['ssh',self.ssh_dest]+self.ssh_cmd+ [cmd]
99100
elifisinstance(cmd,list):
100-
ssh_cmd= ['ssh',f"{self.username}@{self.host}"]+self.ssh_cmd+cmd
101+
ssh_cmd= ['ssh',self.ssh_dest]+self.ssh_cmd+cmd
101102
process=subprocess.Popen(ssh_cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
102103
ifget_process:
103104
returnprocess
@@ -246,9 +247,9 @@ def mkdtemp(self, prefix=None):
246247
- prefix (str): The prefix of the temporary directory name.
247248
"""
248249
ifprefix:
249-
command= ["ssh"]+self.ssh_cmd+ [f"{self.username}@{self.host}",f"mktemp -d{prefix}XXXXX"]
250+
command= ["ssh"]+self.ssh_cmd+ [self.ssh_dest,f"mktemp -d{prefix}XXXXX"]
250251
else:
251-
command= ["ssh"]+self.ssh_cmd+ [f"{self.username}@{self.host}","mktemp -d"]
252+
command= ["ssh"]+self.ssh_cmd+ [self.ssh_dest,"mktemp -d"]
252253

253254
result=subprocess.run(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True)
254255

@@ -292,7 +293,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
292293

293294
withtempfile.NamedTemporaryFile(mode=mode,delete=False)astmp_file:
294295
ifnottruncate:
295-
scp_cmd= ['scp']+self.ssh_cmd+ [f"{self.username}@{self.host}:{filename}",tmp_file.name]
296+
scp_cmd= ['scp']+self.ssh_cmd+ [f"{self.ssh_dest}:{filename}",tmp_file.name]
296297
subprocess.run(scp_cmd,check=False)# The file might not exist yet
297298
tmp_file.seek(0,os.SEEK_END)
298299

@@ -308,11 +309,11 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
308309
tmp_file.write(data)
309310

310311
tmp_file.flush()
311-
scp_cmd= ['scp']+self.ssh_cmd+ [tmp_file.name,f"{self.username}@{self.host}:{filename}"]
312+
scp_cmd= ['scp']+self.ssh_cmd+ [tmp_file.name,f"{self.ssh_dest}:{filename}"]
312313
subprocess.run(scp_cmd,check=True)
313314

314315
remote_directory=os.path.dirname(filename)
315-
mkdir_cmd= ['ssh']+self.ssh_cmd+ [f"{self.username}@{self.host}",f"mkdir -p{remote_directory}"]
316+
mkdir_cmd= ['ssh']+self.ssh_cmd+ [self.ssh_dest,f"mkdir -p{remote_directory}"]
316317
subprocess.run(mkdir_cmd,check=True)
317318

318319
os.remove(tmp_file.name)
@@ -377,7 +378,7 @@ def get_pid(self):
377378
returnint(self.exec_command("echo $$",encoding=get_default_encoding()))
378379

379380
defget_process_children(self,pid):
380-
command= ["ssh"]+self.ssh_cmd+ [f"{self.username}@{self.host}",f"pgrep -P{pid}"]
381+
command= ["ssh"]+self.ssh_cmd+ [self.ssh_dest,f"pgrep -P{pid}"]
381382

382383
result=subprocess.run(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True)
383384

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp