Salome HOME
Deal with ref count server side.
[modules/kernel.git] / bin / appliskel / runSalomeScript
index 94de99b29061fd5cb68c0ff4b79b3ce675ebf40d..5b005d587b77d4277503e35e49708facae129bca 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #  -*- coding: utf-8 -*-
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -8,7 +8,7 @@
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -137,11 +137,11 @@ def copy_files(user,machine,script,infiles,outfiles,directory):
   """modify script, copy files to remote computer and return lists of copied files"""
 
   namescript=os.path.basename(script)
-  logname=os.getenv("LOGNAME",user)
+  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=[]
@@ -155,7 +155,7 @@ def copy_files(user,machine,script,infiles,outfiles,directory):
     #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)
@@ -175,9 +175,8 @@ def copy_files(user,machine,script,infiles,outfiles,directory):
     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
@@ -193,15 +192,13 @@ def main():
 
   tmp_script=script
 
-  print "mode:",mode
-
   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
@@ -229,7 +226,7 @@ def main():
   #          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:
@@ -246,4 +243,3 @@ def main():
 
 if __name__ == '__main__':
   main()
-