New: SalomeManager
Mod: docs New: bashrc example
This commit is contained in:
parent
3f8d798965
commit
8b70f273db
3
INSTALL.rst
Normal file
3
INSTALL.rst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
@ -27,7 +27,7 @@ env.update(
|
|||||||
env.update(
|
env.update(
|
||||||
logger_name = "anisotropy",
|
logger_name = "anisotropy",
|
||||||
db_path = env["BUILD"],
|
db_path = env["BUILD"],
|
||||||
salome_port = 2810,
|
salome_timeout = 15 * 60,
|
||||||
openfoam_template = os.path.join(env["ROOT"], "anisotropy/openfoam/template")
|
openfoam_template = os.path.join(env["ROOT"], "anisotropy/openfoam/template")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class Anisotropy(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
versions["Salome"] = salomepl.utils.version()
|
versions["Salome"] = salomepl.utils.SalomeManager().version()
|
||||||
versions["OpenFOAM"] = openfoam.version()
|
versions["OpenFOAM"] = openfoam.version()
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -230,20 +230,25 @@ class Anisotropy(object):
|
|||||||
:return: Process output, error messages and returncode
|
:return: Process output, error messages and returncode
|
||||||
:rtype: tuple(str, str, int)
|
:rtype: tuple(str, str, int)
|
||||||
"""
|
"""
|
||||||
scriptpath = os.path.join(self.env["ROOT"], "anisotropy/core/cli.py")
|
|
||||||
port = 2900
|
|
||||||
|
|
||||||
p = self.params["structure"]
|
p = self.params["structure"]
|
||||||
|
scriptpath = os.path.join(self.env["ROOT"], "anisotropy/core/cli.py")
|
||||||
return salomepl.utils.runSalome(
|
salomeargs = [
|
||||||
self.env["salome_port"],
|
|
||||||
scriptpath,
|
|
||||||
self.env["ROOT"],
|
|
||||||
"computemesh",
|
"computemesh",
|
||||||
p["type"], p["direction"], p["theta"],
|
p["type"],
|
||||||
|
p["direction"],
|
||||||
|
p["theta"],
|
||||||
|
]
|
||||||
|
manager = salomepl.utils.SalomeManager()
|
||||||
|
|
||||||
|
return manager.execute(
|
||||||
|
scriptpath,
|
||||||
|
*salomeargs,
|
||||||
|
timeout = self.env["salome_timeout"],
|
||||||
|
root = self.env["ROOT"],
|
||||||
logpath = os.path.join(self.env["LOG"], "salome.log")
|
logpath = os.path.join(self.env["LOG"], "salome.log")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def genmesh(self):
|
def genmesh(self):
|
||||||
"""Computes a mesh on shape
|
"""Computes a mesh on shape
|
||||||
|
|
||||||
|
@ -2,76 +2,105 @@
|
|||||||
# This file is part of anisotropy.
|
# This file is part of anisotropy.
|
||||||
# License: GNU GPL version 3, see the file "LICENSE" for details.
|
# License: GNU GPL version 3, see the file "LICENSE" for details.
|
||||||
|
|
||||||
#import salome
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
import sys, os
|
import sys, os
|
||||||
|
import re
|
||||||
def hasDesktop() -> bool:
|
|
||||||
return salome.sg.hasDesktop()
|
|
||||||
|
|
||||||
|
|
||||||
class SalomeNotFound(Exception):
|
class SalomeNotFound(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def version() -> str:
|
class SalomeManager(object):
|
||||||
if os.environ.get("SALOME_PATH"):
|
def __init__(self):
|
||||||
cmd = os.path.join(os.environ["SALOME_PATH"], "salome")
|
self.__port = None
|
||||||
|
self.__lastproc = None
|
||||||
|
|
||||||
else:
|
|
||||||
raise(SalomeNotFound("Can't find salome executable."))
|
|
||||||
|
|
||||||
proc = subprocess.Popen(
|
def runner(self, cmdargs: list, **kwargs):
|
||||||
[ cmd, "--version" ],
|
timeout = kwargs.pop("timeout") if kwargs.get("timeout") else None
|
||||||
stdout = subprocess.PIPE,
|
|
||||||
stderr = subprocess.PIPE
|
|
||||||
)
|
|
||||||
|
|
||||||
out, err = proc.communicate()
|
|
||||||
|
|
||||||
return str(out, "utf-8").strip().split(" ")[-1]
|
|
||||||
|
|
||||||
def runSalome(port: int, scriptpath: str, root: str, *args, logpath: str = None) -> int:
|
|
||||||
# ISSUE: salome removes commas from string list
|
|
||||||
|
|
||||||
if os.environ.get("SALOME_PATH"):
|
|
||||||
cmd = [ os.path.join(os.environ["SALOME_PATH"], "salome") ]
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise(SalomeNotFound("Can't find salome executable."))
|
|
||||||
|
|
||||||
if not logpath:
|
|
||||||
logpath = "/tmp/salome.log"
|
|
||||||
|
|
||||||
#fullargs = list(args)
|
|
||||||
args = list(args)
|
|
||||||
args.insert(1, root)
|
|
||||||
fmtargs = "args:{}".format(",".join([ '"{}"'.format(str(arg)) for arg in args ]))
|
|
||||||
cmdargs = [
|
|
||||||
"start", "-t",
|
|
||||||
"--shutdown-servers=1",
|
|
||||||
"--port", str(port),
|
|
||||||
scriptpath,
|
|
||||||
fmtargs
|
|
||||||
]
|
|
||||||
|
|
||||||
cmd.extend(cmdargs)
|
|
||||||
|
|
||||||
|
try:
|
||||||
with subprocess.Popen(
|
with subprocess.Popen(
|
||||||
cmd,
|
cmdargs,
|
||||||
stdout = subprocess.PIPE,
|
stdout = kwargs.pop("stdout") if kwargs.get("stdout") else subprocess.PIPE,
|
||||||
stderr = subprocess.PIPE
|
stderr = kwargs.pop("stdout") if kwargs.get("stderr") else subprocess.PIPE,
|
||||||
) as proc, open(logpath, "wb") as logfile:
|
**kwargs
|
||||||
|
) as proc:
|
||||||
|
self.__lastproc = proc
|
||||||
|
out, err = proc.communicate(timeout = timeout)
|
||||||
|
|
||||||
logfile = open(logpath, "wb")
|
except FileNotFoundError:
|
||||||
for line in proc.stdout:
|
raise SalomeNotFound()
|
||||||
logfile.write(line)
|
|
||||||
|
|
||||||
out, err = proc.communicate()
|
|
||||||
|
|
||||||
if err:
|
|
||||||
logfile.write(err)
|
|
||||||
|
|
||||||
return out, err, proc.returncode
|
return out, err, proc.returncode
|
||||||
|
|
||||||
|
|
||||||
|
def port(self) -> int:
|
||||||
|
out, err, returncode = self.runner(["salome", "start", "--print-port"], text = True)
|
||||||
|
|
||||||
|
if returncode == 0:
|
||||||
|
reg = re.search("(?!port:)([0-9]+)", out)
|
||||||
|
|
||||||
|
if reg:
|
||||||
|
return int(reg.group())
|
||||||
|
|
||||||
|
return 2810
|
||||||
|
|
||||||
|
|
||||||
|
def version(self) -> int:
|
||||||
|
out, err, returncode = self.runner(["salome", "--version"], text = True)
|
||||||
|
|
||||||
|
return out.strip().split(" ")[-1]
|
||||||
|
|
||||||
|
|
||||||
|
def kill(self, port: int = None):
|
||||||
|
return self.runner(["salome", "kill", str(self.__port or port)])
|
||||||
|
|
||||||
|
|
||||||
|
def execute(self, scriptpath: str, *args, root: str = None, logpath: str = None, timeout: int = None, **kwargs):
|
||||||
|
|
||||||
|
if not root:
|
||||||
|
root = os.environ["HOME"]
|
||||||
|
|
||||||
|
# ISSUE: salome removes commas from string list
|
||||||
|
args = list(args)
|
||||||
|
args.insert(1, root)
|
||||||
|
|
||||||
|
salomeargs = "args:"
|
||||||
|
salomeargs += ",".join([ '"{}"'.format(str(arg)) for arg in args ])
|
||||||
|
|
||||||
|
if kwargs:
|
||||||
|
salomeargs += "," + ",".join([ '{}="{}"'.format(k, v) for k, v in kwargs.items() ])
|
||||||
|
|
||||||
|
###
|
||||||
|
self.__port = self.port()
|
||||||
|
cmd = [
|
||||||
|
"salome",
|
||||||
|
"start",
|
||||||
|
"-t",
|
||||||
|
"--shutdown-servers=1",
|
||||||
|
"--port", str(self.__port),
|
||||||
|
scriptpath,
|
||||||
|
salomeargs
|
||||||
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
out, err, returncode = self.runner(cmd, timeout = timeout)
|
||||||
|
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
lastproc = self.__lastproc
|
||||||
|
self.kill()
|
||||||
|
|
||||||
|
out, err = lastproc.communicate()
|
||||||
|
returncode = lastproc.returncode
|
||||||
|
|
||||||
|
if logpath:
|
||||||
|
with open(os.path.join(logpath, "salome.log"), "wb") as io:
|
||||||
|
io.write(out)
|
||||||
|
io.write(err)
|
||||||
|
|
||||||
|
return str(out, "utf-8"), str(err, "utf-8"), returncode
|
||||||
|
|
||||||
|
|
||||||
|
2
conf/bashrc
Normal file
2
conf/bashrc
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export PATH="${PATH}:${HOME}/programs/salome/SALOME-9.7.0-MPI"
|
||||||
|
source "${HOME}/programs/OpenFOAM/OpenFOAM-v2012/etc/bashrc"
|
3
docs/source/INSTALL.rst
Normal file
3
docs/source/INSTALL.rst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
@ -5,7 +5,7 @@ Subpackages
|
|||||||
-----------
|
-----------
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 4
|
:maxdepth: 1
|
||||||
|
|
||||||
anisotropy.core
|
anisotropy.core
|
||||||
anisotropy.openfoam
|
anisotropy.openfoam
|
||||||
|
@ -10,7 +10,8 @@ Welcome to anisotropy's documentation!
|
|||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
:caption: Contents:
|
:caption: Contents:
|
||||||
|
|
||||||
modules
|
INSTALL
|
||||||
|
anisotropy
|
||||||
|
|
||||||
.. include:: ../../README.rst
|
.. include:: ../../README.rst
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user