Salome HOME
Fix wrong compilation of Numeric 23.7 from sources
[tools/install.git] / runInstall
index c6e5bdf8f0cad9fca3e25d78f99820d8d6e0fbd5..d5cf9148407153c8befed7a075e9c8ffe17b5b29 100755 (executable)
@@ -1,5 +1,8 @@
 #!/usr/bin/env python
 
+import warnings
+warnings.filterwarnings("ignore", "", DeprecationWarning)
+
 import xmllib
 import sys, os, string, re
 
@@ -7,12 +10,12 @@ import sys, os, string, re
 # get_help_info
 #==============================================================
 def get_help_info() :
-    str = "\nPAL/SALOME Installation Wizard\n\n"
+    str = "\nSALOME Installation Wizard\n\n"
     str = str + "\tUsage : \n\tInstall [-g|b] [-f <xml-file>] [-t <target-dir>] [-tmp <tmp-dir>]\n"
     str = str + "\n"
     str = str + " -g              Runs the Installation Wizard in the GUI mode.\n"
     str = str + "                 In this case only <xmlfile> is taken into account \n"
-    str = str + "                 from the parameters list. This key is default.\n"
+    str = str + "                 from the parameters list. This key is used by default.\n"
     str = str + "\n"
     str = str + " -b              Runs the Installation Wizard in the batch mode.\n"
     str = str + "                 All the found parameters are taken in to account.\n"
@@ -20,7 +23,7 @@ def get_help_info() :
     str = str + " -f <xml-file>   The configuration file to be parsed by the Installation Wizard.\n" 
     str = str + "                 If this parameter is missed then the script tries to define\n"
     str = str + "                 the Red Hat version and use the corresponding xml. For example,\n"
-    str = str + "                 for Red Hat 8.0 config_RedHat8_0.xml file is supposed to be used\n"
+    str = str + "                 for Red Hat 8.0 config_RedHat_8.0.xml file is supposed to be used\n"
     str = str + "                 by default. If the appropriate xml file is not found, the config.xml\n"
     str = str + "                 is used by default.\n"
     str = str + "\n"
@@ -32,9 +35,15 @@ def get_help_info() :
     str = str + "                 This parameter overloads the temporary directory described in the\n"
     str = str + "                 configuration file.\n"
     str = str + "\n"
-    str = str + " -h              Prints help information.\n" 
+    str = str + " -h              Prints this help information.\n" 
     return str
 
+#==============================================================
+# message finction
+#==============================================================
+def message(msg):
+    print ">>>", msg
+    
 #==============================================================
 # error_exit
 #==============================================================
@@ -143,6 +152,12 @@ def parse_parameters (args) :
     return [xmlfile, target_dir,  tmp_dir, is_gui]
 
 
+#=================================================================
+# Checks boolean value: yes/no, true/false, 1/0
+#=================================================================
+def check_bool(val):
+    return str(val).strip() in ["yes","true", "1"]
+
 #=================================================================
 # The first algorithm to create the dependencies list by their level
 #=================================================================
@@ -248,6 +263,24 @@ def get_dependencies_set(prods) :
 
     return deps 
     
+#=================================================================
+# The third algorithm (same as SALOME_InstallWizard.cxx uses)
+#=================================================================
+def get_dependencies(prods) :
+    list = []
+    for product in prods:
+        if check_bool(product.disable): continue
+        
+        deps = product.dependencies.split(",")
+        for dep in deps:
+            if dep and not dep in list:
+                list.append( dep )
+                
+        if product and not product in list:
+            list.append( product.name )
+            
+    return " ".join( list )
+
 #==============================================================
 # Creates dir, returns the part of path that existed early.
 # Access may be defined.
@@ -284,7 +317,8 @@ class Product :
                  theDependencies       = None,
                  theInstalldiskspace   = None,
                  theTemporarydiskspace = None,
-                 theScript             = None):
+                 theScript             = None,
+                 thePickUpEnvironment  = None):
         
 
         self.name               = theName
@@ -296,6 +330,7 @@ class Product :
         self.installdiskspace   = theInstalldiskspace
         self.temporarydiskspace = theTemporarydiskspace
         self.script             = theScript
+        self.pickupEnv          = thePickUpEnvironment
 
 #===================================================================
 # class Config
@@ -343,6 +378,9 @@ class ConfigParser(xmllib.XMLParser):
                            attrs['temporarydiskspace'],
                            attrs['script'])
 
+        if attrs.has_key( 'pickupenv' ):
+            aProduct.pickupEnv = attrs['pickupenv']
+
         self.products.append(aProduct)
 
     def end_product(self):
@@ -360,11 +398,16 @@ class ConfigParser(xmllib.XMLParser):
     def start_path (self, attrs):
         self.path = Path(attrs['targetdir'],
                          attrs['tempdir'])
-        print self.path.tmpdir
         
     def end_path(self):
         pass
 
+    def getProduct(self, prod):
+        for product in self.products:
+            if product.name == prod:
+                return product
+        return None
+
 #================================================================
 # get the path using file name
 #================================================================
@@ -383,7 +426,7 @@ def check_dir(dir):
     if (os.path.islink(dir)) :
         native_dir = os.readlink(dir)
         if not os.path.exists(native_dir) :
-            print "Bad link " + native_dir + " to directory " + native_dir + ". The last does not exist."
+            print "Invalid link " + dir + ". The directory " + native_dir + " a link points to does not exist."
             return 0 # problem
     else :
         if not os.path.exists(dir):
@@ -403,7 +446,7 @@ def check_disk_space(products, script_dir, target_dir, tmp_dir):
         product.install = re.sub(r'^\s+', "", product.install)
         product.install = re.sub(r'\s+$', "", product.install)
         
-        if product.disable == "true" or product.install == "use native":
+        if check_bool(product.disable) or product.install == "use native" or product.install == "not install":
             continue
         spaces = string.split( product.installdiskspace,',')
         prod_space = spaces[0]
@@ -423,7 +466,14 @@ def check_disk_space(products, script_dir, target_dir, tmp_dir):
     
     return 1
  
-
+#===============================================================
+# Removes temporary directory
+#===============================================================
+def remove_dir( rem_path = "" ):
+    if len( rem_path ) and os.path.exists( rem_path ):
+        os.system( "rm -rf " + rem_path )
+    pass
+    
 #================================================================
 # main
 #================================================================
@@ -436,22 +486,41 @@ if __name__ == "__main__":
 
     # define xml file -----------------
     if (xml_file is None) :
+        plt_name = ""
+        plt_ver  = ""
         xml_file_name = "config.xml"
-        if os.path.exists("/proc/version"):
-            data = open("/proc/version").readline()
-            res = re.search(r'Red\s+Hat\s+\w+(\s+)?(\d[.]\d)', data)
-            if res is not None:
-                num = re.sub("[.]", "_", (res.groups())[1])
-                filename = "config_RedHat" + num+ ".xml"
-                if (os.path.exists(cur_dir + filename)):
-                    xml_file_name = filename
-                
+        if os.path.exists("/etc/redhat-release"):
+            # - Red Hat Linux 8.0
+            # - Red Hat Linux 9
+            # - Mandrake Linux 10.1
+            # - Scientific Linux 3.0.5
+            data = open("/etc/redhat-release").readline()
+           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)
+        elif os.path.exists("/etc/debian_version"):
+            # - Debian 3.1
+            plt_name = "Debian"
+            plt_ver = open("/etc/debian_version").readline().strip()
+        _xml_file_name = "config_%s_%s.xml"%(plt_name, plt_ver)
+        if plt_name and plt_ver and os.path.exists(cur_dir + _xml_file_name):
+            xml_file_name = _xml_file_name
+        else:
+            print ""
+            print "Not supported Linux platform!"
+            print "Trying to use default configuration!"
+            print ""
+
         xml_file = cur_dir +  xml_file_name
-    if xml_file is None or not os.path.exists(xml_file):
-        error_exit("No xml file is found try to run with options -f <xmlfile>")
+
+    if not xml_file or not os.path.exists(xml_file):
+        msg  = "Configuration file %s is not found!"%xml_file
+        msg += "\nTry to run with -f <xmlfile> option."
+        error_exit(msg)
 
     if not os.access(xml_file, os.R_OK):
-        print "There is no acceess to read "+ xml_file
+        print "There is no read access for %s file!"%xml_file
         sys.exit(1)
 
     #---- GUI ----------------
@@ -472,7 +541,8 @@ if __name__ == "__main__":
     #-----  TUI ---------------------
 
     #print xml_file, target_dir, tmp_dir, is_gui
-    
+
+    message("Parsing xml config file: " + xml_file)
     filehandle = open(xml_file)
     data = filehandle.read()
     filehandle.close()
@@ -482,23 +552,25 @@ if __name__ == "__main__":
 
     # definitions :
     # map
-    what_to_do = { "install sources":"install_source",
-                   "install binaries":"install_binary",
-                   "use native":"try_native"}
+    what_to_do = { "install sources"  : "install_source",
+                   "install binaries" : "install_binary",
+                   "use native"       : "try_native",
+                   "not install"      : "try_preinstalled"}
     # define tmp dir  -----------
     if tmp_dir is None:
         tmp_dir = parser.path.tmpdir
+    if tmp_dir is None or tmp_dir == "":
+        tmp_dir = "/tmp"
+    import random
+    tmp_dir = tmp_dir + "/INSTALLWORK" + str(random.randint(10000,100000))
     root_path = ""
     if not os.path.exists(tmp_dir):
-        print "Creating " + tmp_dir; root_path = create_dir(tmp_dir) ; 
-        import random
-        tmp_dir = tmp_dir + "/INSTALLWORK" + str(random.randint(10000,100000))
-        create_dir(tmp_dir,0755)
-        if not os.path.exists(tmp_dir):
-            error_exit("There is no tmp directory " + tmp_dir + ". Use -tmp key to set directory or correct xml file\n\n")
+        message("Creating temporary directory: " + tmp_dir); root_path = create_dir(tmp_dir, 0755) ; 
+    if not os.path.exists(tmp_dir):
+        error_exit("Invalid temporary directory " + tmp_dir + ". Use -tmp key to set directory or correct xml file\n\n")
 
     if not os.access(tmp_dir, os.W_OK) :
-        str = "We have no write permissions for directory " + tmp_dir + ". Use -tmp key to set directory or correct xml file"
+        str = "There is no write permissions for directory " + tmp_dir + ". Use -tmp key to set temporary directory or correct xml file"
         error_exit(str)
         
     # define target dir  --------
@@ -506,44 +578,47 @@ if __name__ == "__main__":
         target_dir = parser.path.targetdir
 
     if not os.path.exists(target_dir):
-        print "Creating " + target_dir; create_dir(target_dir, 0755)
-        if not os.path.exists(target_dir):
-            error_exit("There is no target directory " + target_dir + ". Use -t key to set directory or correct xml file\n\n")
+        message("Creating target directory: " + target_dir); create_dir(target_dir, 0755)
+    if not os.path.exists(target_dir):
+        error_exit("Invalid target directory " + target_dir + ". Use -t key to set directory or correct xml file\n\n")
 
     if not os.access(target_dir, os.W_OK) :
-        str = "We have no write permissions for directory " + target_dir + ". Use -t key to set directory or correct xml file"
+        str = "There is no write permissions for directory " + target_dir + ". Use -t key to set target directory or correct xml file."
         error_exit(str)
-    
 
     # define products dir ------------
     source_dir =  cur_dir + "Products" ; 
     if not check_dir(source_dir):
-        if len(root_path) and os.path.exists(root_path):
-            os.system("rm -r -f "+ root_path)
+        remove_dir(root_path)
         sys.exit(1)
        
     subdir = {"install sources"  : "SOURCES",
               "install binaries" : "BINARIES/"+parser.config.os,
-              "use native": ""}
+              "use native"       : "",
+              "not install"      : ""}
 
 
     #  define scripts dir ------------
     scripts_dir = cur_dir + "config_files/"
     if not check_dir(scripts_dir):
-        if len(root_path) and os.path.exists(root_path):
-            os.system("rm -r -f "+ root_path)
+        remove_dir(root_path)
         sys.exit(1)
     os.chdir(scripts_dir)
 
-    list_of_dep =  create_levels(parser.products)
+    #list_of_dep =  create_levels(parser.products)
     #list_of_dep =  get_dependencies_set(parser.products)
+    list_of_dep =  get_dependencies(parser.products)
 
+    message("Checking available disk space")
     if check_disk_space(parser.products, scripts_dir, target_dir, tmp_dir) :
+
+        message("Starting...")
+        # install products
         for product in parser.products :
 
-            if product.disable == "true": continue
+            if check_bool(product.disable): continue
 
+            message("Processing " + product.name + "...")
             cmd = scripts_dir +  product.script + " " + \
                   what_to_do[product.install]+ " " + \
                   tmp_dir + " " + \
@@ -553,7 +628,25 @@ if __name__ == "__main__":
                   product.name
 
             res = os.system(cmd)
-            if res : break;
+            #if res : break; # try_preinstalled can return 1
+
+        # pickup environment
+        message("Creating environment files")
+        for product in parser.products :
+
+            if check_bool(product.disable): continue
+
+            if check_bool(product.pickupEnv):
+                cmd = scripts_dir +  product.script + " " + \
+                      "pickup_env " + \
+                      tmp_dir + " " + \
+                      source_dir + "/" + subdir[product.install] + " " + \
+                      target_dir + " " + \
+                      '"' + list_of_dep + '"' + " " + \
+                      product.name
+                
+                res = os.system(cmd)
 
-    if len(root_path) and os.path.exists(root_path):
-        os.system("rm -r -f "+ root_path)
+    message("Cleaning temporary directory")
+    remove_dir(root_path)
+    message("Finished!")