Salome HOME
Add commentaries
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 27 Apr 2016 07:17:09 +0000 (09:17 +0200)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 27 Apr 2016 07:17:09 +0000 (09:17 +0200)
17 files changed:
commands/environ.py
commands/testcommand.py
data/products/KERNEL.pyconf
data/products/PRODUCT_ARCHIVE.pyconf
data/products/PRODUCT_CVS.pyconf
data/products/PRODUCT_DEFAULTVERSION.pyconf
data/products/PRODUCT_DEV.pyconf
data/products/PRODUCT_FIXED.pyconf
data/products/PRODUCT_GIT.pyconf
data/products/PRODUCT_NATIVE.pyconf
data/products/PRODUCT_SVN.pyconf
data/products/PRODUCT_UNKNOWN.pyconf
data/products/softA.pyconf
data/products/softB.pyconf
src/compilation.py
src/environment.py
src/product.py

index 6ea7395fd667f630fb2f4de0326f1b7a3c34e784..3c1a939a31af589b833e1cab1ff7cf3c4ac9fb64 100644 (file)
@@ -38,7 +38,7 @@ C_ALL_SHELL = [ "bash", "batch" ]
 ##
 # Writes all the environment files
 def write_all_source_files(config, logger, out_dir=None, src_root=None,
-                           single_dir=None, silent=False, shells=["bash"], prefix="env", env_info=None):
+                           silent=False, shells=["bash"], prefix="env", env_info=None):
     if not out_dir:
         out_dir = config.APPLICATION.workdir
 
@@ -63,7 +63,7 @@ def write_all_source_files(config, logger, out_dir=None, src_root=None,
         else:
             shells_list.append(src.environment.Shell(shell, C_SHELLS[shell]))
     
-    writer = src.environment.FileEnvWriter(config, logger, out_dir, src_root, single_dir, env_info)
+    writer = src.environment.FileEnvWriter(config, logger, out_dir, src_root, env_info)
     writer.silent = silent
     files = []
     for_build = True
@@ -93,10 +93,8 @@ def run(args, runner, logger):
     if options.products is None:
         environ_info = None
     else:
-        environ_info = {}
-
         # add products specified by user (only products included in the application)
-        environ_info['products'] = filter(lambda l: l in runner.cfg.APPLICATION.products.keys(), options.products)
+        environ_info = filter(lambda l: l in runner.cfg.APPLICATION.products.keys(), options.products)
     
     if options.shell == []:
         shell = ["bash"]
index 0a181e9fafc859469937b5bd3b89fac867cbb460..9ad085c902b94b11e22cd8e7e7874d9fb675c678 100644 (file)
@@ -1,15 +1,17 @@
 #!/usr/bin/env python
 #-*- coding:utf-8 -*-
 
-import subprocess
-
 import src
 
-# Define all possible option for config command :  sat config <options>
+# Define all possible option for testcommand command :  sat testcommand <options>
 parser = src.options.Options()
-parser.add_option('u', 'unique', 'boolean', 'unique', "TEST d'option.")
-parser.add_option('v', 'value', 'string', 'value', "Appelle la commande config avec l'option value.")
-parser.add_option('m', 'make', 'boolean', 'test_make', "Test d'une commande exterieure : make.")
+parser.add_option('p', 'product', 'list2', 'nb_proc',
+    _('products to get the sources. This option can be'
+    ' passed several time to get the sources of several products.'))
+
+parser.add_option('', 'dd', 'list2', 'makeflags',
+    _('products to get the sources. This option can be'
+    ' passed several time to get the sources of several products.'))
 
 def description():
     return _("Test d'une commande supplĂ©mentaire.")
@@ -17,15 +19,16 @@ def description():
 
 def run(args, runner, logger):
     (options, args) = parser.parse_args(args)
-    if options.unique:
-        logger.write('unique\n')
-    elif options.value:
-        runner.cfg.VARS.user = 'TEST'
-        runner.config('-v ' + options.value, logger)
-    elif options.test_make:
-        command = "make"
-        logger.write("Execution of make\n", 3)
-        res = subprocess.call(command, cwd=str('/tmp'), shell=True,
-                      stdout=logger.logTxtFile, stderr=logger.logTxtFile)
-        
-        print(res)
\ No newline at end of file
+
+    # check that the command has been called with an application
+    src.check_config_has_application( runner.cfg )
+    
+    pi = src.product.get_product_config(runner.cfg, 'PRODUCT_GIT')
+    
+    builder = src.compilation.Builder(runner.cfg, logger, options, pi)
+    
+    builder.prepare()
+    
+    builder.cmake()
+    
+    builder.make()
\ No newline at end of file
index a362eca6b09b61f1b781d237f35f57c725e279c5..e543ea2700b74ac4fb98b2bea7c188f3ff55ea9a 100644 (file)
@@ -10,10 +10,7 @@ KERNEL_V7_7_1 :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+
     }
     depend : []
     opt_depend : []
index cb3ff804e3ce536e6573e29111e06fc629f98bda..e6d004c3dc11a4cf5e2aeca58078802f680ad67c 100644 (file)
@@ -9,10 +9,6 @@ PRODUCT_ARCHIVE :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
     }
     depend : []
     opt_depend : []
@@ -36,9 +32,9 @@ PRODUCT_ARCHIVE_4_4_2 :
                build: 
                {   
                    "_LD_LIBRARY_PATH" : "COUCOU"
-                   "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-                       "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-                       "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+                   "_PYTHONPATH" : ["TEST" + $VARS.sep + "lib"
+                       "TEST" + $VARS.sep + "${PYTHON_LIBDIR0}"
+                       "TEST" + $VARS.sep + "${PYTHON_LIBDIR1}"]
                }
     }
     env_script : "/home/sr755891/SAT-ETENDU/00-DEV/RESOURCES/env_scripts/pytz.py"
@@ -50,6 +46,7 @@ PRODUCT_ARCHIVE_4_4_2 :
     depend : ['PRODUCT_NATIVE', 'PRODUCT_CVS']
     opt_depend : []
     type : "sample"
+    has_gui : "yes"
     source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
     build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
     patches : []
index 5bff5dbbc6044f9fde37369f59095efec89701d8..7f722a571557613a9d24c1745315a92c2970620a 100644 (file)
@@ -20,10 +20,6 @@ PRODUCT_CVS_V6_7_0 :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
     }
     depend : []
     opt_depend : []
index fa7ca91b8a5bf6d165eb0ef081586bc78c9a82a9..55910a8de9c6cbaf466a8b03aeb6626bc8fa11a5 100644 (file)
@@ -20,10 +20,7 @@ MODULE_DEFAULTVERSION :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+
     }
     depend : []
     opt_depend : []
index ebfefeaeec937ae0ba7501cf77dde5c1819c54b2..46c2afe632f938a27b98e2e5055f63ccce0f0e22 100644 (file)
@@ -10,10 +10,7 @@ PRODUCT_DEV :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+
     }
     depend : []
     opt_depend : []
index 4bfc5acfbada8e9c2ce6d8f9e2d91c83fb4235c7..e107d4558e2023f7c4794de496003af9537ce493 100644 (file)
@@ -4,10 +4,7 @@ PRODUCT_FIXED :
        get_source : "fixed"
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+
     }
     type : "sample"
 }
\ No newline at end of file
index 761379115c128d0847fddc3a4c58eaee898d51d4..0d40f37d80495a419505dd5f09b2885c4dd07fbc 100644 (file)
@@ -10,14 +10,12 @@ PRODUCT_GIT :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+          build : {"ONLY_FOR_BUILD" : "HELLO"}
     }
     depend : [PRODUCT_ARCHIVE, PRODUCT_NATIVE]
     opt_depend : []
-    type : "sample"
+    type : "salome"
+    has_gui : "yes"
     source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
     build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name
     install_dir : "base"
index 52788cc0566e286766ecdaeb51bbb77b63c0af19..77c9c92ca758bba720f5b11802c0fa710c5208d3 100644 (file)
@@ -18,10 +18,7 @@ MODULE_NATIVE :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+
     }
     depend : []
     opt_depend : []
index bca3455b7db775d575f830c9ae7a44efe382d24d..fe7c9b8999c664e71dbf59e803d813c40f928f57 100644 (file)
@@ -18,10 +18,7 @@ PRODUCT_SVN :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+
     }
     depend : []
     opt_depend : []
index cefd2ee6f574a642bd62b679c69806d075d9e16a..85c8eca8df77122b5d93ce464c242d469b1f42d0 100644 (file)
@@ -5,10 +5,7 @@ PRODUCT_UNKNOWN :
     get_source : "unknown"
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+
     }
     depend : []
     opt_depend : []
index a48c30df5d4286e06d8d6a219764652fae1ed20e..aa758efde896e8806d750189b6870e24ebee079d 100644 (file)
@@ -20,10 +20,7 @@ softA :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+
     }
     depend : []
     opt_depend : []
index 5096e19328b9a88bb0542e951da88b4c4d4496bf..38c80321fe887e2fab4794dc02620e0778fa79f7 100644 (file)
@@ -20,10 +20,7 @@ softB :
     }
     environ :
     {
-        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
-            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+
     }
     depend : ['softA']
     opt_depend : []
index f774861a03a7a4a694c7e89735a5def85804b207..afbefc366dc7cb14f5d70750d24e6ffae08d7327 100644 (file)
@@ -95,21 +95,22 @@ class Builder:
         self.product_info = product_info
         self.build_dir = src.Path(self.product_info.build_dir)
         self.source_dir = src.Path(self.product_info.source_dir)
-        self.source_dir = src.Path(self.product_info.install_dir)
+        self.install_dir = src.Path(self.product_info.install_dir)
         self.header = ""
         self.debug_mode = debug_mode
 
         if not self.source_dir.exists() and check_src:
             raise src.SatException(_("No sources found for product %(product)s in %(source_dir)s" % \
-                { "product": self.product, "source_dir": self.source_dir } ))
+                { "product": self.product_info.name, "source_dir": self.source_dir } ))
 
+        """
         # check that required modules exist
         for dep in self.product_info.depend:
             assert dep in self.config.TOOLS.src.product_info, "UNDEFINED product: %s" % dep
             dep_info = self.config.TOOLS.src.product_info[dep]
             if 'install_dir' in dep_info and not os.path.exists(dep_info.install_dir):
                 raise src.SatException(_("Module %s is required") % dep)
-
+        """
         self.results = CompilationResult()
 
     ##
@@ -132,7 +133,7 @@ class Builder:
     ##
     # Logs a compilation step (configure, make ...)
     def log_step(self, step):
-        if self.config.USER.output_level == 3:
+        if self.config.USER.output_verbose_level == 3:
             self.logger.write("\r%s%s" % (self.header, " " * 20), 3)
             self.logger.write("\r%s%s" % (self.header, step), 3)
         self.log("==== %s \n" % src.printcolors.printcInfo(step), 4)
@@ -170,7 +171,7 @@ class Builder:
 
         # create build environment
         self.build_environ = src.environment.SalomeEnviron(self.config, src.environment.Environ(dict(os.environ)), True)
-        self.build_environ.silent = (self.config.USER.output_level < 5)
+        self.build_environ.silent = (self.config.USER.output_verbose_level < 5)
         self.build_environ.set_full_environ(self.logger, environ_info)
 
         # create runtime environment
@@ -196,31 +197,17 @@ class Builder:
         if not self.build_dir.exists():
             # create build dir
             self.build_dir.make()
-        elif self.options.clean_all:
-            self.log('  %s\n' % src.printcolors.printcWarning("CLEAN ALL"), 4)
-            # clean build dir if clean_all option given
-            self.log('  clean previous build = %s\n' % str(self.build_dir), 4)
-            self.build_dir.rm()
-            self.build_dir.make()
-
-        if self.options.clean_all or self.options.clean_install:
-            if os.path.exists(str(self.install_dir)) and not self.single_dir:
-                self.log('  clean previous install = %s\n' % str(self.install_dir), 4)
-                self.install_dir.rm()
 
         self.log('  build_dir   = %s\n' % str(self.build_dir), 4)
         self.log('  install_dir = %s\n' % str(self.install_dir), 4)
         self.log('\n', 4)
 
-        # set the environment
-        environ_info = {}
-
         # add products in depend and opt_depend list recursively
-        environ_info['products'] = src.product.get_product_dependencies(self.config, self.product_info)
+        environ_info = src.product.get_product_dependencies(self.config, self.product_info)
 
         # create build environment
         self.build_environ = src.environment.SalomeEnviron(self.config, src.environment.Environ(dict(os.environ)), True)
-        self.build_environ.silent = (self.config.USER.output_level < 5)
+        self.build_environ.silent = (self.config.USER.output_verbose_level < 5)
         self.build_environ.set_full_environ(self.logger, environ_info)
 
         # create runtime environment
@@ -360,18 +347,18 @@ CC=\\"hack_libtool\\"%g" libtool'''
                         stdout=self.logger.logTxtFile,
                         stderr=subprocess.STDOUT)
 
-    def get_nb_proc(self):
+    def get_nb_proc(self, opt_nb_proc=None):
         nbproc = -1
         if "nb_proc" in self.product_info:
             # nb proc is specified in module definition
             nbproc = self.product_info.nb_proc
-            if self.options.nb_proc and self.options.nb_proc < self.product_info.nb_proc:
+            if opt_nb_proc and opt_nb_proc < self.product_info.nb_proc:
                 # use command line value only if it is lower than module definition
-                nbproc = self.options.nb_proc
+                nbproc = opt_nb_proc
         else:
             # nb proc is not specified in module definition
-            if self.options.nb_proc:
-                nbproc = self.options.nb_proc
+            if opt_nb_proc:
+                nbproc = opt_nb_proc
             else:
                 nbproc = self.config.VARS.nb_proc
         
@@ -380,8 +367,8 @@ CC=\\"hack_libtool\\"%g" libtool'''
 
     ##
     # Runs make to build the module.
-    def make(self):
-        nbproc = self.get_nb_proc()
+    def make(self, opt_nb_proc = None):
+        nbproc = self.get_nb_proc(opt_nb_proc)
 
         hh = 'MAKE -j%s' % str(nbproc)
         if self.debug_mode:
@@ -408,8 +395,8 @@ CC=\\"hack_libtool\\"%g" libtool'''
     
     ##
     # Runs msbuild to build the module.
-    def wmake(self):
-        nbproc = self.get_nb_proc()
+    def wmake(self, opt_nb_proc = None):
+        nbproc = self.get_nb_proc(opt_nb_proc)
 
         hh = 'MSBUILD /m:%s' % str(nbproc)
         if self.debug_mode:
@@ -490,24 +477,6 @@ CC=\\"hack_libtool\\"%g" libtool'''
         self.results.check = (res == 0)
         self.log_result(res)
         return self.results.check
-
-    ##
-    # Cleans the build.
-    def clean(self):
-        self.log_step('CLEAN')
-
-        if src.get_cfg_param(self.config.PRODUCT, 'clean_build_dir', 'no') == "yes":
-            if self.results.buildconfigure and self.results.configure \
-                and self.results.make and self.results.install and self.results.check:
-                self.log(_('Clean BUILD directory\n'), 4)
-                self.build_dir.rm()
-            else:
-                self.log(_('No clean: some error during compilation\n'), 5)
-        else:
-            self.log(_('No clean: not specified in the config\n'), 5)
-
-    def get_result(self):
-        return self.results
       
     ##
     # Performs a default build for this module.
index 935f957c903b1e8876baaebb94686657dbcfee66..0f1046354c6e7559af5bf6d02360751669b9efef 100644 (file)
@@ -23,32 +23,6 @@ import sys
 
 import src
 
-# create bash product file
-_bash_content = """PRODUCT_DIR=%s
-if [[ "${ENV_FOR_LAUNCH}x" == "x" ]]
-then
-    export ENV_FOR_LAUNCH=1
-fi
-
-if [[ "${ENV_FOR_LAUNCH}" == "1" ]]
-then
-    source $PRODUCT_DIR/env_launch.sh
-else
-    source $PRODUCT_DIR/env_build.sh
-fi
-"""
-
-# create batch product file
-_batch_content = """set PRODUCT_DIR=%s
-IF NOT DEFINED ENV_FOR_LAUNCH set ENV_FOR_LAUNCH=1
-
-if "%%ENV_FOR_LAUNCH%%"=="1" (
-    %%PRODUCT_DIR%%\\env_launch.bat
-) else (
-    %%PRODUCT_DIR%%\\env_build.bat
-)
-"""
-
 class Environ:
     '''Class to manage the environment context
     '''
@@ -194,6 +168,14 @@ class SalomeEnviron:
     """
 
     def __init__(self, cfg, environ, forBuild=False):
+        '''Initialization.
+
+        :param cfg Config: the global config
+        :param environ Environ: the Environ instance where 
+                                to store the environment variables
+        :param forBuild bool: If true, it is a launch environment, 
+                              else a build one
+        '''
         self.environ = environ
         self.cfg = cfg
         self.forBuild = forBuild
@@ -207,27 +189,57 @@ class SalomeEnviron:
         return self.__class__.__name__ + str(res)[0:-1] + " ...etc...}"
 
     def append(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
+        '''
         return self.environ.append(key, value, sep)
 
     def prepend(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
+        '''
         return self.environ.prepend(key, value, sep)
 
     def is_defined(self, key):
+        '''Check if the key exists in the environment
+        
+        :param key str: the environment variable to check
+        '''
         return self.environ.is_defined(key)
 
     def get(self, key):
+        '''Get the value of the environment variable "key"
+        
+        :param key str: the environment variable
+        '''
         return self.environ.get(key)
 
     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
+        '''
         # check if value needs to be evaluated
         if value is not None and value.startswith("`") and value.endswith("`"):
-            res = subprocess.Popen("echo %s" % value, shell=True, stdout=subprocess.PIPE).communicate()
+            res = subprocess.Popen("echo %s" % value,
+                                   shell=True,
+                                   stdout=subprocess.PIPE).communicate()
             value = res[0].strip()
 
         return self.environ.set(key, value)
 
     def dump(self, out):
-        """Write the environment to out"""
+        """Write the environment to out
+        
+        :param out file: the stream where to write the environment
+        """
         for k in self.environ.environ.keys():
             try:
                 value = self.get(k)
@@ -236,59 +248,64 @@ class SalomeEnviron:
             out.write("%s=%s\n" % (k, value))
 
     def add_line(self, nb_line):
+        """Add empty lines to the out stream (in case of file generation)
+        
+        :param nb_line int: the number of empty lines to add
+        """
         if 'add_line' in dir(self.environ):
             self.environ.add_line(nb_line)
 
     def add_comment(self, comment):
+        """Add a commentary to the out stream (in case of file generation)
+        
+        :param comment str: the commentary to add
+        """
         if 'add_comment' in dir(self.environ):
             self.environ.add_comment(comment)
 
     def add_warning(self, warning):
+        """Add a warning to the out stream (in case of file generation)
+        
+        :param warning str: the warning to add
+        """
         if 'add_warning' in dir(self.environ):
             self.environ.add_warning(warning)
 
     def finish(self, required):
+        """Add a final instruction in the out file (in case of file generation)
+        
+        :param required bool: Do nothing if required is False
+        """
         if 'finish' in dir(self.environ):
             self.environ.add_line(1)
             self.environ.add_comment("clean all the path")
             self.environ.finish(required)
 
-    def list_version_4_prereq(self, prerequisite, logger):
-        alist = []
-        for path in self.cfg.TOOLS.environ.prereq_install_dir:
-            if not os.path.exists(path):
-                continue
-            prereqlist = os.listdir(path)
-            for prereq in prereqlist:
-                if prereq.split("-")[0] == prerequisite:
-                    #logger.error(str(prereq) + "\n")
-                    alist.append(str(prereq))
-
-        if len(alist) > 0:
-            logger.write(_("Available prerequisites are:") + "\n\t%s\n" % '\n\t'.join(alist), 2)
-
     def set_python_libdirs(self):
-        if src.architecture.is_windows():
-            # sysconfig.get_python_lib() does not return appropriate path on Windows
-            # clearly decide here once for windows
-            ver = self.get('PYTHON_VERSION')
-            self.set('PYTHON_LIBDIR0', os.path.join('lib', 'python' + ver, 'site-packages'))
-            self.set('PYTHON_LIBDIR1', os.path.join('lib64', 'python' + ver, 'site-packages'))
-
-        else:
-            ver = self.get('PYTHON_VERSION')
-            self.set('PYTHON_LIBDIR0', os.path.join('lib', 'python' + ver, 'site-packages'))
-            self.set('PYTHON_LIBDIR1', os.path.join('lib64', 'python' + ver, 'site-packages'))
+        """Set some generic variables for python library paths
+        """
+        ver = self.get('PYTHON_VERSION')
+        self.set('PYTHON_LIBDIR0', os.path.join('lib',
+                                                'python' + ver,
+                                                'site-packages'))
+        self.set('PYTHON_LIBDIR1', os.path.join('lib64',
+                                                'python' + ver,
+                                                'site-packages'))
           
         self.python_lib0 = self.get('PYTHON_LIBDIR0')
         self.python_lib1 = self.get('PYTHON_LIBDIR1')
 
-    ##
-    # Get the products name to add in SALOME_MODULES environment variable
-    # It is the name of the product, except in the case where the is a component name.
-    # And it has to be in SALOME_MODULES variable only if has_gui = "yes"
-    def getNames(self, lProducts):
-        lProdHasGui = [p for p in lProducts if 'has_gui' in src.product.get_product_config(self.cfg, p) and src.product.get_product_config(self.cfg, p).has_gui=='yes']
+    def get_names(self, lProducts):
+        """Get the products name to add in SALOME_MODULES environment variable
+           It is the name of the product, except in the case where the is a 
+           component name. And it has to be in SALOME_MODULES variable only 
+           if has_gui = "yes"
+        
+        :param lProducts list: List of products to potentially add
+        """
+        lProdHasGui = [p for p in lProducts if 'has_gui' in 
+                    src.product.get_product_config(self.cfg, p) and 
+                    src.product.get_product_config(self.cfg, p).has_gui=='yes']
         lProdName = []
         for ProdName in lProdHasGui:
             pi = src.product.get_product_config(self.cfg, ProdName)
@@ -298,57 +315,78 @@ class SalomeEnviron:
                 lProdName.append(ProdName)
         return lProdName
 
-    ##
-    # Sets the environment defined in the PRODUCT file.
     def set_application_env(self, logger):
+        """Sets the environment defined in the APPLICATION file.
+        
+        :param logger Logger: The logger instance to display messages
+        """
+        
+        # Set the variables defined in the "environ" section
         if 'environ' in self.cfg.APPLICATION:
             self.add_comment("APPLICATION environment")
             for p in self.cfg.APPLICATION.environ:
                 self.set(p, self.cfg.APPLICATION.environ[p])
             self.add_line(1)
 
+        # If there is an "environ_script" section, load the scripts
         if 'environ_script' in self.cfg.APPLICATION:
             for pscript in self.cfg.APPLICATION.environ_script:
                 self.add_comment("script %s" % pscript)
                 sname = pscript.replace(" ", "_")
-                self.run_env_script("APPLICATION_%s" % sname, self.cfg.APPLICATION.environ_script[pscript], logger)
+                self.run_env_script("APPLICATION_%s" % sname,
+                                self.cfg.APPLICATION.environ_script[pscript],
+                                logger)
                 self.add_line(1)
         
+        # If there is profile (SALOME), then define additional variables
         if 'profile' in self.cfg.APPLICATION:
             profile_product = self.cfg.APPLICATION.profile.product
-            product_info_profile = src.product.get_product_config(self.cfg, profile_product)
-            profile_share_salome = os.path.join( product_info_profile.install_dir, "share", "salome" )
+            product_info_profile = src.product.get_product_config(self.cfg,
+                                                            profile_product)
+            profile_share_salome = os.path.join(product_info_profile.install_dir,
+                                                "share",
+                                                "salome" )
             self.set( "SUITRoot", profile_share_salome )
-            self.set( "SalomeAppConfig", os.path.join( profile_share_salome, "resources", profile_product.lower() ) )
+            self.set( "SalomeAppConfig",
+                      os.path.join(profile_share_salome,
+                                   "resources",
+                                   profile_product.lower() ) )
         
         # The list of products to launch
-        lProductsName = self.getNames(self.cfg.APPLICATION.products.keys())
+        lProductsName = self.get_names(self.cfg.APPLICATION.products.keys())
         
         self.set( "SALOME_MODULES",    ','.join(lProductsName))
 
-    ##
-    # Set xxx_ROOT_DIR and xxx_SRC_DIR.
-    def set_salome_minimal_product_env(self, product_info, logger, single_dir, cfgdic=None):
+    def set_salome_minimal_product_env(self, product_info, logger):
+        """Sets the minimal environment for a SALOME product.
+           xxx_ROOT_DIR and xxx_SRC_DIR
+        
+        :param product_info Config: The product description
+        :param logger Logger: The logger instance to display messages        
+        """
         # set root dir
         root_dir = product_info.name + "_ROOT_DIR"
-        indic = cfgdic is not None and root_dir in cfgdic
-        if not self.is_defined(root_dir) and not indic:
-            if single_dir:
-                self.set(root_dir, os.path.join(self.get('INSTALL_ROOT'), 'SALOME'))
-            elif 'install_dir' in product_info and product_info.install_dir:
+        if not self.is_defined(root_dir):
+            if 'install_dir' in product_info and product_info.install_dir:
                 self.set(root_dir, product_info.install_dir)
             elif not self.silent:
-                logger.write("  " + _("No install_dir for product %s\n") % product_info.name, 5)
+                logger.write("  " + _("No install_dir for product %s\n") %
+                              product_info.name, 5)
 
-        # set source dir, unless the product is fixed (no source dir)
+        # set source dir, unless no source dir
         if not src.product.product_is_fixed(product_info):
             src_dir = product_info.name + "_SRC_DIR"
-            indic = cfgdic is not None and src_dir in cfgdic
-            if not self.is_defined(src_dir) and not indic:
+            if not self.is_defined(src_dir):
                 self.set(src_dir, product_info.source_dir)
 
     def set_salome_generic_product_env(self, product):
+        """Sets the generic environment for a SALOME product.
+        
+        :param product str: The product name    
+        """
+        # get the product descritption
         pi = src.product.get_product_config(self.cfg, product)
+        # Construct XXX_ROOT_DIR
         env_root_dir = self.get(pi.name + "_ROOT_DIR")
         l_binpath_libpath = []
 
@@ -357,16 +395,20 @@ class SalomeEnviron:
             compo_name = pi.component_name
             if compo_name + "CPP" == product:
                 compo_root_dir = compo_name + "_ROOT_DIR"
-                envcompo_root_dir = os.path.join( self.cfg.TOOLS.common.install_root, compo_name )
+                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" ]:
+        if (src.get_cfg_param(pi, 'product_type', 'SALOME').upper() 
+                            not in [ "SALOME", "SMESH_PLUGIN", "SAMPLE" ]):
             appliname = ''
 
+        # 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) )
@@ -385,14 +427,19 @@ class SalomeEnviron:
                 ]
             self.prepend('PYTHONPATH', l)
 
-    ##
-    # Loads environment define in the configuration.
     def load_cfg_environment(self, cfg_env):
+        """Loads environment defined in cfg_env 
+        
+        :param cfg_env Config: A config containing an environment    
+        """
+        # Loop on cfg_env values
         for env_def in cfg_env:
             val = cfg_env[env_def]
+            # if it is a dict, do not do anything
             if isinstance(val, src.pyconf.Mapping):
                 continue
 
+            # if it is a list, loop on its values
             if isinstance(val, src.pyconf.Sequence):
                 # transform into list of strings
                 l_val = []
@@ -400,6 +447,7 @@ class SalomeEnviron:
                     l_val.append(item)
                 val = l_val
 
+            # "_" means that the value must be prepended
             if env_def.startswith("_"):
                 # separator exception for PV_PLUGIN_PATH
                 if env_def[1:] == 'PV_PLUGIN_PATH':
@@ -409,62 +457,73 @@ class SalomeEnviron:
             elif env_def.endswith("_"):
                 # separator exception for PV_PLUGIN_PATH
                 if env_def[:-1] == 'PV_PLUGIN_PATH':
-                    self.prepend(env_def[:-1], val, ';')
+                    self.append(env_def[:-1], val, ';')
                 else:
-                    self.prepend(env_def[:-1], val)
+                    self.append(env_def[:-1], val)
             else:
                 self.set(env_def, val)
 
-    ##
-    # Sets the environment of a product.
-    def set_a_product(self, product, logger, single_dir):
-               
+    def set_a_product(self, product, logger):
+        """Sets the environment of a product. 
+        
+        :param product str: The product name
+        :param logger Logger: The logger instance to display messages
+        """
+        
+        # Get the informations corresponding to the product
+        pi = src.product.get_product_config(self.cfg, product)
+        
+        # Do not define environment if the product is native
+        if src.product.product_is_native(pi):
+            return
+        
         if not self.silent:
             logger.write(_("Setting environment for %s\n") % product, 4)
 
         self.add_line(1)
         self.add_comment('setting environ for ' + product)
-        
-        pi = src.product.get_product_config(self.cfg, product)
-
-        # Do not define environment if the product is native or fixed
-        if src.product.product_is_native(pi):
-            return
 
+        # Put the environment define in the configuration of the product
         if "environ" in pi:
-            # set environment using definition of the product
-            self.set_salome_minimal_product_env(pi, logger, single_dir, pi.environ)
-            self.set_salome_generic_product_env(product)
             self.load_cfg_environment(pi.environ)
             if self.forBuild and "build" in pi.environ:
                 self.load_cfg_environment(pi.environ.build)
             if not self.forBuild and "launch" in pi.environ:
                 self.load_cfg_environment(pi.environ.launch)
-        else:
-            # no environment defined in config
-            self.set_salome_minimal_product_env(pi, logger, single_dir)
-            if 'install_dir' in pi :
-                self.set_salome_generic_product_env(product)
 
-        # if product_info defines a env_scripts load it
+        # Set an additional environment for SALOME products
+        if src.product.product_is_salome(pi):
+            # set environment using definition of the product
+            self.set_salome_minimal_product_env(pi, logger)
+            self.set_salome_generic_product_env(product)
+
+        # if product_info defines a env_scripts, load it
         if 'env_script' in pi:
             self.run_env_script(pi, logger)
             
 
-    ##
-    # Runs an environment script.
     def run_env_script(self, product_info, logger=None):
+        """Runs an environment script. 
+        
+        :param product_info Config: The product description
+        :param logger Logger: The logger instance to display messages
+        """
         env_script = product_info.env_script
+        # Check that the script exists
         if not os.path.exists(product_info.env_script):
-            raise src.SatException(_("Environment script not found: %s") % env_script)
+            raise src.SatException(_("Environment script not found: %s") % 
+                                   env_script)
 
         if not self.silent and logger is not None:
             logger.write("  ** load %s\n" % product_info.env_script, 4)
 
+        # import the script and run the set_env function
         try:
             import imp
-            pyproduct = imp.load_source(product_info.name + "_env_script", env_script)
-            pyproduct.set_env(self, product_info.install_dir, product_info.version)
+            pyproduct = imp.load_source(product_info.name + "_env_script",
+                                        env_script)
+            pyproduct.set_env(self, product_info.install_dir,
+                              product_info.version)
         except:
             __, exceptionValue, exceptionTraceback = sys.exc_info()
             print(exceptionValue)
@@ -472,38 +531,41 @@ class SalomeEnviron:
             traceback.print_tb(exceptionTraceback)
             traceback.print_exc()
 
-    ##
-    # Sets the environment for all the products.
-    def set_products(self, logger, src_root=None, single_dir=False):
+    def set_products(self, logger, src_root=None):
+        """Sets the environment for all the products. 
+        
+        :param logger Logger: The logger instance to display messages
+        :param src_root src: the application working directory
+        """
         self.add_line(1)
         self.add_comment('setting environ for all products')
 
         self.set_python_libdirs()
 
+        # Set the application working directory
         if src_root is None:
             src_root = self.cfg.APPLICATION.workdir
         self.set('SRC_ROOT', src_root)
 
+        # SALOME variables
         appli_name = "APPLI"
         if "APPLI" in self.cfg and "application_name" in self.cfg.APPLI:
             appli_name = self.cfg.APPLI.application_name
-        self.set("SALOME_APPLI_ROOT", os.path.join(self.cfg.APPLICATION.workdir, appli_name))
-
-        if not single_dir:
-            single_dir = src.get_cfg_param(self.cfg.APPLICATION, "compil_in_single_dir", "no") == 'yes'
-
-        for product in src.get_cfg_param(self.cfg.APPLICATION, "imported_products", []):
-            self.set_a_product(product, logger, single_dir=single_dir)
-            self.finish(False)
+        self.set("SALOME_APPLI_ROOT",
+                 os.path.join(self.cfg.APPLICATION.workdir, appli_name))
 
+        # The loop on the products
         for product in self.cfg.APPLICATION.products.keys():
-            self.set_a_product(product, logger, single_dir=single_dir)
+            self.set_a_product(product, logger)
             self.finish(False)
-
-   
-    ##
-    # Sets the full environment for prerequisites and products specified in env_info dictionary.
     def set_full_environ(self, logger, env_info):
+        """Sets the full environment for products 
+           specified in env_info dictionary. 
+        
+        :param logger Logger: The logger instance to display messages
+        :param env_info list: the list of products
+        """
         # set product environ
         self.set_application_env(logger)
 
@@ -513,77 +575,86 @@ class SalomeEnviron:
         self.set('INSTALL_ROOT', install_root)
         self.set('SRC_ROOT', source_root)
         self.set_python_libdirs()
+        
+        for product in env_info:
+            self.set_a_product(product, logger)
 
-        single_dir = src.get_cfg_param(self.cfg.APPLICATION, "compil_in_single_dir", "no") == 'yes'
-        for product in env_info['products']:
-            self.set_a_product(product, logger, single_dir=single_dir)
-
-##
-# Class to dump the environment to a file.
 class FileEnvWriter:
-    def __init__(self, config, logger, out_dir, src_root, single_dir, env_info=None):
+    """Class to dump the environment to a file.
+    """
+    def __init__(self, config, logger, out_dir, src_root, env_info=None):
+        '''Initialization.
+
+        :param cfg Config: the global config
+        :param logger Logger: The logger instance to display messages
+        :param out_dir str: The directory path where t put the output files
+        :param src_root str: The application working directory
+        :param env_info str: 
+        '''
         self.config = config
         self.logger = logger
         self.out_dir = out_dir
         self.src_root= src_root
-        self.single_dir = single_dir
         self.silent = True
         self.env_info = env_info
 
     def write_env_file(self, filename, forBuild, shell):
-        """Create an environment file."""
+        """Create an environment file.
+        
+        :param filename str: the file path
+        :param forBuild bool: if true, the build environment
+        :param shell str: the type of file wanted (.sh, .bat)
+        :return: The path to the generated file
+        :rtype: str
+        """
         if not self.silent:
-            self.logger.write(_("Create environment file %s\n") % src.printcolors.printcLabel(filename), 3)
+            self.logger.write(_("Create environment file %s\n") % 
+                              src.printcolors.printcLabel(filename), 3)
 
         # create then env object
         env_file = open(os.path.join(self.out_dir, filename), "w")
-        tmp = src.fileEnviron.get_file_environ(env_file, shell, {}, self.config )
+        tmp = src.fileEnviron.get_file_environ(env_file,
+                                               shell,
+                                               {},
+                                               self.config )
         env = SalomeEnviron(self.config, tmp, forBuild)
         env.silent = self.silent
 
+        # Set the environment
         if self.env_info is not None:
             env.set_full_environ(self.logger, self.env_info)
         else:
-            # set env from PRODUCT
+            # set env from the APPLICATION
             env.set_application_env(self.logger)
             # set the products
             env.set_products(self.logger,
-                            src_root=self.src_root, single_dir=self.single_dir)
+                            src_root=self.src_root)
 
         # add cleanup and close
         env.finish(True)
         env_file.close()
 
         return env_file.name
-
-    def write_product_file(self, filename, shell):
-        """Create a product file."""
-        if not self.silent:
-            self.logger.write(_("Create product file %s\n") % src.printcolors.printcLabel(filename), 3)
-
-        prod_file = open(os.path.join(self.out_dir, filename), "w")
-        if shell == "bash":
-            content = _bash_content % self.out_dir
-        elif shell == "batch":
-            content = _batch_content % self.out_dir
-        else:
-            raise src.SatException(_("Unknown shell: %s") % shell)
-
-        prod_file.write(content)
-        prod_file.close()
-       
-        return prod_file.name
    
-    def write_cfgForPy_file(self, aFile, additional_env = {}):
-        """append to current opened aFile a cfgForPy environment (python syntax)."""
+    def write_cfgForPy_file(self, filename, additional_env = {}):
+        """Append to current opened aFile a cfgForPy 
+           environment (SALOME python launcher).
+           
+        :param filename str: the file path
+        :param additional_env dict: a dictionary of additional variables 
+                                    to add to the environment
+        """
         if not self.silent:
-            self.logger.write(_("Create configuration file %s\n") % src.printcolors.printcLabel(aFile.name), 3)
+            self.logger.write(_("Create configuration file %s\n") % 
+                              src.printcolors.printcLabel(aFile.name), 3)
 
         # create then env object
-        tmp = src.fileEnviron.get_file_environ(aFile, "cfgForPy", {}, self.config)
-        forBuild = True
-        forLaunch = False
-        env = SalomeEnviron(self.config, tmp, forLaunch)
+        tmp = src.fileEnviron.get_file_environ(filename, 
+                                               "cfgForPy", 
+                                               {}, 
+                                               self.config)
+        # environment for launch
+        env = SalomeEnviron(self.config, tmp, forBuild=False)
         env.silent = self.silent
 
         if self.env_info is not None:
@@ -595,8 +666,9 @@ class FileEnvWriter:
             env.set_prerequisites(self.logger)
             # set the products
             env.set_products(self.logger,
-                            src_root=self.src_root, single_dir=self.single_dir)
+                            src_root=self.src_root)
 
+        # Add the additional environment if it is not empty
         if len(additional_env) != 0:
             for variable in additional_env:
                 env.set(variable, additional_env[variable])
@@ -604,16 +676,25 @@ class FileEnvWriter:
         # add cleanup and close
         env.finish(True)
 
-##
-# Definition of a Shell.
 class Shell:
+    """Definition of a Shell.
+    """
     def __init__(self, name, extension):
+        '''Initialization.
+
+        :param name str: the shell name
+        :param extension str: the shell extension
+        '''
         self.name = name
         self.extension = extension
 
-##
-# Loads the environment (used to run the tests).
 def load_environment(config, build, logger):
+    """Loads the environment (used to run the tests, for example).
+    
+    :param config Config: the global config
+    :param build bool: build environement if True
+    :param logger Logger: The logger instance to display messages
+    """
     environ = SalomeEnviron(config, Environ(os.environ), build)
     environ.set_application_env(logger)
     environ.set_products(logger)
index 8ef412536b13390d863dbfe7d528da1b1b57011c..9010123da00f3edace12f29dd67ffc848e829bec 100644 (file)
@@ -196,6 +196,20 @@ def product_is_sample(product_info):
     else:
         return False
 
+def product_is_salome(product_info):
+    '''Know if a product is of type salome
+    
+    :param product_info Config: The configuration specific to 
+                               the product
+    :return: True if the product is salome, else False
+    :rtype: boolean
+    '''
+    if 'type' in product_info:
+        ptype = product_info.type
+        return ptype.lower() == 'salome'
+    else:
+        return False
+
 def product_is_fixed(product_info):
     '''Know if a product is fixed