#!/usr/bin/env python
-#-*- coding:utf-8 -*-
+# -*- coding:utf-8 -*-
# Copyright (C) 2010-2013 CEA/DEN
#
# This library is free software; you can redistribute it and/or
# OP
import src
+
def show_progress(logger, top, delai, ss=""):
"""shortcut function to display the progression
-
+
:param logger Logger: The logging instance
:param top int: the number to display
:param delai int: the number max
:param ss str: the string to display
"""
- logger.write("\r%s\r%s timeout %s / %s stay %s s " % ((" " * 30), ss, top, delai, (delai - top)), 4, False)
+ logger.write(
+ "\r%s\r%s timeout %s / %s stay %s s "
+ % ((" " * 30), ss, top, delai, (delai - top)),
+ 4,
+ False,
+ )
logger.flush()
+
def write_back(logger, message, level):
"""shortcut function to write at the begin of the line
-
+
:param logger Logger: The logging instance
:param message str: the text to display
:param level int: the level of verbosity
"""
logger.write("\r%s\r%s" % ((" " * 40), message), level)
+
# Launch command
# --------------
def launch_command(cmd, logger, cwd, args=[], log=None):
# Add Windows case
if src.architecture.is_windows():
- prs = subprocess.Popen(cmd,
- shell=True,
- stdout=log,
- stderr=subprocess.STDOUT,
- cwd=cwd)
+ prs = subprocess.Popen(
+ cmd, shell=True, stdout=log, stderr=subprocess.STDOUT, cwd=cwd
+ )
else:
- prs = subprocess.Popen(cmd,
- shell=True,
- stdout=log,
- stderr=subprocess.STDOUT,
- cwd=cwd,
- executable='/bin/bash')
+ prs = subprocess.Popen(
+ cmd,
+ shell=True,
+ stdout=log,
+ stderr=subprocess.STDOUT,
+ cwd=cwd,
+ executable="/bin/bash",
+ )
return prs
+
# Launch a batch
# --------------
def batch(cmd, logger, cwd, args=[], log=None, delai=20, sommeil=1):
if top == delai:
logger.write("batch: time out KILL\n", 3)
import signal
+
os.kill(proc.pid, signal.SIGTERM)
break
else:
# Launch a salome process
# -----------------------
-def batch_salome(cmd, logger, cwd, args, getTmpDir,
- pendant="SALOME_Session_Server", fin="killSalome.py",
- log=None, delai=20, sommeil=1, delaiapp=0):
+def batch_salome(
+ cmd,
+ logger,
+ cwd,
+ args,
+ getTmpDir,
+ pendant="SALOME_Session_Server",
+ fin="killSalome.py",
+ log=None,
+ delai=20,
+ sommeil=1,
+ delaiapp=0,
+):
beginTime = time.time()
launch_command(cmd, logger, cwd, args, log)
foundSalome = "batch salome not seen"
tmp_dir = getTmpDir()
# print("batch_salome %s %s / %s sommeil %s:\n%s" % (tmp_dir, delai, delaiapp, sommeil, cmd))
- while (not found and top < delaiapp):
+ while not found and top < delaiapp:
if os.path.exists(tmp_dir):
listFile = os.listdir(tmp_dir)
listFile = [f for f in listFile if f.endswith("_pidict")]
time.sleep(sommeil)
top += 1
- show_progress(logger, top, delaiapp, "launching salome or appli found=%s:" % found)
+ show_progress(
+ logger, top, delaiapp, "launching salome or appli found=%s:" % found
+ )
# continue or not
if found:
logger.write("\nbatch_salome: supposed started\n", 5)
else:
- logger.write("\nbatch_salome: seems FAILED to launch salome or appli : %s\n" % foundSalome, 3)
+ logger.write(
+ "\nbatch_salome: seems FAILED to launch salome or appli : %s\n"
+ % foundSalome,
+ 3,
+ )
return False, -1
# salome launched run the script