+
+#==============================================================
+# 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
+