#
# You should have received a copy of the GNU General Public License
# along with SALOME HYDRO module. If not, see <http://www.gnu.org/licenses/>.
+"""
+Script for launch in terminal of a steering file
+"""
import os
import subprocess
orig_steering = f.read()
orig_steering_lines = orig_steering.split("\n")
- cmd = "set -x ; "
# Run the code itself
code = param_dict["CODE"]
- cmd += "runcode.py -w %s %s %s" % \
- (wrkdir, code, steering_filepath)
- cmd += " ; rc=$?"
+ cmd = "runcode.py {code} -w {wrkdir} {steering_filepath} " \
+ .format(code=code,
+ wrkdir=wrkdir,
+ steering_filepath=os.path.basename(steering_filepath))
- # Cleanup intermediate files if the computation was successful
- cmd += " ; if test $rc -eq 0; then rm -rf %s ; fi" % " ".join(interm_files)
+ # Launch the command
+ logger.debug("Running the following command in salome shell in %s: %s", steering_file_dir, cmd)
+ try:
+ log = subprocess.check_output(cmd, cwd=steering_file_dir, stderr=subprocess.STDOUT, shell=True)
+ passed = True
+ log = log.decode('utf-8')
+ except subprocess.CalledProcessError as e:
+ passed = False
+ log = str(e)+"\n"+e.output.decode('utf-8')
- cmd += ' ; echo "return code is $rc"'
+ return passed, log
- # Launch the command
- logger.debug("Running the following command in xterm: %s" % cmd)
- args = ["xterm", "-T", "Execution of Telemac", "-geo", "80x60", "-hold", "-l", "-e", cmd]
- if param_dict.has_key('batchExec'):
- if param_dict['batchExec'] == True:
- args = ["xterm", "-T", "Execution of Telemac", "-geo", "80x60", "+hold", "-l", "-e", cmd]
- subprocess.Popen(args, cwd = wrkdir)
def check_file_or_create_link(filepath, dirpath, interm_file_list = None):
"""