@@ -26,11 +26,11 @@ def __init__(self, ssh, pid):
2626self .pid = pid
2727
2828def kill (self ):
29- command = f "kill{ self .pid } "
29+ command = "kill {}" . format ( self .pid )
3030self .ssh .exec_command (command )
3131
3232def cmdline (self ):
33- command = f "ps -p{ self . pid } -o cmd --no-headers"
33+ command = "ps -p {} -o cmd --no-headers" . format ( self . pid )
3434stdin ,stdout ,stderr = self .ssh .exec_command (command )
3535cmdline = stdout .read ().decode ('utf-8' ).strip ()
3636return cmdline .split ()
@@ -84,9 +84,9 @@ def _read_ssh_key(self):
8484key = paramiko .RSAKey .from_private_key_file (self .ssh_key )
8585return key
8686except FileNotFoundError :
87- raise ExecUtilException (message = f "No such file or directory: '{ self . ssh_key } '" )
87+ raise ExecUtilException (message = "No such file or directory: '{}'" . format ( self . ssh_key ) )
8888except Exception as e :
89- ExecUtilException (message = f "An error occurred while reading the ssh key:{ e } " )
89+ ExecUtilException (message = "An error occurred while reading the ssh key: {}" . format ( e ) )
9090
9191def exec_command (self ,cmd :str ,wait_exit = False ,verbose = False ,expect_error = False ,
9292encoding = None ,shell = True ,text = False ,input = None ,stdout = None ,
@@ -131,7 +131,7 @@ def exec_command(self, cmd: str, wait_exit=False, verbose=False, expect_error=Fa
131131if error_found :
132132if exit_status == 0 :
133133exit_status = 1
134- raise ExecUtilException (message = f "Utility exited with non-zero code. Error:{ error .decode (encoding or 'utf-8' )} " ,
134+ raise ExecUtilException (message = "Utility exited with non-zero code. Error: {}" . format ( error .decode (encoding or 'utf-8' )) ,
135135command = cmd ,
136136exit_code = exit_status ,
137137out = result )
@@ -148,7 +148,7 @@ def environ(self, var_name: str) -> str:
148148 Args:
149149 - var_name (str): The name of the environment variable.
150150 """
151- cmd = f "echo ${ var_name } "
151+ cmd = "echo ${}" . format ( var_name )
152152return self .exec_command (cmd ,encoding = 'utf-8' ).strip ()
153153
154154def find_executable (self ,executable ):
@@ -166,7 +166,7 @@ def find_executable(self, executable):
166166
167167def is_executable (self ,file ):
168168# Check if the file is executable
169- is_exec = self .exec_command (f "test -x{ file } && echo OK" )
169+ is_exec = self .exec_command ("test -x {} && echo OK" . format ( file ) )
170170return is_exec == b"OK\n "
171171
172172def set_env (self ,var_name :str ,var_val :str ):
@@ -176,7 +176,7 @@ def set_env(self, var_name: str, var_val: str):
176176 - var_name (str): The name of the environment variable.
177177 - var_val (str): The value to be set for the environment variable.
178178 """
179- return self .exec_command (f "export{ var_name } ={ var_val } " )
179+ return self .exec_command ("export {}={}" . format ( var_name , var_val ) )
180180
181181# Get environment variables
182182def get_user (self ):
@@ -195,12 +195,12 @@ def makedirs(self, path, remove_existing=False):
195195 - remove_existing (bool): If True, the existing directory at the path will be removed.
196196 """
197197if remove_existing :
198- cmd = f "rm -rf{ path } && mkdir -p{ path } "
198+ cmd = "rm -rf {} && mkdir -p {}" . format ( path , path )
199199else :
200- cmd = f "mkdir -p{ path } "
200+ cmd = "mkdir -p {}" . format ( path )
201201exit_status ,result ,error = self .exec_command (cmd ,verbose = True )
202202if exit_status != 0 :
203- raise Exception (f "Couldn't create dir{ path } because of error{ error } " )
203+ raise Exception ("Couldn't create dir {} because of error {}" . format ( path , error ) )
204204return result
205205
206206def rmdirs (self ,path ,verbose = False ,ignore_errors = True ):
@@ -211,7 +211,7 @@ def rmdirs(self, path, verbose=False, ignore_errors=True):
211211 - verbose (bool): If True, return exit status, result, and error.
212212 - ignore_errors (bool): If True, do not raise error if directory does not exist.
213213 """
214- cmd = f "rm -rf{ path } "
214+ cmd = "rm -rf {}" . format ( path )
215215exit_status ,result ,error = self .exec_command (cmd ,verbose = True )
216216if verbose :
217217return exit_status ,result ,error
@@ -224,11 +224,11 @@ def listdir(self, path):
224224 Args:
225225 path (str): The path to the directory.
226226 """
227- result = self .exec_command (f "ls{ path } " )
227+ result = self .exec_command ("ls {}" . format ( path ) )
228228return result .splitlines ()
229229
230230def path_exists (self ,path ):
231- result = self .exec_command (f "test -e{ path } ; echo $?" ,encoding = 'utf-8' )
231+ result = self .exec_command ("test -e {}; echo $?" . format ( path ) ,encoding = 'utf-8' )
232232return int (result .strip ())== 0
233233
234234@property
@@ -239,7 +239,7 @@ def pathsep(self):
239239elif os_name == "nt" :
240240pathsep = ";"
241241else :
242- raise Exception (f "Unsupported operating system:{ os_name } " )
242+ raise Exception ("Unsupported operating system: {}" . format ( os_name ) )
243243return pathsep
244244
245245def mkdtemp (self ,prefix = None ):
@@ -249,7 +249,7 @@ def mkdtemp(self, prefix=None):
249249 - prefix (str): The prefix of the temporary directory name.
250250 """
251251if prefix :
252- temp_dir = self .exec_command (f "mktemp -d{ prefix } XXXXX" ,encoding = 'utf-8' )
252+ temp_dir = self .exec_command ("mktemp -d {}XXXXX" . format ( prefix ) ,encoding = 'utf-8' )
253253else :
254254temp_dir = self .exec_command ("mktemp -d" ,encoding = 'utf-8' )
255255
@@ -262,7 +262,7 @@ def mkdtemp(self, prefix=None):
262262
263263def mkstemp (self ,prefix = None ):
264264if prefix :
265- temp_dir = self .exec_command (f "mktemp{ prefix } XXXXX" ,encoding = 'utf-8' )
265+ temp_dir = self .exec_command ("mktemp {}XXXXX" . format ( prefix ) ,encoding = 'utf-8' )
266266else :
267267temp_dir = self .exec_command ("mktemp" ,encoding = 'utf-8' )
268268
@@ -277,8 +277,8 @@ def copytree(self, src, dst):
277277if not os .path .isabs (dst ):
278278dst = os .path .join ('~' ,dst )
279279if self .isdir (dst ):
280- raise FileExistsError (f "Directory{ dst } already exists." )
281- return self .exec_command (f "cp -r{ src } { dst } " )
280+ raise FileExistsError ("Directory {} already exists." . format ( dst ) )
281+ return self .exec_command ("cp -r {} {}" . format ( src , dst ) )
282282
283283# Work with files
284284def write (self ,filename ,data ,truncate = False ,binary = False ,read_and_write = False ,encoding = 'utf-8' ):
@@ -344,10 +344,10 @@ def touch(self, filename):
344344
345345 This method behaves as the 'touch' command in Unix. It's equivalent to calling 'touch filename' in the shell.
346346 """
347- self .exec_command (f "touch{ filename } " )
347+ self .exec_command ("touch {}" . format ( filename ) )
348348
349349def read (self ,filename ,binary = False ,encoding = None ):
350- cmd = f "cat{ filename } "
350+ cmd = "cat {}" . format ( filename )
351351result = self .exec_command (cmd ,encoding = encoding )
352352
353353if not binary and result :
@@ -357,9 +357,9 @@ def read(self, filename, binary=False, encoding=None):
357357
358358def readlines (self ,filename ,num_lines = 0 ,binary = False ,encoding = None ):
359359if num_lines > 0 :
360- cmd = f "tail -n{ num_lines } { filename } "
360+ cmd = "tail -n {} {}" . format ( num_lines , filename )
361361else :
362- cmd = f "cat{ filename } "
362+ cmd = "cat {}" . format ( filename )
363363
364364result = self .exec_command (cmd ,encoding = encoding )
365365
@@ -371,31 +371,31 @@ def readlines(self, filename, num_lines=0, binary=False, encoding=None):
371371return lines
372372
373373def isfile (self ,remote_file ):
374- stdout = self .exec_command (f "test -f{ remote_file } ; echo $?" )
374+ stdout = self .exec_command ("test -f {}; echo $?" . format ( remote_file ) )
375375result = int (stdout .strip ())
376376return result == 0
377377
378378def isdir (self ,dirname ):
379- cmd = f "if [ -d{ dirname } ]; then echo True; else echo False; fi"
379+ cmd = "if [ -d {} ]; then echo True; else echo False; fi" . format ( dirname )
380380response = self .exec_command (cmd )
381381return response .strip ()== b"True"
382382
383383def remove_file (self ,filename ):
384- cmd = f "rm{ filename } "
384+ cmd = "rm {}" . format ( filename )
385385return self .exec_command (cmd )
386386
387387# Processes control
388388def kill (self ,pid ,signal ):
389389# Kill the process
390- cmd = f "kill -{ signal } { pid } "
390+ cmd = "kill -{} {}" . format ( signal , pid )
391391return self .exec_command (cmd )
392392
393393def get_pid (self ):
394394# Get current process id
395395return int (self .exec_command ("echo $$" ,encoding = 'utf-8' ))
396396
397397def get_process_children (self ,pid ):
398- command = f "pgrep -P{ pid } "
398+ command = "pgrep -P {}" . format ( pid )
399399stdin ,stdout ,stderr = self .ssh .exec_command (command )
400400children = stdout .readlines ()
401401return [PsUtilProcessProxy (self .ssh ,int (child_pid .strip ()))for child_pid in children ]
@@ -437,4 +437,4 @@ def db_connect(self, dbname, user, password=None, host="127.0.0.1", port=5432, s
437437return conn
438438except Exception as e :
439439self .tunnel .stop ()
440- raise ExecUtilException ("Could not create db tunnel." )
440+ raise ExecUtilException ("Could not create db tunnel. {}" . format ( e ) )