import getpass
logname = getpass.getuser()
tmp_script="/tmp/%s_%s_%s" % (logname,os.getpid(),namescript)
- fscript=open(script)
- script_text=fscript.read()
- fscript.close()
+ with open(script, 'r') as fscript:
+ script_text=fscript.read()
list_infiles=[]
list_outfiles=[]
#modify the salome script
script_text = re.sub(infile,tmp_file,script_text)
- # copy the infile to the remote server (into /tmp)
+ # copy the infile to the remote server
cmd="scp %s %s@%s:%s" % (infile,user,machine,tmp_file)
print "[ SCP ]",cmd
os.system(cmd)
list_outfiles.append(tmp_file)
n=n+1
- fscript=open(tmp_script,'w')
- fscript.write(script_text)
- fscript.close()
+ with open(tmp_script,'w') as fscript:
+ fscript.write(script_text)
if directory:
#copy the salome script on the remote server
tmp_script=script
print "mode:",mode
+ print "user:",user
+ print "machine:",machine
+ print "port:",port
+ print "directory:",directory
+ print "infiles:",infiles
+ print "outfiles:",outfiles
+ print "script:",script
if mode == "remote":
list_infiles, list_outfiles, tmp_script = copy_files(user,machine,script,infiles,outfiles,directory)
#################################################
# Execution #
#################################################
- if directory:
+ if mode == "remote":
print "[ REMOTE ]"
# execute runSession from the remote SALOME application
# Get remote files and clean #
#################################################
if mode == "remote":
- temp_files=list_infiles+list_outfiles
+ temp_files=list_infiles+list_outfiles+[tmp_script]
#get the outfiles
for outfile in outfiles:
if __name__ == '__main__':
main()
-
try:
import re
omniNamesPid, omniNamesPort = re.search('(.+?) omniNames -start (.+?) ', out).group(1, 2)
- if verbose():
- print "stop omniNames [pid=%s] on port %s"%(omniNamesPid, omniNamesPort)
- appliCleanOmniOrbConfig(omniNamesPort)
- from PortManager import releasePort
- releasePort(omniNamesPort)
- os.kill(int(omniNamesPid),signal.SIGKILL)
+ if omniNamesPort == port:
+ if verbose():
+ print "stop omniNames [pid=%s] on port %s"%(omniNamesPid, omniNamesPort)
+ appliCleanOmniOrbConfig(omniNamesPort)
+ from PortManager import releasePort
+ releasePort(omniNamesPort)
+ os.kill(int(omniNamesPid),signal.SIGKILL)
except (ImportError, AttributeError, OSError) as e:
pass
except:
#
def runSalome():
+ print sys.argv
import user
clt,args = main()
# --
from optparse import OptionParser
from NSparam import getNSparams
import socket
+import subprocess
# Use to display newlines (\n) in epilog
class MyParser(OptionParser):
os.environ['OMNIORB_CONFIG'] = filename
#
+
+# command looks like a Bash command-line:
+# script1.py [args] ; script2.py [args] ; ...
+def runSession(command):
+ if command:
+ sep = ";"
+ if sys.platform == "win32":
+ sep= "&"
+ command = command.split(sep)
+ outmsg = []
+ errmsg = []
+ for cmd in command:
+ save_cmd = cmd
+ cmd = cmd.strip().split(' ')
+ #proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ proc = subprocess.Popen(cmd)
+ (stdoutdata, stderrdata) = proc.communicate()
+ if stdoutdata:
+ outmsg.append(stdoutdata)
+ if stderrdata:
+ errmsg.append(stderrdata)
+
+ if proc.returncode != 0:
+ errmsg.append("Error raised when executing command: %s\n"%save_cmd)
+ if outmsg:
+ sys.stdout.write("".join(outmsg))
+ if errmsg:
+ sys.stderr.write("".join(errmsg))
+ sys.exit(proc.returncode)
+
+ return ("".join(outmsg), "".join(errmsg))
+ else:
+ absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
+ cmd = ["/bin/bash", "--rcfile", absoluteAppliPath + "/.bashrc" ]
+ proc = subprocess.Popen(cmd, shell=False, close_fds=True)
+ return proc.communicate()
+#
def runSalome(self, args):
# Run this module as a script, in order to use appropriate Python interpreter
# according to current path (initialized from environment files).
- kill = False
- for e in args:
- if "--shutdown-server" in e:
- kill = True
- args.remove(e)
+# kill = False
+# for e in args:
+# if "--shutdown-server" in e:
+# kill = True
+# args.remove(e)
absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
proc = subprocess.Popen(['python', os.path.join(absoluteAppliPath,"bin","salome","salomeContext.py"), pickle.dumps(self), pickle.dumps(args)], shell=False, close_fds=True)
msg = proc.communicate()
- if kill:
- self._killAll(args)
+ # if kill:
+ # self._killAll(args)
return msg, proc.returncode
#
scriptArgs = getScriptsAndArgs(args)
command = formatScriptsAndArgs(scriptArgs)
- if command:
- sep = ";"
- if sys.platform == "win32":
- sep= "&"
- command = command.split(sep)
- outmsg = []
- errmsg = []
- for cmd in command:
- save_cmd = cmd
- cmd = cmd.strip().split(' ')
- #proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- proc = subprocess.Popen(cmd)
- (stdoutdata, stderrdata) = proc.communicate()
- if stdoutdata:
- outmsg.append(stdoutdata)
- if stderrdata:
- errmsg.append(stderrdata)
-
- if proc.returncode != 0:
- errmsg.append("Error raised when executing command: %s\n"%save_cmd)
- if outmsg:
- sys.stdout.write("".join(outmsg))
- if errmsg:
- sys.stderr.write("".join(errmsg))
- sys.exit(proc.returncode)
-
- return ("".join(outmsg), "".join(errmsg))
- else:
- absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
- cmd = ["/bin/bash", "--rcfile", absoluteAppliPath + "/.bashrc" ]
- proc = subprocess.Popen(cmd, shell=False, close_fds=True)
- return proc.communicate()
+ return runSession.runSession(command)
#
def _runConsole(self, args=[]):