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'))
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')
##
# 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.
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)
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)
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.
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
# 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,
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
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',
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" ]
##
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:
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):
###########################################################################
"""
+cfg_header='''[SALOME Configuration]
+'''
Launcher_header='''# a generated SALOME Configuration file using python syntax
'''
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:
"""
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.