"""
-__version__ = "1.1.4"
+__version__ = "1.1.5"
# --- avoid "deprecation" warnings --- #
import warnings
"""
XML configuration files parser
"""
- def __init__(self, is_force_src=False):
+ def __init__(self, is_force_src=False, pltname=None):
self.docElem = None
- self.products = list()
- self.full_prods_list = list()
+ self.products = []
+ self.full_prods_list = []
self.config = None
self.is_force_src = is_force_src
+ self.pltname = pltname
pass
def parse_config(self):
configElem.getAttribute('platforms').strip(),
configElem.getAttribute('targetdir').strip(),
configElem.getAttribute('tempdir').strip())
+ if not self.pltname and self.config.platforms:
+ self.pltname = self.config.platforms.split(",")[0].strip()
pass
def parse_dependencies(self):
for prodElem in depsElem.getElementsByTagName('product'):
prodName = prodElem.getAttribute('name').strip()
if not prodName: continue
- depsList = list()
+ depsList = []
for depElem in prodElem.getElementsByTagName('dep'):
depsList.append(depElem.firstChild.data)
pass
# Parse 'products' part of the XML file
depsMap = self.parse_dependencies()
prodsElem = self.docElem.getElementsByTagName('products')[0]
- sal_prods_list = list(); req_prods_list = list()
- modules_list = list(); prereqs_list = list()
+ sal_prods_list = []; req_prods_list = []
+ modules_list = []; prereqs_list = []
for prodElem in prodsElem.getElementsByTagName('product'):
prodName = prodElem.getAttribute('name').strip()
if not prodName: continue
- instElem = prodElem.getElementsByTagName('installation')[0]
+ instElems = prodElem.getElementsByTagName('installation')
+ instElem = None
+ for node in instElems:
+ if not self.pltname or self.pltname == node.getAttribute('os').strip():
+ instElem = node
+ break
+ pass
+ if not instElem: continue
if check_bool(str(instElem.getAttribute('disable').strip())): continue
- depsList = list()
+ depsList = []
if prodName in depsMap: depsList = depsMap[prodName]
aProduct = Product(prodName,
prodElem.getAttribute('type').strip(),
__CTX__PREREQUISITE__,
self.products[0].os,
"",
- list(),
+ [],
None,
"0,0,0",
"gcc-common.sh",
dest="xmlfile",
metavar="FILE",
help=help_str)
+ help_str = "The platform specification.\n"
+ help_str += "This option can be used in conjunction with --file option in order"
+ help_str += "to specify Linux platform name when XML file contains installation"
+ help_str += "options for several platforms."
+ opt_parser.add_option("-p",
+ "--platform",
+ action="store",
+ dest="platform",
+ metavar="PLT",
+ help=help_str)
help_str = "The target directory the products to be installed to.\n"
help_str += "When used this parameter overrides the default target directory "
help_str += "defined in the configuration xml file."
dest="force_sources",
default=False,
help=help_str)
+ help_str = "Install all SALOME binaries packages to one directory.\n"
+ help_str += "This option is ignored when --all-from-sources (-a) option is used."
+ opt_parser.add_option("-s",
+ "--single-directory",
+ action="store_true",
+ dest="single_dir",
+ default=False,
+ help=help_str)
help_str = "Prints version information and quits."
opt_parser.add_option("-v",
"--version",
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, options.force_sources, options.single_dir, options.platform]
#=================================================================
# strip : removes spaces at the beginning and at the end of the
"""
Gets a list of installed and required products.
"""
- prods_list = list()
+ prods_list = []
for product in prods:
for dep in product.dependencies:
if dep and dep not in prods_list:
if not res:
res = re.search(regvar1, l)
if res:
- plt_name = "".join("".join(res.groups()[:len(res.groups())-1]).split())
+ 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("Welcometo", "").strip()
+ 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 = "64"
+ plt_arch = "64bit"
pass
# workaround for Red Hat Enterprise
if not plt_arch:
try:
import platform
if platform.machine() == "x86_64":
- plt_arch = "64"
+ plt_arch = "64bit"
pass
pass
except:
corresponding configuration files.
"""
platforms_map = {}
- xml_file_list = list()
if xml_file:
- xml_file_list = [ xml_file ]
+ xml_file_list = [xml_file]
+ pass
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))
+ 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)
- filehandle = open(an_xml_file)
- data = filehandle.read()
- filehandle.close()
parser = ConfigParser()
- parser.feed(data)
- parser.close()
+ 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
-## print "plt = %s, xml = %s"%(strip(plt), an_xml_file)
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]
+
#------------------------------------------------------------------#
# #
# 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, is_force_src, is_single_dir, pltname] = 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)
cmd = "./bin/SALOME_InstallWizard"
if xml_file is not None:
cmd += " --file %s"%xml_file
+ if pltname is not None:
+ cmd += " --platform %s"%pltname
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"
+ if is_single_dir:
+ cmd += " --single-directory"
cmd += "&"
sys.exit(os.system(cmd))
#----- TUI ---------------------
-
+ #
# define xml file to be used
- if not xml_file:
- # get current Linux platform
- plt_name = ""; plt_ver = ""; plt_arch = ""
- plt_name, plt_ver, plt_arch = get_os_release()
- data = []
- for i in plt_name, plt_ver, plt_arch:
- if i: data.append(i)
- full_plt_name = "_".join(data)
- xml_file_name = "config_%s.xml" % full_plt_name
- if not plt_name or not plt_ver or not os.path.exists("%s/%s"%(cur_dir, xml_file_name)):
- msg = "Not supported Linux platform: %s!" % full_plt_name
- error_exit(msg)
+ #
+ # get current Linux platform
+ plt_name, plt_ver, plt_arch = get_os_release()
+ data = []
+ for i in plt_name, plt_ver, plt_arch:
+ if i: data.append(i)
+ full_plt_name = " ".join(data)
+ # get all supported platforms
+ all_platforms = get_supported_platforms(xml_file)
+ if all_platforms:
+ if pltname:
+ # platform name is specified in the command line
+ if pltname in all_platforms:
+ # if specified platform is supported, choose the corresponding XML file for use
+ xml_file = all_platforms[pltname]
+ else:
+ # if specified platform is NOT supported, print warning message
+ # and prompt user to choose another platform
+ msg = "Specified platform is not supported: %s" % (pltname)
+ warning(msg)
+ pltname, xml_file = select_platform(all_platforms)
+ pass
+ pass
+ elif full_plt_name in all_platforms:
+ # if current platform is supported, choose the corresponding XML file for use
+ pltname = full_plt_name
+ xml_file = all_platforms[pltname]
+ else:
+ if xml_file and len(all_platforms) == 1:
+ # XML file is specified and contains only one platform definition
+ xml_file = all_platforms.values()[0]
+ pltname = all_platforms.keys()[0]
+ else:
+ # current Linux platform is not supported, print warning message
+ # and prompt user to choose platform from the list
+ warning("Not supported Linux platform: %s."%" ".join(data))
+ pltname, xml_file = select_platform(all_platforms)
pass
-
- xml_file= "%s/%s"%(cur_dir, xml_file_name)
+ pass
+ else:
+ # current Linux platform is not supported, exit
+ if pltname:
+ msg = "Not supported Linux platform: %s."%pltname
+ else:
+ msg = "Not supported Linux platform: %s."%" ".join(data)
+ error_exit(msg, False)
pass
- check_xml_file(xml_file)
-
# parse XML file -----------
message("Parsing XML configuration file: %s"%xml_file)
- parser = ConfigParser(is_force_src)
+ parser = ConfigParser(is_force_src, pltname)
parser.parse(xml_file)
# source directory map
bin_dir = ""
if parser.config.platforms:
- bin_dir += "/%s"%parser.config.platforms
+ bin_dir += "/%s"%"_".join( parser.pltname.split() )
subdir = { __BINARIES__ : "BINARIES" + bin_dir,
__BUILDSRC__ : "SOURCES",
__PREINSTALL__ : ""}
rm_src_tmp,
source_dir, subdir[__BINARIES__]
)
- if product.woguiinst is not None and product.woguiinst != "": cmd += ' TRUE'
+ # install all modules with GUI
+ if product.woguiinst is not None and product.woguiinst != "":
+ cmd += ' TRUE'
+ # use single directory or not
+ if product.whattodo == __BINARIES__ and product.type == __CTX__COMPONENT__ and is_single_dir:
+ cmd += ' TRUE'
res = os.system(cmd)
rm_src_tmp = "FALSE"
pass
+ # modify *.la files, if --single-directory option was -----------
+ if is_single_dir:
+ message("Modifying of *.la files of SALOME modules...")
+ cmd = '%s/modifyLaFiles.sh modify_la_files %s' % (scripts_dir, target_dir)
+ res = os.system(cmd)
+
# pickup environment -----------
message("Creating environment files")
for product in parser.products :
rm_src_tmp,
source_dir, subdir[__BINARIES__]
)
- if product.woguiinst is not None and product.woguiinst != "": cmd += ' TRUE'
+ # install all modules with GUI
+ if product.woguiinst is not None and product.woguiinst != "":
+ cmd += ' TRUE'
+ # use single directory or not
+ if product.whattodo == __BINARIES__ and product.type == __CTX__COMPONENT__ and is_single_dir:
+ cmd += ' TRUE'
res = os.system(cmd)
pass
pass