From: crouzet Date: Thu, 12 Dec 2019 15:44:01 +0000 (+0100) Subject: add salomeContect based python3 launcher for salome, to be used with already set... X-Git-Tag: V9_5_0a1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9aa864580c67f5206f7deacd594870cf2433a0c3;p=tools%2FSALOME.git add salomeContect based python3 launcher for salome, to be used with already set environment --- diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index 6706be3..3039ff3 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -23,7 +23,8 @@ # These files are executable scripts SET(SCRIPTS - start_salome.py + start_salome.py # light python launcher + salome.py # python launcher with context api relying on runSalome.py ) SALOME_INSTALL_SCRIPTS("${SCRIPTS}" ${SALOME_INSTALL_SCRIPT_PYTHON}) diff --git a/bin/salome.py b/bin/salome.py new file mode 100755 index 0000000..8174d47 --- /dev/null +++ b/bin/salome.py @@ -0,0 +1,75 @@ +#! /usr/bin/env python3 + +################################################################ +# WARNING: this file is automatically generated by SalomeTools # +# WARNING: and so could be overwritten at any time. # +################################################################ + +import os +import sys +import subprocess + +# Preliminary work to initialize path to SALOME Python modules +def __initialize(): + # define folder to store omniorb config (initially in virtual application folder) + try: + from salomeContextUtils import setOmniOrbUserPath + setOmniOrbUserPath() + except Exception as e: + print(e) + sys.exit(1) +# End of preliminary work + +# salome doc only works for virtual applications. Therefore we overwrite it with this function +def _showDoc(modules): + for module in modules: + modulePath = os.getenv(module+"_ROOT_DIR") + if modulePath != None: + baseDir = os.path.join(modulePath, "share", "doc", "salome") + docfile = os.path.join(baseDir, "gui", module.upper(), "index.html") + if not os.path.isfile(docfile): + docfile = os.path.join(baseDir, "tui", module.upper(), "index.html") + if not os.path.isfile(docfile): + docfile = os.path.join(baseDir, "dev", module.upper(), "index.html") + if os.path.isfile(docfile): + out, err = subprocess.Popen(["xdg-open", docfile]).communicate() + else: + print("Online documentation is not accessible for module:", module) + else: + print(module+"_ROOT_DIR not found!") + +def main(args): + # Identify application path then locate configuration files + __initialize() + + if args == ['--help']: + from salomeContext import usage + usage() + sys.exit(0) + + # Create a SalomeContext + try: + from salomeContext import SalomeContext, SalomeContextException + context = SalomeContext(None) + + # Logger level error + context.getLogger().setLevel(40) + + if len(args) >1 and args[0]=='doc': + _showDoc(args[1:]) + return + + # Start SALOME, parsing command line arguments + out, err, status = context.runSalome(args) + sys.exit(status) + + except SalomeContextException as e: + import logging + logging.getLogger("salome").error(e) + sys.exit(1) + + +if __name__ == "__main__": + args = sys.argv[1:] + main(args) +#