#!/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
# 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
"""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=[]
#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
-
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()
-