4 warnings.filterwarnings("ignore", "", DeprecationWarning)
7 import sys, os, string, re
8 from optparse import OptionParser
13 __TAG__SOURCES__ = "install sources"
14 __TAG__BINARIES__ = "install binaries"
15 __TAG__NATIVE__ = "use native"
16 __TAG__PREINSTALL__ = "not install"
18 #==============================================================
20 #==============================================================
28 theDependencies = None,
29 theInstalldiskspace = None,
30 theTemporarydiskspace = None,
32 thePickUpEnvironment = None):
33 self.name = strip(theName)
34 self.version = strip(theVersion)
35 self.install = strip(theInstall)
36 self.supported = strip(theSupportred)
37 self.dependencies = strip(theDependencies)
38 self.installdiskspace = strip(theInstalldiskspace)
39 self.temporarydiskspace = strip(theTemporarydiskspace)
40 self.script = strip(theScript)
41 self.pickupEnv = strip(thePickUpEnvironment)
43 #===================================================================
45 #===================================================================
53 self.version = strip(theVersion)
54 self.caption = strip(theCaption)
55 self.copyright = strip(theCopyright)
56 self.license = strip(theLicense)
57 self.os = strip(theOS)
59 #===================================================================
61 #===================================================================
66 self.targetdir = strip(theTargetdir)
67 self.tmpdir = strip(theTmpdir)
69 #===================================================================
71 #===================================================================
72 class ConfigParser(xmllib.XMLParser):
74 xmllib.XMLParser.__init__(self)
80 def handle_data(self, data):
81 self.currentdata.append(data)
83 def start_product(self, attrs):
84 if not attrs.get('name', '').strip(): return
85 if check_bool(attrs.get('disable', 'false')): return
86 aProduct = Product(attrs.get('name'),
87 attrs.get('version', None),
88 attrs.get('install', None),
89 attrs.get('supported', None),
90 attrs.get('dependancies', None),
91 attrs.get('installdiskspace', None),
92 attrs.get('temporarydiskspace', None),
93 attrs.get('script', None),
94 attrs.get('pickupenv', None))
95 self.products.append(aProduct)
98 def end_product(self):
101 def start_config(self, attrs):
102 self.config = Config(attrs.get('version', None),
103 attrs.get('caption', None),
104 attrs.get('copyright', None),
105 attrs.get('license', None),
106 attrs.get('os', None))
109 def end_config(self):
112 def start_path (self, attrs):
113 self.path = Path(attrs.get('targetdir', None),
114 attrs.get('tempdir', None))
120 def getProduct(self, prod):
121 for product in self.products:
122 if product.name == prod:
126 #==============================================================
127 # message: prints diagnostic information
128 #==============================================================
134 #==============================================================
135 # warning: prints warning
136 #==============================================================
144 #==============================================================
145 # error_exit : prints (optionally) error string, then prints
146 # help information and quits
147 #==============================================================
148 def error_exit(msg = "", print_help = True):
149 # print error message
154 # print help information
158 opt_parser.print_help()
166 #==============================================================
167 # clean_all : performs system cleaning before exiting
168 #==============================================================
171 remove_dir(root_path)
174 #==============================================================
175 # parse_parameters : parses command line arguments
176 #==============================================================
177 def parse_parameters():
179 opt_parser = OptionParser(add_help_option=False)
180 help_str = "Runs the Installation Wizard in the GUI mode [default].\n"
181 help_str += "In this case only -f option is taken into account. "
182 help_str += "Other options are ignored."
183 opt_parser.add_option("-g",
189 help_str = "Runs the Installation Wizard in the TUI mode."
190 opt_parser.add_option("-b",
192 action="store_false",
195 help_str = "The configuration xml file.\n"
196 help_str += "If this parameter is missing, then the program tries to define the "
197 help_str += "Linux platform and use the corresponding xml file. For example, "
198 help_str += "for Red Hat 8.0 config_RedHat_8.0.xml file is used in this case."
199 help_str += "If program fails to define target Linux platform or the corresponding "
200 help_str += "xml file is not provided with the Installation Wizard, then default "
201 help_str += "config.xml file is used."
202 opt_parser.add_option("-f",
208 help_str = "The target directory the products to be installed to.\n"
209 help_str += "When used this parameter overrides the default target directory "
210 help_str += "defined in the configuration xml file."
211 opt_parser.add_option("-d",
217 help_str = "The directory used for temporary files.\n"
218 help_str += "When used this parameter overrides the default temporary directory "
219 help_str += "defined in the configuration xml file."
220 opt_parser.add_option("-t",
226 help_str = "Prints this help and quits."
227 opt_parser.add_option("-v",
231 help_str = "Prints version information and quits."
232 opt_parser.add_option("-h",
236 (options, args) = opt_parser.parse_args()
238 # print help info and quit
239 print "\nSALOME Installation Wizard\n"
240 opt_parser.print_help()
244 # print version info and quit
246 cmd = "./bin/SALOME_InstallWizard --version"
250 return [options.xmlfile, options.target_dir, options.tmp_dir, options.gui]
252 #=================================================================
253 # strip : removes spaces at the beginning and at eh end of the
254 # <param> if it is of string type
255 #=================================================================
258 if type(param) == types.StringType:
262 #=================================================================
263 # check_bool : checks boolean value: yes/no, true/false, 1/0
264 #=================================================================
266 if str(val).lower().strip() in ["yes","true", "1"]:
268 if str(val).lower().strip() in ["no","false", "0"]:
277 #=================================================================
278 # get_dependencies : extract products dependencies
279 #=================================================================
280 def get_dependencies(prods):
282 for product in prods:
283 deps = product.dependencies.split(",")
285 if dep and not dep in list:
288 if product and not product in list:
289 list.append( product.name )
291 return " ".join( list )
293 #==============================================================
294 # create_dir : creates a directory with (optional) permissions,
295 # returns the part of path that existed before
296 # directory creation; exits with error if access
298 #==============================================================
299 def create_dir(directory, access = 0777):
301 dirs = string.split(directory, "/")
306 if len(subdir) == 0: continue
307 dir = "%s/%s"%(dir, subdir)
308 if os.path.exists(dir):
312 os.mkdir(dir, access)
314 error_exit("Can't create directory: %s.\nAccess is denied."%directory)
315 if dir == "%s/%s"%(existing, subdir):
319 #==============================================================
320 # substituteVars : performes environment variables substistution
321 # the given string; if varibale is not defined
322 # it is substituted by the empty string
323 #==============================================================
324 def substituteVars(str):
325 str = os.path.expanduser(str)
326 str = os.path.expandvars(str)
329 #================================================================
330 # get_program_path : gets program's directory path
331 # (and performs 'cd' command there)
332 #================================================================
333 def get_program_path():
334 path = os.path.dirname(sys.argv[0])
339 #================================================================
340 # check_dir : checks directory existence
341 #================================================================
343 if (os.path.islink(dir)):
344 realpath = os.path.realpath(dir)
345 if not os.path.exists(realpath):
346 msg = "Invalid link %s.\nThe directory %s a link points to does not exist."%(dir,realpath)
347 error_exit(msg, False)
349 if not os.path.exists(dir):
350 msg = "Directory %s does not exist."%dir
351 error_exit(msg, False)
354 #===============================================================
355 # check_disk_space : checks the disk space;
356 # quits if there is no enough disk space
357 #===============================================================
358 def check_disk_space(products, scripts_dir, target_dir, tmp_dir):
361 for product in products:
362 if product.install in [__TAG__NATIVE__, __TAG__PREINSTALL__]:
364 spaces = string.split(product.installdiskspace, ',')
365 prod_space = spaces[0]
366 if (len(spaces) > 1 ) and (product.install == __TAG__SOURCES__):
367 prod_space = spaces[1]
368 install_space = install_space + string.atoi(prod_space)
369 if product.install == __TAG__SOURCES__:
370 temporary_space = max(temporary_space, string.atoi(product.temporarydiskspace))
372 res = os.system("%s/%s %s %d"%(scripts_dir, "checkSize.sh", target_dir, install_space))
374 msg = "There is no enough space to install the products."
375 error_exit(msg, False)
377 res = os.system("%s/%s %s %d"%(scripts_dir, "checkSize.sh", tmp_dir, temporary_space))
379 msg = "There is no enough space for temporary directory."
380 error_exit(msg, False)
383 #===============================================================
384 # remove_dir : removes temporary directory
385 #===============================================================
386 def remove_dir(path):
387 if path and os.path.exists(path):
388 os.system("rm -rf " + path)
391 #==============================================================
392 # has_binaries : returns True if some product is installed from
394 #===============================================================
395 def has_binaries(products):
396 for product in products:
397 if product.install == __TAG__BINARIES__:
401 #==============================================================
402 # has_sources : returns True if some product is installed from
404 #===============================================================
405 def has_sources(products):
406 for product in products:
407 if product.install == __TAG__SOURCES__:
411 #================================================================
413 #================================================================
415 if __name__ == "__main__":
417 cur_dir = get_program_path()
419 [xml_file, target_dir, tmp_dir, is_gui] = parse_parameters()
421 # define xml file to be used
422 if (xml_file is None):
425 xml_file_name = "config.xml"
426 if os.path.exists("/etc/redhat-release"):
427 # - Red Hat Linux 8.0
429 # - Mandrake Linux 10.1
430 # - Scientific Linux 3.0.5
431 data = open("/etc/redhat-release").readline()
432 res = re.search(r'(.*)[L|l]inux.*release\s+([\d.]*)', data)
434 plt_name = "".join(res.group(1).split())
435 plt_ver = res.group(2)
436 elif os.path.exists("/etc/debian_version"):
439 plt_ver = open("/etc/debian_version").readline().strip()
440 _xml_file_name = "config_%s_%s.xml"%(plt_name, plt_ver)
441 if plt_name and plt_ver and os.path.exists("%s/%s"%(cur_dir, _xml_file_name)):
442 xml_file_name = _xml_file_name
444 msg = "Not supported Linux platform!\n"
445 msg += "Trying to use default configuration file!"
448 xml_file = "%s/%s"%(cur_dir, xml_file_name)
450 if not xml_file or not os.path.exists(xml_file):
451 msg = "Configuration file %s is not found!"%xml_file
454 if not os.access(xml_file, os.R_OK):
455 msg = "There is no read access for %s file!"%xml_file
458 #---- GUI ----------------
462 if not env.has_key("PATH") :
464 if not env.has_key("LD_LIBRARY_PATH") :
465 env["LD_LIBRARY_PATH"] = ""
467 env["LD_LIBRARY_PATH"] = ".:" + env["LD_LIBRARY_PATH"]
468 env["PATH"] = ".:" + env["PATH"]
470 cmd = "./bin/SALOME_InstallWizard %s &"%xml_file
471 sys.exit(os.system(cmd))
473 #----- TUI ---------------------
475 # parse XML file -----------
476 message("Parsing XML configuration file: %s"%xml_file)
477 filehandle = open(xml_file)
478 data = filehandle.read()
480 parser = ConfigParser()
485 what_to_do = { __TAG__SOURCES__ : "install_source",
486 __TAG__BINARIES__ : "install_binary",
487 __TAG__NATIVE__ : "try_native",
488 __TAG__PREINSTALL__ : "try_preinstalled"}
489 # source directory map
492 bin_dir += "/%s"%parser.config.os
493 subdir = { __TAG__SOURCES__ : "SOURCES",
494 __TAG__BINARIES__ : "BINARIES" + bin_dir,
495 __TAG__NATIVE__ : "",
496 __TAG__PREINSTALL__ : ""}
498 # check scripts directory -----------
499 scripts_dir = "%s/%s"%(cur_dir, "config_files")
500 check_dir(scripts_dir)
502 # check products archives directories -----------
503 has_bin = has_binaries(parser.products)
504 has_src = has_sources(parser.products)
505 source_dir = "%s/%s"%(cur_dir, "Products")
507 if has_src or has_bin:
508 check_dir(source_dir)
511 check_dir("%s/%s"%(source_dir,subdir[__TAG__SOURCES__]))
514 check_dir("%s/%s"%(source_dir,subdir[__TAG__BINARIES__]))
516 # check/create target dir -----------
517 if target_dir is None:
518 target_dir = parser.path.targetdir
519 target_dir = substituteVars(target_dir)
521 message("Creating target directory: " + target_dir)
522 create_dir(target_dir, 0755)
524 if not os.path.exists(target_dir):
525 error_exit("Invalid target directory: " + target_dir)
527 if not os.access(target_dir, os.W_OK) :
528 error_exit("There is no write permissions for the directory: " + target_dir)
530 # check/create temporary dir -----------
532 tmp_dir = parser.path.tmpdir
535 tmp_dir = substituteVars(tmp_dir)
537 tmp_dir = "%s/INSTALLWORK%d"%(tmp_dir, random.randint(10000,100000))
539 message("Creating temporary directory: " + tmp_dir)
540 root_path = create_dir(tmp_dir, 0755)
542 if not os.path.exists(tmp_dir):
543 error_exit("Invalid temporary directory: " + tmp_dir)
545 if not os.access(tmp_dir, os.W_OK) :
546 error_exit("There is no write permissions for the directory: " + tmp_dir)
548 # check available disk space
549 message("Checking available disk space")
550 check_disk_space(parser.products, scripts_dir, target_dir, tmp_dir)
552 # change current directory
553 os.chdir(scripts_dir)
555 # get dependencies list
556 list_of_dep = get_dependencies(parser.products)
559 message("Starting ...")
562 for product in parser.products:
563 message("... processing %s ..."%product.name)
564 cmd = '%s/%s %s %s %s/%s %s "%s" %s'%(scripts_dir,
566 what_to_do[product.install],
569 subdir[product.install],
576 message("Creating environment files")
577 for product in parser.products :
578 if check_bool(product.pickupEnv):
579 cmd = '%s/%s pickup_env %s %s/%s %s "%s" %s'%(scripts_dir,
583 subdir[product.install],
589 # clean temporary directory
590 message("Cleaning temporary directory")