git://git.onelab.eu
/
nepi.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
still making both branches closer
[nepi.git]
/
src
/
nepi
/
util
/
execfuncs.py
diff --git
a/src/nepi/util/execfuncs.py
b/src/nepi/util/execfuncs.py
index
d2da3ac
..
1f7b6b9
100644
(file)
--- a/
src/nepi/util/execfuncs.py
+++ b/
src/nepi/util/execfuncs.py
@@
-3,9
+3,8
@@
# Copyright (C) 2013 INRIA
#
# This program is free software: you can redistribute it and/or modify
# Copyright (C) 2013 INRIA
#
# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-17,8
+16,10
@@
#
# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
#
# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
-from nepi.util.sshfuncs import ProcStatus, STDOUT
+from nepi.util.sshfuncs import ProcStatus, STDOUT
, log, shell_escape
+import logging
+import shlex
import subprocess
def lexec(command,
import subprocess
def lexec(command,
@@
-30,21
+31,32
@@
def lexec(command,
"""
if env:
export = ''
"""
if env:
export = ''
- for envkey, envval in env.ite
rite
ms():
+ for envkey, envval in env.items():
export += '%s=%s ' % (envkey, envval)
command = "%s %s" % (export, command)
if sudo:
command = "sudo %s" % command
export += '%s=%s ' % (envkey, envval)
command = "%s %s" % (export, command)
if sudo:
command = "sudo %s" % command
- elif user:
- command = "su %s ; %s " % (user, command)
+
+ # XXX: Doing 'su user' blocks waiting for a password on stdin
+ #elif user:
+ # command = "su %s ; %s " % (user, command)
+
+ proc = subprocess.Popen(command,
+ shell = True,
+ stdout = subprocess.PIPE,
+ stderr = subprocess.PIPE)
+ out = err = ""
+ log_msg = "lexec - command %s " % command
- proc = subprocess.Popen(command, shell=True,
- stdout = subprocess.PIPE,
- stderr = subprocess.PIPE)
+ try:
+ out, err = proc.communicate()
+ log(log_msg, logging.DEBUG, out, err)
+ except:
+ log(log_msg, logging.ERROR, out, err)
+ raise
- out, err = proc.communicate()
return ((out, err), proc)
def lcopy(source, dest, recursive = False):
return ((out, err), proc)
def lcopy(source, dest, recursive = False):
@@
-52,28
+64,35
@@
def lcopy(source, dest, recursive = False):
Copies from/to localy.
"""
Copies from/to localy.
"""
- if TRACE:
- print "scp", source, dest
-
- command = ["cp"]
+ args = ["cp"]
if recursive:
if recursive:
-
command.append("-R
")
+
args.append("-r
")
- if isinstance(dest, str):
- dest = dest.split(";")
-
- if isinstance(src, str):
- src = src.split(";")
-
- args.extend(src)
+ if isinstance(source, list):
+ args.extend(source)
+ else:
+ args.append(source)
- args.extend(dest)
+ if isinstance(dest, list):
+ args.extend(dest)
+ else:
+ args.append(dest)
- proc = subprocess.Popen(
command
,
+ proc = subprocess.Popen(
args
,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- out, err = proc.communicate()
+ out = err = ""
+ command = " ".join(args)
+ log_msg = " lcopy - command %s " % command
+
+ try:
+ out, err = proc.communicate()
+ log(log_msg, logging.DEBUG, out, err)
+ except:
+ log(log_msg, logging.ERROR, out, err)
+ raise
+
return ((out, err), proc)
def lspawn(command, pidfile,
return ((out, err), proc)
def lspawn(command, pidfile,
@@
-125,7
+144,7
@@
def lspawn(command, pidfile,
'stdin' : stdin,
}
'stdin' : stdin,
}
- cmd = "%(create)s%(gohome)s rm -f %(pidfile)s ; %(sudo)s
nohup
bash -c %(command)s " % {
+ cmd = "%(create)s%(gohome)s rm -f %(pidfile)s ; %(sudo)s bash -c %(command)s " % {
'command' : shell_escape(daemon_command),
'sudo' : 'sudo -S' if sudo else '',
'pidfile' : shell_escape(pidfile),
'command' : shell_escape(daemon_command),
'sudo' : 'sudo -S' if sudo else '',
'pidfile' : shell_escape(pidfile),
@@
-136,7
+155,7
@@
def lspawn(command, pidfile,
(out,err), proc = lexec(cmd)
if proc.wait():
(out,err), proc = lexec(cmd)
if proc.wait():
- raise RuntimeError
, "Failed to set up application on host %s: %s %s" % (host, out,err,
)
+ raise RuntimeError
("Failed to set up application on host %s: %s %s" % (host, out,err,)
)
return ((out,err), proc)
return ((out,err), proc)
@@
-160,7
+179,7
@@
def lgetpid(pidfile):
if out:
try:
if out:
try:
- return
map(int,out.strip().split(' ',1))
+ return
[ int(x) for x in out.strip().split(' ',1))]
except:
# Ignore, many ways to fail that don't matter that much
return None
except:
# Ignore, many ways to fail that don't matter that much
return None