X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Flinux%2Fnode.py;h=80212586cc7b71b571a505b2fdbb147cb41e2483;hb=edb86b896991fc95a83b0bebed51e836e641318f;hp=7ac2d12c2785892ac7283e7bf445d3c07ca05341;hpb=78a5f5ae901920e205fb257e889a3b9b3659b44e;p=nepi.git diff --git a/src/nepi/resources/linux/node.py b/src/nepi/resources/linux/node.py index 7ac2d12c..80212586 100644 --- a/src/nepi/resources/linux/node.py +++ b/src/nepi/resources/linux/node.py @@ -375,7 +375,6 @@ class LinuxNode(ResourceManager): self.error(msg, out, err) if raise_on_error: raise RuntimeError, msg - # Wait for pid file to be generated pid, ppid = self.wait_pid( home = home, @@ -388,7 +387,7 @@ class LinuxNode(ResourceManager): (out, err), proc = self.check_errors(home, ecodefile, stderr) # Out is what was written in the stderr file - if out or err: + if err: msg = " Failed to run command '%s' " % command self.error(msg, out, err) @@ -434,8 +433,7 @@ class LinuxNode(ResourceManager): } # Export environment - environ = "\n".join(map(lambda e: "export %s" % e, env.split(" "))) + "\n" \ - if env else "" + environ = self.format_environment(env) # Add environ to command command = environ + command @@ -443,18 +441,30 @@ class LinuxNode(ResourceManager): dst = os.path.join(home, shfile) return self.upload(command, dst, text = True) + def format_environment(self, env, inline = False): + """Format environmental variables for command to be executed either + as an inline command (i.e. PYTHONPATH=src/.. python script.py) or + as a bash script (i.e. export PYTHONPATH=src/.. \n export LALA=.. \n) + """ + sep = " " if inline else "\n" + export = " " if inline else "export" + return sep.join(map(lambda e: "%s %s" % (export, e), env.split(" "))) \ + + sep if env else "" + def check_errors(self, home, ecodefile = "exitcode", - stderr = "stderr"): + stderr = "stderr", + stdout = "stdout"): """ Checks whether errors occurred while running a command. It first checks the exit code for the command, and only if the exit code is an error one it returns the error output. + """ out = err = "" proc = None - # get Exit code + # get exit code saved in the 'exitcode' file ecode = self.exitcode(home, ecodefile) if ecode in [ ExitCode.CORRUPTFILE, ExitCode.ERROR ]: @@ -462,13 +472,16 @@ class LinuxNode(ResourceManager): elif ecode > 0 or ecode == ExitCode.FILENOTFOUND: # The process returned an error code or didn't exist. # Check standard error. - (out, err), proc = self.check_output(home, stderr) - - # If the stderr file was not found, assume nothing happened. - # We just ignore the error. + (err, eerr), proc = self.check_output(home, stderr) + + # Alsow retrive standard output for information + (out, oerr), oproc = self.check_output(home, stdout) + + # If the stderr file was not found, assume nothing bad happened, + # and just ignore the error. # (cat returns 1 for error "No such file or directory") if ecode == ExitCode.FILENOTFOUND and proc.poll() == 1: - out = err = "" + err = "" return (out, err), proc