Salome HOME
Restauration de la commande application
authorcrouzet <nicolas.crouzet@cea.fr>
Tue, 18 Jul 2017 14:36:38 +0000 (16:36 +0200)
committercrouzet <nicolas.crouzet@cea.fr>
Tue, 18 Jul 2017 14:36:38 +0000 (16:36 +0200)
 - Prise en charge des fichiers d'environnement cfg
 - section APPLICATION.virtual_app pour prĂ©ciser les infos (en remplacement de l'ancienne section APPLI)
 - prise en compte d'une nouvelle property fhs pour la mise en place auto de l'environnement SALOME

commands/application.py
commands/environ.py
src/environment.py
src/fileEnviron.py

index 971278db33790ee22d5544d0c4d6147f5ddd6290..ddb3bb7617006f91fd6302bca8f701d1e7890116 100644 (file)
@@ -28,7 +28,7 @@ import src
 
 parser = src.options.Options()
 parser.add_option('n', 'name', 'string', 'name',
-    _('Optional: The name of the application (default is APPLI.name or '
+    _('Optional: The name of the application (default is APPLICATION.virtual_app.name or '
       'runAppli)'))
 parser.add_option('c', 'catalog', 'string', 'catalog',
     _('Optional: The resources catalog to use'))
@@ -79,7 +79,10 @@ def create_config_file(config, modules, env_file, logger):
     f = open(config_file, "w")
 
     f.write('<application>\n')
-    f.write('<prerequisites path="%s"/>\n' % env_file)
+    if env_file.endswith("cfg"):
+        f.write('<context path="%s"/>\n' % env_file)
+    else:   
+        f.write('<prerequisites path="%s"/>\n' % env_file)
     f.write('<resources path="CatalogResources.xml"/>\n')
     f.write('<modules>\n')
 
@@ -118,8 +121,8 @@ def create_config_file(config, modules, env_file, logger):
 ##
 # Customizes the application by editing SalomeApp.xml.
 def customize_app(config, appli_dir, logger):
-    if 'configure' not in config.APPLI \
-        or len(config.APPLI.configure) == 0:
+    if 'configure' not in config.APPLICATION.virtual_app \
+        or len(config.APPLICATION.virtual_app.configure) == 0:
         return
 
     # shortcut to get an element (section or parameter) from parent.
@@ -152,9 +155,9 @@ def customize_app(config, appli_dir, logger):
     assert document is not None, "document tag not found"
 
     logger.write("\n", 4)
-    for section_name in config.APPLI.configure:
-        for parameter_name in config.APPLI.configure[section_name]:
-            parameter_value = config.APPLI.configure[section_name][parameter_name]
+    for section_name in config.APPLICATION.virtual_app.configure:
+        for parameter_name in config.APPLICATION.virtual_app.configure[section_name]:
+            parameter_value = config.APPLICATION.virtual_app.configure[section_name][parameter_name]
             logger.write("  configure: %s/%s = %s\n" % (section_name,
                                                         parameter_name,
                                                         parameter_value), 4)
@@ -272,8 +275,12 @@ def generate_launch_file(config, appli_dir, catalog, logger, l_SALOME_modules):
     finally:
         logger.write(src.printcolors.printc(status) + "\n", 2, False)
 
-    # build the application
-    env_file = os.path.join(config.APPLICATION.workdir, "env_launch.sh")
+    # build the application (the name depends upon salome version
+    # for salome 8 we use a salome context file
+    VersionSalome = src.get_salome_version(config)
+    env_ext="cfg" if VersionSalome>=820 else "sh"
+    env_file = os.path.join(config.APPLICATION.workdir, "env_launch.cfg")
+
     write_step(logger, _("Building application"), level=2)
     cf = create_config_file(config, l_SALOME_modules, env_file, logger)
 
@@ -296,44 +303,6 @@ def generate_launch_file(config, appli_dir, catalog, logger, l_SALOME_modules):
     return retcode
 
 
-##
-# Generates a launcher that sources Salome's python and calls original launcher
-def generate_sourcing_launcher(config, appli_dir, logger) :
-
-    # Rename original launcher
-    launcher_name = os.path.join( appli_dir,
-                                  "bin",
-                                  "salome",
-                                  config.APPLI.launch_alias_name )
-    original_launcher = launcher_name + "-original"
-    os.rename( launcher_name, original_launcher )
-    
-    # Open new launcher
-    f = open(launcher_name, "w")
-    
-    # Write the set up of the environment
-    env = src.environment.SalomeEnviron( config,
-                                         src.fileEnviron.get_file_environ(
-                                                                        f,
-                                                                        "bash",
-                                                                        {},
-                                                                        config))
-    env.set_a_product( "Python", logger)
-    
-    # Write the call to the original launcher
-    f.write( "\n\n")
-    f.write( "# This is the call to the original launcher\n")
-    f.write( original_launcher + " $*" )
-    f.write( "\n\n")
-    
-    # Write the cleaning of the environment
-    env.finish(True)
-    
-    # Close new launcher
-    f.close()
-    os.chmod(launcher_name, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO) # 0777
-
-   
 
 ##
 # Generates the catalog from a list of machines.
@@ -423,9 +392,9 @@ def run(args, runner, logger):
     application = src.printcolors.printcLabel(runner.cfg.VARS.application)
     logger.write(_("Building application for %s\n") % application, 1)
 
-    # if section APPLI does not exists create one
-    if "APPLI" not in runner.cfg:
-        msg = _("The section APPLI is not defined in the product.")
+    # if section APPLICATION.virtual_app does not exists create one
+    if "virtual_app" not in runner.cfg.APPLICATION:
+        msg = _("The section APPLICATION.virtual_app is not defined in the product.")
         logger.write(src.printcolors.printcError(msg), 1)
         logger.write("\n", 1)
         return 1
@@ -437,16 +406,16 @@ def run(args, runner, logger):
 
     # set list of modules
     if options.modules:
-        runner.cfg.APPLI['modules'] = options.modules
+        runner.cfg.APPLICATION.virtual_app['modules'] = options.modules
 
     # set name and application_name
     if options.name:
-        runner.cfg.APPLI['name'] = options.name
-        runner.cfg.APPLI['application_name'] = options.name + "_appdir"
+        runner.cfg.APPLICATION.virtual_app['name'] = options.name
+        runner.cfg.APPLICATION.virtual_app['application_name'] = options.name + "_appdir"
     
-    application_name = src.get_cfg_param(runner.cfg.APPLI,
+    application_name = src.get_cfg_param(runner.cfg.APPLICATION.virtual_app,
                                          "application_name",
-                                         runner.cfg.APPLI.name + "_appdir")
+                                         runner.cfg.APPLICATION.virtual_app.name + "_appdir")
     appli_dir = os.path.join(target_dir, application_name)
 
     src.printcolors.print_value(logger,
@@ -464,18 +433,18 @@ def run(args, runner, logger):
         catalog_src = options.gencat
         catalog = generate_catalog(options.gencat.split(","),
                                    runner.cfg,logger)
-    elif 'catalog' in runner.cfg.APPLI:
+    elif 'catalog' in runner.cfg.APPLICATION.virtual_app:
         # use catalog specified in the product
-        if runner.cfg.APPLI.catalog.endswith(".xml"):
+        if runner.cfg.APPLICATION.virtual_app.catalog.endswith(".xml"):
             # catalog as a file
-            catalog = runner.cfg.APPLI.catalog
+            catalog = runner.cfg.APPLICATION.virtual_app.catalog
         else:
             # catalog as a list of computers
-            catalog_src = runner.cfg.APPLI.catalog
+            catalog_src = runner.cfg.APPLICATION.virtual_app.catalog
             mlist = filter(lambda l: len(l.strip()) > 0,
-                           runner.cfg.APPLI.catalog.split(","))
+                           runner.cfg.APPLICATION.virtual_app.catalog.split(","))
             if len(mlist) > 0:
-                catalog = generate_catalog(runner.cfg.APPLI.catalog.split(","),
+                catalog = generate_catalog(runner.cfg.APPLICATION.virtual_app.catalog.split(","),
                                            runner.cfg, logger)
 
     # display which catalog is used
index a552fddf0aa609d77e637f08ee8dc23fa23a4e49..b34aed761255cd83ca34084a6df4a3a32a6d100e 100644 (file)
@@ -23,7 +23,7 @@ import src
 parser = src.options.Options()
 parser.add_option('', 'shell', 'list2', 'shell',
     _("Optional: Generates the environment files for the given format: "
-      "bash (default), bat (for windows) or all."), [])
+      "bash (default), bat (for windows), cfg (salome context file) or all."), [])
 parser.add_option('p', 'products', 'list2', 'products',
     _("Optional: Includes only the specified products."))
 parser.add_option('', 'prefix', 'string', 'prefix',
@@ -34,8 +34,8 @@ parser.add_option('t', 'target', 'string', 'out_dir',
     None)
 
 # list of available shells with extensions
-C_SHELLS = { "bash": "sh", "bat": "bat" }
-C_ALL_SHELL = [ "bash", "bat" ]
+C_SHELLS = { "bash": "sh", "bat": "bat", "cfg" : "cfg" }
+C_ALL_SHELL = [ "bash", "bat", "cfg" ]
 
 
 ##
index ad7ff4064f5ea461a4e23100a190f51011e54266..4adeb116b8b1741422990dcb3596d3a7428d8df8 100644 (file)
@@ -393,26 +393,29 @@ class SalomeEnviron:
         l_binpath_libpath = []
 
         # create additional ROOT_DIR for CPP components
-        if 'component_name' in pi:
+        if src.product.product_is_cpp(pi):
+            assert 'component_name' in pi, 'Error : CPP component should have a component_name field'
             compo_name = pi.component_name
-            if compo_name + "CPP" == pi.name:
-                compo_root_dir = compo_name + "_ROOT_DIR"
-                envcompo_root_dir = os.path.join(
-                            self.cfg.TOOLS.common.install_root, compo_name )
-                self.set(compo_root_dir ,  envcompo_root_dir)
-                bin_path = os.path.join(envcompo_root_dir, 'bin', 'salome')
-                lib_path = os.path.join(envcompo_root_dir, 'lib', 'salome')
-                l_binpath_libpath.append( (bin_path, lib_path) )
-
-        appliname = 'salome'
-        if (src.get_cfg_param(pi, 'product_type', 'SALOME').upper() 
-                            not in [ "SALOME", "SMESH_PLUGIN", "SAMPLE" ]):
-            appliname = ''
+            compo_root_dir = compo_name + "_ROOT_DIR"
+            envcompo_root_dir = os.path.join(
+                        self.cfg.TOOLS.common.install_root, compo_name )
+            self.set(compo_root_dir ,  envcompo_root_dir)
+            bin_path = os.path.join(envcompo_root_dir, 'bin', 'salome')
+            lib_path = os.path.join(envcompo_root_dir, 'lib', 'salome')
+            l_binpath_libpath.append( (bin_path, lib_path) )
+
+        bin_path = os.path.join(env_root_dir, 'bin', 'salome')
+        if src.get_property_in_product_cfg(pi, "fhs"):
+            lib_path = os.path.join(env_root_dir, 'lib')
+            pylib1_path = os.path.join(env_root_dir, self.python_lib0)
+            pylib2_path = os.path.join(env_root_dir, self.python_lib1)
+        else:
+            lib_path = os.path.join(env_root_dir, 'lib', 'salome')
+            pylib1_path = os.path.join(env_root_dir, self.python_lib0, 'salome')
+            pylib2_path = os.path.join(env_root_dir, self.python_lib1, 'salome')
 
         # Construct the paths to prepend to PATH and LD_LIBRARY_PATH and 
         # PYTHONPATH
-        bin_path = os.path.join(env_root_dir, 'bin', appliname)
-        lib_path = os.path.join(env_root_dir, 'lib', appliname)
         l_binpath_libpath.append( (bin_path, lib_path) )
 
         for bin_path, lib_path in l_binpath_libpath:
@@ -423,10 +426,7 @@ class SalomeEnviron:
                 else :
                     self.prepend('LD_LIBRARY_PATH', lib_path)
 
-            l = [ bin_path, lib_path,
-                  os.path.join(env_root_dir, self.python_lib0, appliname),
-                  os.path.join(env_root_dir, self.python_lib1, appliname)
-                ]
+            l = [ bin_path, lib_path, pylib1_path, pylib2_path ]
             self.prepend('PYTHONPATH', l)
 
     def set_cpp_env(self, product_info):
index 427e29831b3e158f747b8f5e08a90e100d5a45b9..721a5512d8c1e5d68dd651511af532df3e6293a2 100644 (file)
@@ -74,6 +74,8 @@ export PRODUCT_ROOT_DIR=${PRODUCT_OUT_DIR}
 ###########################################################################
 """
 
+cfg_header='''[SALOME Configuration]
+'''
 
 Launcher_header='''# a generated SALOME Configuration file using python syntax
 '''
@@ -91,6 +93,8 @@ def get_file_environ(output, shell, environ=None):
         return BatFileEnviron(output, environ)
     if shell == "cfgForPy":
         return LauncherFileEnviron(output, environ)
+    if shell == "cfg":
+        return ContextFileEnviron(output, environ)
     raise Exception("FileEnviron: Unknown shell = %s" % shell)
 
 class FileEnviron:
@@ -330,6 +334,85 @@ class BatFileEnviron(FileEnviron):
         """
         return
 
+class ContextFileEnviron(FileEnviron):
+    """Class for a salome context configuration file.
+    """
+    def __init__(self, output, environ=None):
+        """Initialization
+        
+        :param output file: the output file stream.
+        :param environ dict: a potential additional environment.
+        """
+        self._do_init(output, environ)
+        self.output.write(cfg_header)
+
+    def set(self, key, value):
+        '''Set the environment variable "key" to value "value"
+        
+        :param key str: the environment variable to set
+        :param value str: the value
+        '''
+        self.output.write('%s="%s"\n' % (key, value))
+        self.environ[key] = value
+
+    def get(self, key):
+        '''Get the value of the environment variable "key"
+        
+        :param key str: the environment variable
+        '''
+        return '%({0})s'.format(key)
+
+    def command_value(self, key, command):
+        '''Get the value given by the system command "command" 
+           and put it in the environment variable key.
+           Has to be overwritten in the derived classes
+           This can be seen as a virtual method
+        
+        :param key str: the environment variable
+        :param command str: the command to execute
+        '''
+        raise NotImplementedError("command_value is not implement "
+                                  "for salome context files!")
+
+    def add_echo(self, text):
+        """Add a comment
+        
+        :param text str: the comment to add
+        """
+        self.add_comment(text)
+
+    def add_warning(self, warning):
+        """Add a warning
+        
+        :param text str: the warning to add
+        """
+        self.add_comment("WARNING %s"  % warning)
+
+    def prepend_value(self, key, value, sep=os.pathsep):
+        '''prepend value to key using sep
+        
+        :param key str: the environment variable to prepend
+        :param value str: the value to prepend to key
+        :param sep str: the separator string
+        '''
+        self.output.write('ADD_TO_%s: %s\n' % (key, value))
+
+    def append_value(self, key, value, sep=os.pathsep):
+        '''append value to key using sep
+        
+        :param key str: the environment variable to append
+        :param value str: the value to append to key
+        :param sep str: the separator string
+        '''
+        self.prepend_value(key, value)
+
+    def finish(self, required=True):
+        """Add a final instruction in the out file (in case of file generation)
+        
+        :param required bool: Do nothing if required is False
+        """
+        return
+
 def special_path_separator(name):
     """TCLLIBPATH, TKLIBPATH, PV_PLUGIN_PATH environments variables need
        some exotic path separator.