if out.find("Debian") == 0:
self._os = OSType.DEBIAN
- elif out.find("Ubuntu") ==0:
+ elif out.find("Ubuntu") == 0:
self._os = OSType.UBUNTU
elif out.find("Fedora release") == 0:
self._os = OSType.FEDORA
@property
def use_deb(self):
- return (self.os & (OSType.DEBIAN|OSType.UBUNTU))
+ return (self.os & (OSType.DEBIAN | OSType.UBUNTU))
@property
def use_rpm(self):
(out, err), proc = self.execute(cmd, retry = 1, with_lock = True)
- def search_for_child(self, pid, pids, ppid, family=[]):
+ def search_for_child(self, pid, pids, ppid, family=None):
""" Recursive function to search for child. List A contains the pids and list B the parents (ppid)
"""
+ family = family if family is not None else []
family.append(pid)
for key, value in enumerate(ppid):
if value == pid:
# create a temporal file with the content to upload
# in python3 we need to open in binary mode if str is bytes
mode = 'w' if isinstance(src, str) else 'wb'
- f = tempfile.NamedTemporaryFile(mode=mode, delete=False)
+ f = tempfile.NamedTemporaryFile(mode = mode, delete = False)
f.write(src)
f.close()
if executable:
return self.execute(cmd, with_lock = True)
def run_and_wait(self, command, home,
- shfile="cmd.sh",
- env=None,
- overwrite=True,
- wait_run=True,
- pidfile="pidfile",
- ecodefile="exitcode",
- stdin=None,
- stdout="stdout",
- stderr="stderr",
- sudo=False,
- tty=False,
- raise_on_error=True):
+ shfile = "cmd.sh",
+ env = None,
+ overwrite = True,
+ wait_run = True,
+ pidfile = "pidfile",
+ ecodefile = "exitcode",
+ stdin = None,
+ stdout = "stdout",
+ stderr = "stderr",
+ sudo = False,
+ tty = False,
+ raise_on_error = True):
"""
Uploads the 'command' to a bash script in the host.
Then runs the script detached in background in the host, and
return ExitCode.ERROR
def upload_command(self, command,
- shfile="cmd.sh",
- ecodefile="exitcode",
- overwrite=True,
- env=None):
+ shfile = "cmd.sh",
+ ecodefile = "exitcode",
+ overwrite = True,
+ env = None):
""" Saves the command as a bash script file in the remote host, and
forces to save the exit code of the command execution to the ecodefile
"""
# The exit code of the command will be stored in ecodefile
command = " {{ {command} }} ; echo $? > {ecodefile} ;"\
- .format(command=command, ecodefile=ecodefile)
+ .format(command = command, ecodefile = ecodefile)
# Export environment
environ = self.format_environment(env)
# Add environ to command
command = environ + command
- return self.upload(command, shfile, text=True, overwrite=overwrite)
+ return self.upload(command, shfile, text = True, overwrite = overwrite)
- def format_environment(self, env, inline=False):
+ def format_environment(self, env, inline = False):
""" Formats the environment variables for a command to be executed
either as an inline command
(i.e. export PYTHONPATH=src/..; export LALAL= ..;python script.py) or
command = []
for d in dests:
- command.append(" [ -f {dst} ] && echo '{dst}' ".format(dst=d) )
+ command.append(" [ -f {dst} ] && echo '{dst}' ".format(dst = d) )
command = ";".join(command)