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-05-31 15:38:30 +05:00
|
|
|
|
2021-03-18 17:29:30 +05:00
|
|
|
def hasDesktop() -> bool:
|
|
|
|
return salome.sg.hasDesktop()
|
|
|
|
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
class SalomeNotFound(Exception):
|
|
|
|
pass
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
def version() -> str:
|
|
|
|
if os.environ.get("SALOME_PATH"):
|
|
|
|
cmd = os.path.join(os.environ["SALOME_PATH"], "salome")
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
else:
|
|
|
|
raise(SalomeNotFound("Can't find salome executable."))
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
proc = subprocess.Popen(
|
|
|
|
[ cmd, "--version" ],
|
|
|
|
stdout = subprocess.PIPE,
|
|
|
|
stderr = subprocess.PIPE
|
|
|
|
)
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
out, err = proc.communicate()
|
2021-04-14 15:13:41 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
return str(out, "utf-8").strip().split(" ")[-1]
|
2021-04-14 15:13:41 +05:00
|
|
|
|
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
def runSalome(port: int, scriptpath: str, root: str, logpath: str = None, *args) -> int:
|
2021-04-14 15:13:41 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
if os.environ.get("SALOME_PATH"):
|
|
|
|
cmd = os.path.join(os.environ["SALOME_PATH"], salome)
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
else:
|
|
|
|
raise(SalomeNotFound("Can't find salome executable."))
|
2021-03-24 21:27:12 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
if not logpath:
|
|
|
|
logpath = "/tmp/salome.log"
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-07-26 18:00:23 +05:00
|
|
|
fullargs = list(args)
|
|
|
|
fullargs.extend([ root, logpath ])
|
2021-07-19 17:01:42 +05:00
|
|
|
fmtargs = "args:{}".format(", ".join([ str(arg) for arg in args ]))
|
|
|
|
cmdargs = [
|
2021-07-26 18:00:23 +05:00
|
|
|
"start", "-t",
|
|
|
|
"--shutdown-servers=1",
|
|
|
|
"--port", str(port),
|
|
|
|
scriptpath,
|
2021-07-19 17:01:42 +05:00
|
|
|
fmtargs
|
|
|
|
]
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
with subprocess.Popen(
|
|
|
|
[ cmd, cmdargs ],
|
2021-03-22 22:49:56 +05:00
|
|
|
stdout = subprocess.PIPE,
|
2021-07-19 17:01:42 +05:00
|
|
|
stderr = subprocess.PIPE
|
|
|
|
) as proc, open(logpath, "wb") as logfile:
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
logfile = open(logpath, "wb")
|
|
|
|
for line in proc.stdout:
|
|
|
|
logfile.write(line)
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
out, err = p.communicate()
|
2021-03-19 21:59:30 +05:00
|
|
|
|
2021-07-19 17:01:42 +05:00
|
|
|
if err:
|
|
|
|
logfile.write(err)
|
|
|
|
|
|
|
|
return out, err, proc.returncode
|
2021-03-19 21:59:30 +05:00
|
|
|
|