From de9675a0726808bb8103802876fe2dee5306e8e4 Mon Sep 17 00:00:00 2001 From: akl Date: Fri, 27 Jul 2007 13:24:43 +0000 Subject: [PATCH] Modifications in according to improvement 15165. --- runInstall | 287 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 173 insertions(+), 114 deletions(-) diff --git a/runInstall b/runInstall index 64efac4..a766b2e 100755 --- a/runInstall +++ b/runInstall @@ -361,42 +361,47 @@ class ArgParser: #------------------------------------------------------------------# #=================================================================== -# class Config : general configuration options : version, OS, etc... +# class Config : general configuration options : version, target and +# temporary directories, etc... #=================================================================== class Config : """ General configuration file options: - Install Wizard window caption - SALOME platform version - - Copyright and libcense info - - Target Linux OS version + - Copyright and license info + - Default target and temporary directories """ def __init__(self, theVersion = None, theCaption = None, theCopyright = None, theLicense = None, - theOS = None): + thePlatforms = None, + theTargetdir = None, + theTmpdir = None): self.version = strip(theVersion) self.caption = strip(theCaption) self.copyright = strip(theCopyright) self.license = strip(theLicense) - self.os = strip(theOS) - -#=================================================================== -# class Path : default target, temporary directories options -#=================================================================== -class Path : - """ - Path options: - - default target directory - - default temporary directory - """ - def __init__(self, - theTargetdir = None, - theTmpdir = None): + self.platforms = strip(thePlatforms) self.targetdir = strip(theTargetdir) self.tmpdir = strip(theTmpdir) + +## #=================================================================== +## # class Path : default target, temporary directories options +## #=================================================================== +## class Path : +## """ +## Path options: +## - default target directory +## - default temporary directory +## """ +## def __init__(self, +## theTargetdir = None, +## theTmpdir = None): +## self.targetdir = strip(theTargetdir) +## self.tmpdir = strip(theTmpdir) #============================================================== # class Product : pre-requisite product options @@ -405,6 +410,7 @@ class Product : """ Product options: - name, version + - target Linux OS version - supported installation modes and the default one - dependencies - required disk space @@ -413,6 +419,8 @@ class Product : """ def __init__(self, theName, + theType = None, + theOS = None, theVersion = None, theInstall = None, theSupportred = None, @@ -420,9 +428,10 @@ class Product : theInstalldiskspace = None, theTemporarydiskspace = None, theScript = None, - thePickUpEnvironment = None, - theContext = None): + thePickUpEnvironment = None): self.name = strip(theName) + self.type = strip(theType) + self.os = strip(theOS) self.version = strip(theVersion) self.install = strip(theInstall) self.supported = strip(theSupportred) @@ -431,7 +440,6 @@ 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): @@ -472,17 +480,31 @@ class ConfigParser(xmllib.XMLParser): xmllib.XMLParser.__init__(self) self.products = [] self.currentdata = [] - self.path = None +## self.path = None self.config = None self.is_force_src = is_force_src def handle_data(self, data): self.currentdata.append(data) + def start_config(self, attrs): + self.config = Config(attrs.get('version', None), + attrs.get('caption', None), + attrs.get('copyright', None), + attrs.get('license', None), + attrs.get('platforms', None), + attrs.get('targetdir', None), + attrs.get('tempdir', None)) + pass + + def end_config(self): + pass + def start_product(self, attrs): if not attrs.get('name', '').strip(): return if check_bool(attrs.get('disable', 'false')): return aProduct = Product(attrs.get('name'), + attrs.get('type', None), attrs.get('version', None), attrs.get('install', None), attrs.get('supported', None), @@ -490,8 +512,7 @@ class ConfigParser(xmllib.XMLParser): attrs.get('installdiskspace', None), attrs.get('temporarydiskspace', None), attrs.get('script', None), - attrs.get('pickupenv', None), - attrs.get('context', None)) + attrs.get('pickupenv', None)) if self.is_force_src: aProduct.setMode(__TAG__SOURCES__) self.products.append(aProduct) @@ -500,24 +521,29 @@ class ConfigParser(xmllib.XMLParser): def end_product(self): pass - def start_config(self, attrs): - self.config = Config(attrs.get('version', None), - attrs.get('caption', None), - attrs.get('copyright', None), - attrs.get('license', None), - attrs.get('os', None)) + def start_installation(self, attrs): +## anInstallation = Installation(attrs.get('os', None), +## attrs.get('type', None), +## attrs.get('version', None), +## attrs.get('install', None), +## attrs.get('supported', None), +## attrs.get('dependancies', None), +## attrs.get('installdiskspace', None), +## attrs.get('temporarydiskspace', None), +## attrs.get('script', None), +## attrs.get('pickupenv', None)) pass - def end_config(self): + def end_installation(self): pass - def start_path (self, attrs): - self.path = Path(attrs.get('targetdir', None), - attrs.get('tempdir', None)) - pass +## def start_path (self, attrs): +## self.path = Path(attrs.get('targetdir', None), +## attrs.get('tempdir', None)) +## pass - def end_path(self): - pass +## def end_path(self): +## pass def getProduct(self, prod): for product in self.products: @@ -525,6 +551,12 @@ class ConfigParser(xmllib.XMLParser): return product return None + def getInstallation(self, os): + for product in self.products: + if product.name == prod: + return product + return None + #------------------------------------------------------------------# # # # SERVICE FUNCTIONS # @@ -646,9 +678,6 @@ def parse_parameters(): help_str += "If this parameter is missing, then the program tries to define the " help_str += "Linux platform and use the corresponding xml file. For example, " help_str += "for Red Hat 8.0 config_RedHat_8.0.xml file is used in this case. " - help_str += "If program fails to define target Linux platform or the corresponding " - help_str += "xml file is not provided with the Installation Wizard, then default " - help_str += "config.xml file is used." opt_parser.add_option("-f", "--file", action="store", @@ -673,15 +702,6 @@ 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", @@ -706,7 +726,7 @@ def parse_parameters(): os.system(cmd) print "" sys.exit(0) - return [options.xmlfile, options.target_dir, options.tmp_dir, options.gui, options.force_sources] + return [options.xmlfile, options.target_dir, options.tmp_dir, options.gui] #================================================================= # strip : removes spaces at the beginning and at the end of the @@ -911,80 +931,98 @@ def get_tmp_dir(dir): if not os.path.exists( tmp_dir ): return tmp_dir return "%s/%s%d"%(dir, dir_prefix, random.randint(range_bottom,range_top)) - + +#============================================================== +# get_current_platform : gets name, version and bit of +# the current user's Linux platform +#=============================================================== +def get_current_platform(): + """ + Gets name, version and bit of + the current user's Linux platform. + """ + plt_name = ""; plt_ver = ""; plt_bit = "" + if os.path.exists("/etc/issue"): + data = open("/etc/issue").readline() + res = re.search(r'(.*)[L|l]inux.*release\s+([\d.]*)', data) + if not res: + # Debian identification + res = re.search(r'(.*)GNU/Linux\s+([\d.]*)', data) + if res: + plt_name = "".join(res.group(1).split()) + plt_ver = res.group(2) + if re.search(r'x86_64', data): + plt_bit = "_64" + pass + pass + pass + + return plt_name, plt_ver, plt_bit + +#============================================================== +# check_xml_file : checks XML file existence and readability +#=============================================================== +def check_xml_file(xml_file): + """ + Checks XML file existence and readability. + """ + if not os.path.isfile(xml_file): + msg = "Configuration file %s is not found!"%xml_file + error_exit(msg, False) + + if not os.access(xml_file, os.R_OK): + msg = "There is no read access for %s file!"%xml_file + error_exit(msg, False) + pass + +#============================================================== +# get_supported_plts : gets map of supported Linux platforms and +# corresponding configuration files +#=============================================================== +def get_supported_platforms(xml_file=None): + """ + Gets map of supported Linux platforms and + corresponding configuration files. + """ + platforms_map = {} + xml_file_list = list() + if xml_file: + xml_file_list = [ xml_file ] + else: + entry_list = os.listdir(get_program_path()) + for entry in entry_list: + if re.search(r'(.*).xml', entry): + xml_file_list.append(os.path.abspath(entry)) + for an_xml_file in xml_file_list: # XML files parsing + check_xml_file(an_xml_file) + filehandle = open(an_xml_file) + data = filehandle.read() + filehandle.close() + parser = ConfigParser() + parser.feed(data) + parser.close() + if parser.config.platforms is not None: + for plt in parser.config.platforms.split(","): + if not plt or plt in platforms_map.keys(): continue +## print "plt = %s, xml = %s"%(strip(plt), an_xml_file) + platforms_map[strip(plt)] = an_xml_file + return platforms_map + #------------------------------------------------------------------# # # # EXECUTION STARTS HERE # # # #------------------------------------------------------------------# - + if __name__ == "__main__": # parse command line - [xml_file, target_dir, tmp_dir, is_gui, is_force_src] = parse_parameters() + [xml_file, target_dir, tmp_dir, is_gui] = 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() - # define xml file to be used - if (xml_file is None): - plt_name = "" - plt_ver = "" - plt_bit = "" - xml_file_name = "config.xml" - if os.path.exists("/etc/fedora-release"): - # - Fedora Core 4 - plt_name = "Fedora" - data = open("/etc/fedora-release").readline() - res = re.search(r'Fedora.*release\s+([\d.]*)', data) - if res: - plt_ver = res.group(1) - elif os.path.exists("/etc/redhat-release"): - # - Red Hat Linux 8.0 - # - Red Hat Linux 9 - # - Mandrake Linux 10.1 - # - 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.]*)', data) - if res: - plt_name = "".join(res.group(1).split()) - plt_ver = res.group(2) - if re.search(r'x86_64', data): - plt_bit = "_64" - elif os.path.exists("/etc/debian_version"): - # - Debian 3.1 - plt_name = "Debian" - plt_ver = open("/etc/debian_version").readline().strip() - 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.]*)', data) - if res: - plt_name = "".join(res.group(1).split()) - plt_ver = res.group(2) - 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: - msg = "Not supported Linux platform!\n" - msg += "Trying to use default configuration file!" - warning(msg) - - xml_file = "%s/%s"%(cur_dir, xml_file_name) - - if not xml_file or not os.path.exists(xml_file): - msg = "Configuration file %s is not found!"%xml_file - error_exit(msg) - - if not os.access(xml_file, os.R_OK): - msg = "There is no read access for %s file!"%xml_file - error_exit(msg) - #---- GUI ---------------- if is_gui : @@ -997,17 +1035,38 @@ if __name__ == "__main__": env["LD_LIBRARY_PATH"] = ".:" + env["LD_LIBRARY_PATH"] env["PATH"] = ".:" + env["PATH"] - cmd = "./bin/SALOME_InstallWizard --file %s"%xml_file + cmd = "./bin/SALOME_InstallWizard" + if xml_file is not None: + cmd += " --file %s"%xml_file if target_dir is not None: 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)) #----- TUI --------------------- + + # get program dir + cur_dir = get_program_path() + + # get current Linux platform + plt_name = ""; plt_ver = ""; plt_bit = "" + plt_name, plt_ver, plt_bit = get_current_platform() + full_plt_name = plt_name + plt_ver + plt_bit + print "full_plt_name = %s" % full_plt_name + + # get supported Linux platforms + supported_plts_map = get_supported_platforms(xml_file) + # check: whether the current platform is supported + if supported_plts_map.has_key(full_plt_name): + # define xml file to be used + xml_file = supported_plts_map.get(full_plt_name, "") + print "set xml_file = %s" % os.path.basename(xml_file) + pass + else: + msg = "Not supported Linux platform!\n" + warning(msg) # parse XML file ----------- message("Parsing XML configuration file: %s"%xml_file) -- 2.39.2