Salome HOME
Correct the message when incompatible options are called
[tools/sat.git] / src / fileEnviron.py
index 8463fc8929663b5126e4a2aece2f2d37b128ab43..27071d0be384cb81a79dc4356d38a78cf30fca78 100644 (file)
@@ -18,7 +18,7 @@
 
 import os
 
-batch_header="""@echo off
+bat_header="""@echo off
 
 rem The following variables are used only in case of a sat package
 set out_dir_Path=%~dp0
@@ -70,8 +70,6 @@ export $1=$out_var
 export out_dir_Path=`dirname "${BASH_SOURCE[0]}"`
 export PRODUCT_OUT_DIR=${out_dir_Path}
 export PRODUCT_ROOT_DIR=${PRODUCT_OUT_DIR}
-export prereq_install_Path=${out_dir_Path}/PREREQUISITES/INSTALL
-export prereq_build_Path=${out_dir_Path}/PREREQUISITES/BUILD
 
 ###########################################################################
 """
@@ -89,8 +87,8 @@ def get_file_environ(output, shell, environ=None):
     """
     if shell == "bash":
         return BashFileEnviron(output, environ)
-    if shell == "batch":
-        return BatchFileEnviron(output, environ)
+    if shell == "bat":
+        return BatFileEnviron(output, environ)
     if shell == "cfgForPy":
         return LauncherFileEnviron(output, environ)
     raise Exception("FileEnviron: Unknown shell = %s" % shell)
@@ -277,7 +275,7 @@ class BashFileEnviron(FileEnviron):
             return
         FileEnviron.finish(self, required)
         
-class BatchFileEnviron(FileEnviron):
+class BatFileEnviron(FileEnviron):
     """for Windows batch shell.
     """
     def __init__(self, output, environ=None):
@@ -287,7 +285,7 @@ class BatchFileEnviron(FileEnviron):
         :param environ dict: a potential additional environment.
         """
         self._do_init(output, environ)
-        self.output.write(batch_header)
+        self.output.write(bat_header)
 
     def add_comment(self, comment):
         """Add a comment in the shell file
@@ -364,15 +362,15 @@ class LauncherFileEnviron:
         else:
             self.environ = os.environ
         # Initialize some variables
-        if not self.environ.has_key("PATH"):
+        if not "PATH" in self.environ.keys():
             self.environ["PATH"]=""
-        if not self.environ.has_key("LD_LIBRARY_PATH"):
+        if not "LD_LIBRARY_PATH" in self.environ.keys():
             self.environ["LD_LIBRARY_PATH"]=""
-        if not self.environ.has_key("PYTHONPATH"):
+        if not "PYTHONPATH" in self.environ.keys():
             self.environ["PYTHONPATH"]=""
-        if not self.environ.has_key("TCLLIBPATH"):
+        if not "TCLLIBPATH" in self.environ.keys():
             self.environ["TCLLIBPATH"]=""
-        if not self.environ.has_key("TKLIBPATH"):
+        if not "TKLIBPATH" in self.environ.keys():
             self.environ["TKLIBPATH"]=""
 
         # four whitespaces for first indentation in a python script
@@ -466,7 +464,7 @@ class LauncherFileEnviron:
         
         :param key str: the environment variable to check
         '''
-        return self.environ.has_key(key)
+        return key in self.environ.keys()
 
     def get(self, key):
         '''Get the value of the environment variable "key"
@@ -566,4 +564,164 @@ class LauncherFileEnviron:
         
         :param required bool: Do nothing if required is False
         """
-        return        
\ No newline at end of file
+        return
+
+class ScreenEnviron(FileEnviron):
+    def __init__(self, output, environ=None):
+        self._do_init(output, environ)
+        self.defined = {}
+
+    def add_line(self, number):
+        pass
+
+    def add_comment(self, comment):
+        pass
+
+    def add_echo(self, text):
+        pass
+
+    def add_warning(self, warning):
+        pass
+
+    def write(self, command, name, value, sign="="):
+        import src
+        self.output.write("  %s%s %s %s %s\n" % \
+            (src.printcolors.printcLabel(command),
+             " " * (12 - len(command)),
+             src.printcolors.printcInfo(name), sign, value))
+
+    def is_defined(self, name):
+        return self.defined.has_key(name)
+
+    def get(self, name):
+        return "${%s}" % name
+
+    def set(self, name, value):
+        self.write("set", name, value)
+        self.defined[name] = value
+
+    def prepend(self, name, value, sep=":"):
+        if isinstance(value, list):
+            value = sep.join(value)
+        value = value + sep + self.get(name)
+        self.write("prepend", name, value)
+
+    def append(self, name, value, sep=":"):
+        if isinstance(value, list):
+            value = sep.join(value)
+        value = self.get(name) + sep + value
+        self.write("append", name, value)
+
+    def command_value(self, key, command):
+        pass
+
+    def run_env_script(self, module, script):
+        self.write("load", script, "", sign="")
+
+# The SALOME launcher template 
+withProfile =  """#! /usr/bin/env python
+
+################################################################
+# WARNING: this file is automatically generated by SalomeTools #
+# WARNING: and so could be overwritten at any time.            #
+################################################################
+
+import os
+import sys
+
+
+# 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] = [ os.path.join( 'PROFILE_INSTALL_DIR', 'bin', 'salome' ) ]
+  os.environ['ABSOLUTE_APPLI_PATH'] = 'PROFILE_INSTALL_DIR'
+  
+  # define folder to store omniorb config (initially in virtual application folder)
+  try:
+    from salomeContextUtils import setOmniOrbUserPath
+    setOmniOrbUserPath()
+  except Exception, e:
+    print e
+    sys.exit(1)
+# End of preliminary work
+
+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
+
+    # Start SALOME, parsing command line arguments
+    context.runSalome(args)
+    #print 'Thank you for using SALOME!'
+
+    # Logger level info
+    context.getLogger().setLevel(20)
+
+  except SalomeContextException, 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)
+#
+"""
+    
\ No newline at end of file