2021-03-24 21:27:12 +05:00
|
|
|
#import salome
|
2021-03-22 15:44:22 +05:00
|
|
|
import subprocess
|
|
|
|
import logging
|
2021-05-17 00:39:07 +05:00
|
|
|
import sys, os
|
2021-04-15 18:46:43 +05:00
|
|
|
import config
|
|
|
|
from config import logger
|
2021-03-18 17:29:30 +05:00
|
|
|
|
|
|
|
def hasDesktop() -> bool:
|
|
|
|
return salome.sg.hasDesktop()
|
|
|
|
|
2021-03-22 22:49:56 +05:00
|
|
|
def startServer(port):
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-04-15 18:46:43 +05:00
|
|
|
logger.info("Starting SALOME on port {} ...".format(port))
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-03-25 23:22:21 +05:00
|
|
|
p = subprocess.Popen(["salome", "start", "--port", str(port), "-t"],
|
2021-03-24 21:27:12 +05:00
|
|
|
#shell = False,
|
2021-03-22 22:49:56 +05:00
|
|
|
stdout = subprocess.PIPE,
|
|
|
|
stderr = subprocess.PIPE)
|
2021-03-19 21:59:30 +05:00
|
|
|
|
|
|
|
return p
|
|
|
|
|
2021-04-14 15:13:41 +05:00
|
|
|
def salomeVersion() -> str:
|
|
|
|
return "Salome 9.6.0"
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-04-14 15:13:41 +05:00
|
|
|
def runExecute(port: int, scriptpath: str, *args) -> int:
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-04-14 15:13:41 +05:00
|
|
|
cmd = ["salome", "start", "--shutdown-servers=1", "--port", str(port), "-t",
|
|
|
|
scriptpath, "args:{}".format(", ".join([str(arg) for arg in args]))]
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-04-15 18:46:43 +05:00
|
|
|
logger.info("salome: {}".format(cmd[1 : 6]))
|
2021-05-13 20:51:26 +05:00
|
|
|
logpath = os.path.join("/".join(args[4].split("/")[:-1]), "salome.log")
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-04-14 15:13:41 +05:00
|
|
|
#p = subprocess.Popen(["salome", "start", "--shutdown-servers=1", "--port", str(port), "-t", scriptpath, "args:{}".format(", ".join([str(arg) for arg in args]))],
|
|
|
|
# stderr = subprocess.STDOUT)
|
|
|
|
#_, err = p.communicate()
|
|
|
|
|
|
|
|
with subprocess.Popen(cmd,
|
|
|
|
stdout = subprocess.PIPE,
|
2021-05-13 20:51:26 +05:00
|
|
|
stderr = subprocess.PIPE) as p, \
|
|
|
|
open(logpath, "wb") as logfile:
|
2021-04-14 15:13:41 +05:00
|
|
|
|
2021-05-13 20:51:26 +05:00
|
|
|
for line in p.stdout:
|
2021-04-14 15:13:41 +05:00
|
|
|
# sys.stdout.buffer.write(line)
|
2021-05-13 20:51:26 +05:00
|
|
|
logfile.write(line)
|
2021-04-14 15:13:41 +05:00
|
|
|
|
|
|
|
out, err = p.communicate()
|
2021-05-13 20:51:26 +05:00
|
|
|
#print(str(err, "utf-8"))
|
|
|
|
logfile.write(err)
|
2021-04-14 15:13:41 +05:00
|
|
|
|
2021-05-13 20:51:26 +05:00
|
|
|
if err:
|
2021-04-15 18:46:43 +05:00
|
|
|
logger.error("salome:\n\t{}".format(str(err, "utf-8")))
|
2021-04-14 15:13:41 +05:00
|
|
|
#if err:
|
|
|
|
# if p.returncode == 1:
|
2021-04-15 18:46:43 +05:00
|
|
|
# logger.error(err)
|
2021-04-14 15:13:41 +05:00
|
|
|
|
|
|
|
# else:
|
2021-04-15 18:46:43 +05:00
|
|
|
# logger.warning(err)
|
2021-03-25 23:22:21 +05:00
|
|
|
|
|
|
|
return p.returncode
|
2021-03-24 21:27:12 +05:00
|
|
|
|
2021-03-22 22:49:56 +05:00
|
|
|
def killServer(port):
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-04-15 18:46:43 +05:00
|
|
|
logger.info("Terminating SALOME on port {} ...".format(port))
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-03-25 23:22:21 +05:00
|
|
|
p = subprocess.Popen(["salome", "kill", str(port)],
|
2021-03-24 21:27:12 +05:00
|
|
|
#shell = True,
|
2021-03-22 22:49:56 +05:00
|
|
|
stdout = subprocess.PIPE,
|
|
|
|
stderr = subprocess.PIPE)
|
2021-03-19 21:59:30 +05:00
|
|
|
|
|
|
|
return p
|
|
|
|
|
2021-03-24 21:27:12 +05:00
|
|
|
def remote(port, cmd):
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-04-15 18:46:43 +05:00
|
|
|
logger.info("Executing command in the SALOME on port {} ...".format(port))
|
2021-03-22 22:49:56 +05:00
|
|
|
|
|
|
|
# cmd = "python -m"; = "python -c"
|
2021-03-25 23:22:21 +05:00
|
|
|
p = subprocess.Popen(["salome", "remote", "-p", str(port), "--", str(cmd)],
|
2021-03-24 21:27:12 +05:00
|
|
|
#shell = True,
|
2021-03-22 22:49:56 +05:00
|
|
|
stdout = subprocess.PIPE,
|
|
|
|
stderr = subprocess.PIPE)
|
2021-03-19 21:59:30 +05:00
|
|
|
|
|
|
|
return p
|