]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
spns #8849 : generation d'un launcher python3 nct/launcher_python3
authorcrouzet <nicolas.crouzet@cea.fr>
Fri, 18 May 2018 15:01:37 +0000 (17:01 +0200)
committercrouzet <nicolas.crouzet@cea.fr>
Fri, 18 May 2018 15:01:37 +0000 (17:01 +0200)
commands/launcher.py
src/fileEnviron.py

index b7d9feda58f842594575ce4611c873f35d374c99..c633fcc401e4aee9dd7f145c0194d314a7797b0f 100644 (file)
@@ -104,10 +104,15 @@ def generate_launch_file(config,
     else:
         app_root_dir=salome_application_name
 
-    # Get the launcher template
-    withProfile = src.fileEnviron.withProfile\
-                     .replace("BIN_KERNEL_INSTALL_DIR", bin_kernel_install_dir)\
-                     .replace("KERNEL_INSTALL_DIR", app_root_dir)
+    # Get the launcher template (python3 or python2)
+    if "python3" in config.APPLICATION and config.APPLICATION.python3 == "yes":
+        withProfile = src.fileEnviron.withProfile3\
+                         .replace("BIN_KERNEL_INSTALL_DIR", bin_kernel_install_dir)\
+                         .replace("KERNEL_INSTALL_DIR", app_root_dir)
+    else:
+        withProfile = src.fileEnviron.withProfile\
+                         .replace("BIN_KERNEL_INSTALL_DIR", bin_kernel_install_dir)\
+                         .replace("KERNEL_INSTALL_DIR", app_root_dir)
 
     before, after = withProfile.split(
                                 "# here your local standalone environment\n")
index 888e94d1a01137e2c0fccc394e02dd29044abc1f..119f4d30eedbe4ebae654f42968e928406e6a62b 100644 (file)
@@ -864,3 +864,130 @@ if __name__ == "__main__":
 #
 """
     
+withProfile3 =  """\
+#! /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
+
+
+# Add the pwdPath to able to run the launcher after unpacking a package
+# Used only in case of a salomeTools package
+out_dir_Path=os.path.abspath(os.path.dirname(__file__))
+
+# Preliminary work to initialize path to SALOME Python modules
+def __initialize():
+
+  sys.path[:0] = [ 'BIN_KERNEL_INSTALL_DIR' ]
+  os.environ['ABSOLUTE_APPLI_PATH'] = 'KERNEL_INSTALL_DIR'
+  
+  # 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)
+
+  #from salomeContextUtils import getConfigFileNames
+  #configFileNames, args, unexisting = getConfigFileNames( args, checkExistence=True )
+  #if len(unexisting) > 0:
+  #  print("ERROR: unexisting configuration file(s): " + ', '.join(unexisting))
+  #  sys.exit(1)
+
+  # Create a SalomeContext which parses configFileNames to initialize environment
+  try:
+    from salomeContext import SalomeContext, SalomeContextException
+    SalomeContext.addToSpecial=addToSpecial
+    context = SalomeContext(None)
+    
+    # Here set specific variables, if needed
+    # context.addToPath('mypath')
+    # context.addToLdLibraryPath('myldlibrarypath')
+    # context.addToPythonPath('mypythonpath')
+    # context.setVariable('myvarname', 'value')
+
+    # Logger level error
+    context.getLogger().setLevel(40)
+
+    context.setVariable(r"PRODUCT_ROOT_DIR", out_dir_Path, overwrite=True)
+    # here your local standalone environment
+
+    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)
+#
+def addToSpecial(self, name, value, pathSep=None):
+  # add special dangerous cases: TCLLIBPATH PV_PLUGIN_PATH etc...
+  # http://computer-programming-forum.com/57-tcl/1dfddc136afccb94.htm
+  # TCLLIBPATH: Tcl treats the contents of that variable as a list. Be happy, for you can now use drive letters on windows.
+  if value == '':
+    return
+  
+  specialBlanksKeys=["TCLLIBPATH", "TKLIBPATH"]
+  specialSemicolonKeys=["PV_PLUGIN_PATH"]
+  res=os.pathsep
+  if name in specialBlanksKeys: res=" "
+  if name in specialSemicolonKeys: res=";"
+  
+  if pathSep==None:
+    sep=res
+  else:
+    sep=pathSep
+  value = os.path.expandvars(value) # expand environment variables
+  self.getLogger().debug("Add to %s: %s", name, value)
+  env = os.getenv(name, None)
+  if env is None:
+    os.environ[name] = value
+  else:
+    os.environ[name] = value + sep + env #explicitely or not special path separator ?whitespace, semicolon?
+
+if __name__ == "__main__":
+  args = sys.argv[1:]
+  main(args)
+#
+"""
+