__version__ = "1.1.5"
+# --- imports --- #
+import sys
+try:
+ import xml.sax, xml.dom.minidom
+ import os, re
+ import types
+ import random
+ import warnings
+except Exception, an_exc:
+ sys.exit("Error: %s! Please check the installed Python package." % str(an_exc))
+ pass
+
# --- avoid "deprecation" warnings --- #
-import warnings
warnings.filterwarnings("ignore", "", DeprecationWarning)
-# --- imports --- #
-import xml.sax, xml.dom.minidom
-import sys, os, re
-import types
-import random
-
# --- global variables --- #
opt_parser = None
root_path = None
theCaption = None,
theCopyright = None,
theLicense = None,
- thePlatforms = None,
- theTargetdir = None,
- theTmpdir = None):
+ theTargetdir = None):
self.version = strip(theVersion)
self.caption = strip(theCaption)
self.copyright = strip(theCopyright)
self.license = strip(theLicense)
- self.platforms = strip(thePlatforms)
self.targetdir = strip(theTargetdir)
- self.tmpdir = strip(theTmpdir)
#==============================================================
# class Product : pre-requisite product options
def __init__(self,
theName,
theType = None,
- theOS = None,
theVersion = None,
theDependencies = None,
- theWoGuiInstallation = None,
theInstalldiskspace = None,
theScript = None,
thePickUpEnvironment = None):
self.name = strip(theName)
self.type = strip(theType)
- self.os = strip(theOS)
self.version = strip(theVersion)
self.dependencies = strip(theDependencies)
- self.woguiinst = strip(theWoGuiInstallation)
self.installdiskspace = strip(theInstalldiskspace)
self.script = strip(theScript)
self.pickupEnv = strip(thePickUpEnvironment)
- self.whattodo = __BINARIES__
+ self.whattodo = __BUILDSRC__
def setMode(self, mode):
if mode not in [__BINARIES__, __BUILDSRC__, __PREINSTALL__]:
"""
XML configuration files parser
"""
- def __init__(self, is_force_src=False):
+ def __init__(self):
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 = None
pass
def parse_config(self):
configElem.getAttribute('caption').strip(),
configElem.getAttribute('copyright').strip(),
configElem.getAttribute('license').strip(),
- configElem.getAttribute('platforms').strip(),
- configElem.getAttribute('targetdir').strip(),
- configElem.getAttribute('tempdir').strip())
+ configElem.getAttribute('targetdir').strip())
pass
def parse_dependencies(self):
# Parse 'dependencies' part of the XML file
depsMap = {}
+ if not len(self.docElem.getElementsByTagName('dependencies')):
+ return depsMap;
depsElem = self.docElem.getElementsByTagName('dependencies')[0]
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(),
- instElem.getAttribute('os').strip(),
instElem.getAttribute('version').strip(),
depsList,
- instElem.getAttribute('woguimode').strip(),
instElem.getAttribute('installdiskspace').strip(),
- instElem.getAttribute('script').strip(),
- instElem.getAttribute('pickupenv').strip())
- if self.is_force_src:
- aProduct.setMode(__BUILDSRC__)
- pass
+ instElem.getAttribute('script').strip())
if prodElem.getAttribute('type').strip() == "component":
sal_prods_list.append(aProduct)
# fill an ordered modules list -----------
req_prods_list.append(aProduct)
# fill an ordered prerequisites list -----------
prereqs_list.append(prodName)
- #AKL: prerequisite sources and temp files are removed, by default.
- # So, there is no need to make sources environment
- #if aProduct.whattodo == __BUILDSRC__: prereqs_list.append(prodName + "_src")
pass
pass
self.products.extend( req_prods_list )
self.products.extend( sal_prods_list )
- if len(self.products) != 0:
- gcc_product = Product("gcc",
- __CTX__PREREQUISITE__,
- self.products[0].os,
- "",
- list(),
- None,
- "0,0,0",
- "gcc-common.sh",
- "")
- gcc_product.setMode(__PREINSTALL__)
- self.products.insert(0, gcc_product)
- prereqs_list.insert(0, gcc_product.name)
- pass
self.full_prods_list.extend( prereqs_list )
self.full_prods_list.extend( modules_list )
pass
dest="gui",
help=help_str)
help_str = "The configuration xml file.\n"
- 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 this parameter is missing, then the default 'config.xml'"
+ help_str += "configuration file will be used."
opt_parser.add_option("-f",
"--file",
action="store",
dest="target_dir",
metavar="DIR",
help=help_str)
- help_str = "The directory to be used for temporary files.\n"
- help_str += "When used this parameter overrides the default temporary directory "
- help_str += "defined in the configuration xml file."
- opt_parser.add_option("-t",
- "--tmp",
- action="store",
- dest="tmp_dir",
- metavar="DIR",
- help=help_str)
- help_str = "Force all products to be installed from sources \n"
- help_str += "including SALOME modules.\n"
- 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 = "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, options.single_dir]
+ return [options.xmlfile, options.target_dir, options.gui]
#=================================================================
# 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:
# check_disk_space : checks the disk space;
# quits if there is no enough disk space
#===============================================================
-def check_disk_space(products, scripts_dir, target_dir, tmp_dir, is_force_src=False):
+def check_disk_space(products, scripts_dir, target_dir):
"""
Checks if there is enough disk space to install products.
Quits with error if there is no enough disk space.
f = open(filename)
lines = f.readlines()
f.close()
- # ---
- regvar = re.compile("(.*)\s+[^\s]*[R|r]elease[^\s]*\s+([\d.]*)")
+ # --- = 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())
+ 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__":
+ # get program dir
+ cur_dir = get_program_path()
# parse command line
- [xml_file, target_dir, tmp_dir, is_gui, is_force_src, is_single_dir] = parse_parameters()
+ [xml_file, target_dir, is_gui] = parse_parameters()
if xml_file: xml_file = os.path.abspath(xml_file)
+ else: xml_file = os.path.join(cur_dir, "config.xml")
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()
#---- GUI ----------------
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"
- 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)
- pass
-
- xml_file= "%s/%s"%(cur_dir, xml_file_name)
- pass
-
+ #
+ # check XML file
check_xml_file(xml_file)
-
# parse XML file -----------
message("Parsing XML configuration file: %s"%xml_file)
- parser = ConfigParser(is_force_src)
+ parser = ConfigParser()
parser.parse(xml_file)
# source directory map
- bin_dir = ""
- if parser.config.platforms:
- bin_dir += "/%s"%parser.config.platforms
- subdir = { __BINARIES__ : "BINARIES" + bin_dir,
- __BUILDSRC__ : "SOURCES",
- __PREINSTALL__ : ""}
+ subdir = { __BUILDSRC__ : "SOURCES" }
# check scripts directory -----------
scripts_dir = "%s/%s"%(cur_dir, "config_files")
if not os.access(target_dir, os.W_OK) :
error_exit("There is no write permissions for the directory: " + target_dir)
- # check/create temporary dir -----------
- if tmp_dir is None:
- tmp_dir = parser.config.tmpdir
- if not tmp_dir:
- tmp_dir = "/tmp"
- tmp_dir = substituteVars(tmp_dir)
- tmp_dir = get_tmp_dir(tmp_dir)
-
- 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)
-
- if not os.access(tmp_dir, os.W_OK) :
- error_exit("There is no write permissions for the directory: " + tmp_dir)
-
# check available disk space -----------
message("Checking available disk space")
- check_disk_space(parser.products, scripts_dir, target_dir, tmp_dir, is_force_src)
+ check_disk_space(parser.products, scripts_dir, target_dir)
# change current directory -----------
os.chdir(scripts_dir)
# get dependencies list -----------
- list_of_dep = get_dependencies(parser.products)
products_string = " ".join(parser.full_prods_list)
# don't remove sources and tmp files, by default -----------
# install products -----------
for product in parser.products:
- # remove only prerequisites temporary files
- if product.type == __CTX__PREREQUISITE__ or \
- (product.type == __CTX__COMPONENT__ and product.whattodo == __BUILDSRC__):
- rm_src_tmp = "TRUE"
message("... processing %s ..."%product.name)
- cmd = '%s/%s %s %s %s/%s %s "%s" %s "%s" %s/%s %s %s/%s' % (
+ cmd = '%s/%s %s %s/%s %s "%s" %s "%s" %s/%s' % (
scripts_dir, product.script,
product.whattodo,
- tmp_dir,
source_dir, subdir[product.whattodo],
target_dir,
products_string,
product.name,
products_string,
source_dir, subdir[__BUILDSRC__],
- rm_src_tmp,
- source_dir, subdir[__BINARIES__]
)
- # 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 :
- if check_bool(product.pickupEnv):
- cmd = '%s/%s pickup_env %s %s/%s %s "%s" %s "%s" %s/%s %s %s/%s' % (
- scripts_dir, product.script,
- tmp_dir,
- source_dir, subdir[product.whattodo],
- target_dir,
- products_string,
- product.name,
- products_string,
- source_dir, subdir[__BUILDSRC__],
- rm_src_tmp,
- source_dir, subdir[__BINARIES__]
- )
- # 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
-
- # clean temporary directory -----------
- message("Cleaning temporary directory")
- clean_all()
-
# finishing -----------
message("Finished!")
pass