Salome HOME
Implement features:
[tools/install.git] / runInstall
index 3c287bcc1dc7e3f9b7a80d7834359958b11898ad..a902de3feb9451f3fdcf84dccc2e67106b56f4fc 100755 (executable)
@@ -2,6 +2,12 @@
 
 """
 Installation Wizard launching script.
+
+This script is the part of the SALOME installation procedure.
+Author    : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
+Created   : Thu Dec 18 12:01:00 2002
+Copyright : 2002-2006 CEA
+
 """
 
 __version__ = "1.0.1"
@@ -12,7 +18,7 @@ warnings.filterwarnings("ignore", "", DeprecationWarning)
 
 # --- imports --- #
 import xmllib
-import sys, os, string, re
+import sys, os, re
 import types
 import random
 
@@ -25,6 +31,12 @@ __TAG__SOURCES__    = "install sources"
 __TAG__BINARIES__   = "install binaries"
 __TAG__NATIVE__     = "use native"
 __TAG__PREINSTALL__ = "not install"
+__TAG__BUILDSRC__   = "build sources"
+
+# --- product context definition --- #
+__CTX__SALOME__SRC__  = "salome sources"
+__CTX__SALOME__BIN__  = "salome binaries"
+__CTX__PREREQUISITE__ = "prerequisite"
 
 #------------------------------------------------------------------#
 #                                                                  #
@@ -408,7 +420,8 @@ class Product :
                  theInstalldiskspace   = None,
                  theTemporarydiskspace = None,
                  theScript             = None,
-                 thePickUpEnvironment  = None):
+                 thePickUpEnvironment  = None,
+                 theContext            = None):
         self.name               = strip(theName)
         self.version            = strip(theVersion)
         self.install            = strip(theInstall)
@@ -418,7 +431,36 @@ class Product :
         self.temporarydiskspace = strip(theTemporarydiskspace)
         self.script             = strip(theScript)
         self.pickupEnv          = strip(thePickUpEnvironment)
+        self.context            = strip(theContext)
+        self.whattodo           = self.install
+        
+    def hasContext(self, ctx):
+        try:
+            return ctx in [ strip(s) for s in self.context.split(",") ]
+        except:
+            pass
+        return False
 
+    def setMode(self, mode):
+        if mode not in [__TAG__SOURCES__, __TAG__BINARIES__, __TAG__NATIVE__, __TAG__PREINSTALL__]:
+            return
+        try:
+            supported = [ strip(s) for s in self.supported.split(",") ]
+            if mode in supported or mode == __TAG__PREINSTALL__:
+                self.install = mode
+                self.whattodo = self.install
+            salbin = self.hasContext(__CTX__SALOME__BIN__)
+            salsrc = self.hasContext(__CTX__SALOME__SRC__)
+            if mode == __TAG__SOURCES__:
+                if salbin and not salsrc:
+                    self.install = __TAG__PREINSTALL__
+                    self.whattodo = self.install
+                elif salsrc:
+                    self.whattodo = __TAG__BUILDSRC__
+        except:
+            pass
+        return
+        
 #===================================================================
 # class ConfigParser : XML files parser implementation
 #===================================================================
@@ -426,12 +468,13 @@ class ConfigParser(xmllib.XMLParser):
     """
     XML configuration files parser
     """
-    def __init__(self):
+    def __init__(self, is_force_src=False):
         xmllib.XMLParser.__init__(self)
         self.products = []
         self.currentdata = []
         self.path = None
         self.config = None
+        self.is_force_src = is_force_src
         
     def handle_data(self, data):
         self.currentdata.append(data)
@@ -447,7 +490,10 @@ class ConfigParser(xmllib.XMLParser):
                            attrs.get('installdiskspace',   None),
                            attrs.get('temporarydiskspace', None),
                            attrs.get('script',             None),
-                           attrs.get('pickupenv',          None))
+                           attrs.get('pickupenv',          None),
+                           attrs.get('context',            None))
+        if self.is_force_src:
+            aProduct.setMode(__TAG__SOURCES__)
         self.products.append(aProduct)
         pass
 
@@ -627,6 +673,15 @@ def parse_parameters():
                           dest="tmp_dir",
                           metavar="DIR",
                           help=help_str)
+    help_str  = "Force all products to be installed from sources\n"
+    help_str += "including SALOME modules."
+    help_str += "If this option is used all the default installation modes are ignored."
+    opt_parser.add_option("-a",
+                          "--all-from-sources",
+                          action="store_true",
+                          dest="force_sources",
+                          default=False,
+                          help=help_str)
     help_str  = "Prints version information and quits."
     opt_parser.add_option("-v",
                           "--version",
@@ -651,7 +706,7 @@ def parse_parameters():
         os.system(cmd)
         print ""
         sys.exit(0)
-    return [options.xmlfile, options.target_dir, options.tmp_dir, options.gui]
+    return [options.xmlfile, options.target_dir, options.tmp_dir, options.gui, options.force_sources]
 
 #=================================================================
 # strip : removes spaces at the beginning and at the end of the 
@@ -698,7 +753,7 @@ def create_dir(directory, access = 0777):
     directory creation; exits with error if access
     is denied.
     """
-    dirs = string.split(directory, "/")
+    dirs = directory.split("/")
     existing = "";
     dir = ""
     root = ""
@@ -765,7 +820,7 @@ def check_dir(dir):
 # check_disk_space : checks the disk space;
 #                    quits if there is no enough disk space
 #===============================================================
-def check_disk_space(products, scripts_dir, target_dir, tmp_dir):
+def check_disk_space(products, scripts_dir, target_dir, tmp_dir, is_force_src=False):
     """
     Checks if there is enough disk space to install products.
     Quits with error if there is no enough disk space.
@@ -775,13 +830,23 @@ def check_disk_space(products, scripts_dir, target_dir, tmp_dir):
     for product in products:
         if product.install in [__TAG__NATIVE__, __TAG__PREINSTALL__]:
             continue
-        spaces = string.split(product.installdiskspace, ',')
-        prod_space = spaces[0]
-        if (len(spaces) > 1 ) and (product.install == __TAG__SOURCES__):
-            prod_space = spaces[1]
-        install_space = install_space + string.atoi(prod_space)
+        prod_space = 0
+        try:
+            spaces = product.installdiskspace.split(',')
+            prod_space = int( spaces[0] )
+            if len( spaces ) > 1 and product.install == __TAG__SOURCES__ and not is_force_src:
+                prod_space = int( spaces[1] )
+        except:
+            pass
+        install_space = install_space + prod_space
         if product.install == __TAG__SOURCES__:
-            temporary_space = max(temporary_space, string.atoi(product.temporarydiskspace))
+            tmp_space = 0
+            try:
+                tmp_space = int( product.temporarydiskspace )
+            except:
+                pass
+            temporary_space = max( temporary_space, tmp_space )
+        pass
 
     res = os.system("%s/%s %s %d"%(scripts_dir, "checkSize.sh", target_dir, install_space))
     if res:
@@ -854,10 +919,13 @@ def get_tmp_dir(dir):
 #------------------------------------------------------------------#
     
 if __name__ == "__main__":
+    # parse command line
+    [xml_file, target_dir, tmp_dir, is_gui, is_force_src] = parse_parameters()
+    if xml_file:   xml_file   = os.path.abspath(xml_file)
+    if target_dir: target_dir = os.path.abspath(target_dir)
+    if tmp_dir:    tmp_dir    = os.path.abspath(tmp_dir)
     # get program dir
     cur_dir = get_program_path()
-    # parse command line
-    [xml_file, target_dir, tmp_dir, is_gui] = parse_parameters()
 
     # define xml file to be used
     if (xml_file is None):
@@ -872,12 +940,12 @@ if __name__ == "__main__":
             # - Scientific Linux 3.0.5
            # - Mandriva 2006.0 32bit/64bit
             data = open("/etc/redhat-release").readline()
-           res = re.search(r'(.*)[L|l]inux.*release\s+([\d.]*).*\s+(\S+)', data)
+           res = re.search(r'(.*)[L|l]inux.*release\s+([\d.]*)', data)
            if res:
                 plt_name = "".join(res.group(1).split())
                 plt_ver  = res.group(2)
-                if plt_name != "RedHat":
-                    plt_bit  = res.group(3)
+               if re.search(r'x86_64', data):
+                    plt_bit  = "_64"
         elif os.path.exists("/etc/debian_version"):
             # - Debian 3.1
             plt_name = "Debian"
@@ -885,20 +953,14 @@ if __name__ == "__main__":
         elif os.path.exists("/etc/mandriva-release"):
             # - Mandriva 2006 (an additional check if above check fails)
             data = open("/etc/mandriva-release").readline()
-           res = re.search(r'(.*)[L|l]inux.*release\s+([\d.]*).*for\s+(\S+)', data)
+           res = re.search(r'(.*)[L|l]inux.*release\s+([\d.]*)', data)
            if res:
                 plt_name = "".join(res.group(1).split())
                 plt_ver  = res.group(2)
-                plt_bit  = res.group(3)
-       if plt_bit == "x86_64":
-               plt_bit = "_64"
-               _xml_file_name = "config_Mandriva_2006.0_64.xml"
-               msg = "%s"%_xml_file_name
-               warning(msg)
-       else:
-               _xml_file_name = "config_%s_%s.xml"%(plt_name, plt_ver)
-               msg = "%s"%_xml_file_name
-               warning(msg)    
+               if re.search(r'x86_64', data):
+                    plt_bit  = "_64"
+                pass
+        _xml_file_name = "config_%s_%s%s.xml"%(plt_name, plt_ver, plt_bit)
         if plt_name and plt_ver and os.path.exists("%s/%s"%(cur_dir, _xml_file_name)):
             xml_file_name = _xml_file_name
         else:
@@ -933,6 +995,8 @@ if __name__ == "__main__":
             cmd += " --target %s"%target_dir
         if tmp_dir is not None:
             cmd += " --tmp %s"%tmp_dir
+        if is_force_src:
+            cmd += " --all-from-sources"
         cmd += "&"
         sys.exit(os.system(cmd))
 
@@ -943,7 +1007,7 @@ if __name__ == "__main__":
     filehandle = open(xml_file)
     data = filehandle.read()
     filehandle.close()
-    parser = ConfigParser()
+    parser = ConfigParser(is_force_src)
     parser.feed(data)
     parser.close()
 
@@ -951,7 +1015,8 @@ if __name__ == "__main__":
     what_to_do = { __TAG__SOURCES__    : "install_source",
                    __TAG__BINARIES__   : "install_binary",
                    __TAG__NATIVE__     : "try_native",
-                   __TAG__PREINSTALL__ : "try_preinstalled"}
+                   __TAG__PREINSTALL__ : "try_preinstalled",
+                   __TAG__BUILDSRC__   : "install_source_and_build"}
     # source directory map
     bin_dir = ""
     if parser.config.os:
@@ -1012,7 +1077,7 @@ if __name__ == "__main__":
         
     # check available disk space -----------
     message("Checking available disk space")
-    check_disk_space(parser.products, scripts_dir, target_dir, tmp_dir)
+    check_disk_space(parser.products, scripts_dir, target_dir, tmp_dir, is_force_src)
 
     # change current directory -----------
     os.chdir(scripts_dir)
@@ -1028,7 +1093,7 @@ if __name__ == "__main__":
         message("... processing %s ..."%product.name)
         cmd = '%s/%s %s %s %s/%s %s "%s" %s'%(scripts_dir,
                                               product.script,
-                                              what_to_do[product.install],
+                                              what_to_do[product.whattodo],
                                               tmp_dir,
                                               source_dir,
                                               subdir[product.install],