+
+#==============================================================
+# get_os_release : gets OS release; the OS name, version and
+# architecture
+# For example:
+# RedHat, 8.0; Mandriva, 2006.0, 64
+#===============================================================
+def get_os_release():
+ filename = "/etc/issue"
+ # ---
+ plt_name = "unknown"
+ plt_ver = ""
+ plt_arch = ""
+ if os.path.exists(filename):
+ # ---
+ f = open(filename)
+ lines = f.readlines()
+ f.close()
+ # ---
+ regvar = re.compile("(.*)\s+[^\s]*[R|r]elease[^\s]*\s+([\d.]*)")
+ regvar1 = re.compile("(.*)\s+[^\s]*[L|l][I|i][N|n][U|u][X|x][^\s]*(.*)\s+([\d.]*)\s+")
+ for l in lines:
+ res = re.search(regvar, l)
+ if not res:
+ res = re.search(regvar1, l)
+ if res:
+ plt_name = " ".join(" ".join(res.groups()[:len(res.groups())-1]).split())
+ # workaround for Mandrake and other platforms
+ plt_name = plt_name.replace("Linux", "").replace("linux", "").replace("LINUX", "").strip()
+ # workaround for SuSe
+ plt_name = plt_name.replace("Welcome to", "").strip()
+ # ---
+ plt_name = " ".join(plt_name.split())
+ plt_ver = res.group(len(res.groups()))
+ if re.search(r'x86_64', l):
+ plt_arch = "64bit"
+ pass
+ # workaround for Red Hat Enterprise
+ if not plt_arch:
+ try:
+ import platform
+ if platform.machine() == "x86_64":
+ plt_arch = "64bit"
+ pass
+ pass
+ except:
+ pass
+ pass
+ break
+ pass
+ pass
+
+ return plt_name, plt_ver, plt_arch
+
+#==============================================================
+# 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 = {}
+ if xml_file:
+ xml_file_list = [xml_file]
+ pass
+ else:
+ xml_file_list = filter(lambda i: i.endswith(".xml"), os.listdir(get_program_path()))
+ while 'config.xml' in xml_file_list: xml_file_list.remove('config.xml')
+ if os.path.exists(os.path.join(get_program_path(), 'config.xml')):
+ xml_file_list.append('config.xml')
+ xml_file_list = [os.path.abspath(i) for i in xml_file_list]
+ pass
+ for an_xml_file in xml_file_list: # XML files parsing
+ check_xml_file(an_xml_file)
+ parser = ConfigParser()
+ parser.parse(an_xml_file)
+ if parser.config.platforms is not None:
+ for plt in parser.config.platforms.split(","):
+ if not plt or plt in platforms_map.keys(): continue
+ platforms_map[strip(plt)] = an_xml_file
+ pass
+ pass
+ pass
+ return platforms_map
+
+#==============================================================
+# Print menu with list of supported platform
+# and return user choice
+#===============================================================
+def select_platform(all_platforms):
+ platforms = all_platforms.keys()
+ platforms.sort()
+ pltname = None
+ while not pltname:
+ print "Please, select any platform from the list below."
+ print "--------------------------"
+ for idx in range(len(platforms)):
+ print " %2d. %s" % (idx+1, " ".join(platforms[idx].split("_")))
+ print " 0. Exit"
+ print "--------------------------"
+ print "Type your choice (%d-%d) and press <Enter>:" % (0, len(platforms)),
+ try:
+ idx = raw_input()
+ except:
+ sys.exit(1)
+ try:
+ idx = int(idx)
+ except:
+ warning("Invalid input!")
+ pass
+ if idx == 0: sys.exit(0)
+ if idx > 0 and idx <= len(platforms):
+ pltname = platforms[idx-1]
+ else:
+ warning("Invalid input!")
+ pass
+ return pltname, all_platforms[pltname]
+
+#==============================================================
+# Check existence of required libraries in system and
+# warn user if some ones are absent
+#===============================================================
+def check_not_found_libs(filepath, optlibs):
+ a_file = open(filepath, 'r')
+ nf_mand_libs = list()
+ nf_opt_libs = list()
+ pref_opt_libs = optlibs.split(",")
+ for line in a_file:
+ line = line.strip()
+ if not line:
+ continue
+ line = line.split(" ")[0]
+ if line in nf_mand_libs or line in nf_opt_libs:
+ continue
+ is_optional = False;
+ for opt_lib in pref_opt_libs:
+ if line.lower().startswith(opt_lib.lower().strip()):
+ is_optional = True
+ break
+ if is_optional:
+ nf_opt_libs.append(line)
+ else:
+ nf_mand_libs.append(line)
+ pass
+
+ msg = "=== WARNING: Some libraries are absent! ===\n"
+ if nf_mand_libs:
+ msg += "One or several MANDATORY libraries listed below are not found. SALOME may not work properly.\n\t"
+ msg += "\n\t".join(nf_mand_libs)
+ msg += "\n"
+ if nf_opt_libs:
+ msg += "One or several OPTIONAL libraries listed below are not found. This does not affect on the correct work of SALOME platform.\n\t"
+ msg += "\n\t".join(nf_opt_libs)
+ if nf_mand_libs or nf_opt_libs:
+ print msg
+ a_file.close()
+ pass
+