+#------------------------------------------------------------------#
+# #
+# SERVICE FUNCTIONS #
+# #
+#------------------------------------------------------------------#
+
+#==============================================================
+# message: prints diagnostic information
+#==============================================================
+def message(msg):
+ """
+ Prints diagnostic information.
+ """
+ if msg.strip():
+ print ">>>", msg
+ pass
+
+#==============================================================
+# warning: prints warning
+#==============================================================
+def warning(msg):
+ """
+ Prints warning.
+ """
+ if msg.strip():
+ print ""
+ print msg
+ print ""
+ pass
+
+#==============================================================
+# error_exit : prints (optionally) error string, then prints
+# help information and quits
+#==============================================================
+def error_exit(msg = "", print_help = True):
+ """
+ Prints (optionally) error string,
+ then prints help information and quits.
+ """
+ # print error message
+ if len(msg.strip()):
+ print ""
+ print msg
+ print ""
+ # print help information
+ if print_help:
+ global opt_parser
+ if opt_parser:
+ opt_parser.print_help()
+ print ""
+ # cleaning
+ clean_all()
+ # quit
+ sys.exit(1);
+ pass
+
+#==============================================================
+# boolean : Converts string to boolean value.
+#==============================================================
+def boolean(val):
+ """
+ Converts string to boolean value if possible.
+ Raises exception if wrong string is used.
+ """
+ if isinstance(val, types.StringType):
+ if val.strip().lower() in ["true", "yes", "ok"] : return True
+ elif val.strip().lower() in ["false", "no", "cancel"] : return False
+ else: raise TypeError("invalid boolean value")
+ return bool(val)
+
+#=================================================================
+# check_bool : checks boolean value: yes/no, true/false, 1/0
+#=================================================================
+def check_bool(val):
+ """
+ Checks boolean value.
+ """
+ try:
+ return boolean(val)
+ except:
+ pass
+ return False
+
+#==============================================================
+# clean_all : performs system cleaning before exiting
+#==============================================================
+def clean_all():
+ """
+ Performs system cleaning before exiting.
+ """
+ global root_path
+ remove_dir(root_path)
+ pass
+
+#==============================================================
+# parse_parameters : parses command line arguments
+#==============================================================
+def parse_parameters():
+ """
+ Parses command line arguments.
+ """
+ global opt_parser
+ opt_parser = ArgParser()
+
+ help_str = "Runs the Installation Wizard in the GUI mode [default].\n"
+ opt_parser.add_option("-g",
+ "--gui",
+ action="store_true",
+ dest="gui",
+ default=True,
+ help=help_str)
+ help_str = "Runs the Installation Wizard in the TUI mode."
+ opt_parser.add_option("-b",
+ "--batch",
+ action="store_false",
+ 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 program fails to define target Linux platform or the corresponding "
+ help_str += "xml file is not provided with the Installation Wizard, then default "
+ help_str += "config.xml file is used."
+ opt_parser.add_option("-f",
+ "--file",
+ action="store",
+ dest="xmlfile",
+ metavar="FILE",
+ 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."
+ opt_parser.add_option("-d",
+ "--target",
+ 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."
+ 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 = "Prints version information and quits."
+ opt_parser.add_option("-v",
+ "--version",
+ action="store_true",
+ help=help_str)
+ help_str = "Prints this help and quits."
+ opt_parser.add_option("-h",
+ "--help",
+ action="store_true",
+ help=help_str)
+ (options, args) = opt_parser.parse_args()
+ if options.help:
+ # print help info and quit
+ print "\nSALOME Installation Wizard\n"
+ opt_parser.print_help()
+ print ""
+ sys.exit(0)
+ if options.version:
+ # print version info and quit
+ print ""
+ cmd = "./bin/SALOME_InstallWizard --version"
+ os.system(cmd)
+ print ""
+ sys.exit(0)
+ return [options.xmlfile, options.target_dir, options.tmp_dir, options.gui, options.force_sources]
+
+#=================================================================
+# strip : removes spaces at the beginning and at the end of the
+# <param> if it is of string type
+#=================================================================
+def strip(param):
+ """
+ Removes spaces at the beginning and at the end
+ of the given parameter.
+ """
+ if type(param) == types.StringType:
+ return param.strip()
+ return param
+
+#=================================================================
+# get_dependencies : extract products dependencies
+#=================================================================
+def get_dependencies(prods):
+ """
+ Gets full list of pre-requisite products.
+ """
+ list = []
+ for product in prods:
+ deps = product.dependencies.split(",")
+ for dep in deps:
+ if dep and not dep in list:
+ list.append( dep )
+
+ if product and not product in list:
+ list.append( product.name )
+
+ return " ".join( list )
+
+#==============================================================
+# create_dir : creates a directory with (optional) permissions,
+# returns the part of path that existed before
+# directory creation; exits with error if access
+# is denied
+#==============================================================
+def create_dir(directory, access = 0777):
+ """
+ Creates a directory with (optional) permissions,
+ returns the part of path that existed before
+ directory creation; exits with error if access
+ is denied.
+ """
+ dirs = directory.split("/")
+ existing = "";
+ dir = ""
+ root = ""
+ for subdir in dirs:
+ if len(subdir) == 0: continue
+ dir = "%s/%s"%(dir, subdir)
+ if os.path.exists(dir):
+ existing = dir
+ else:
+ try:
+ os.mkdir(dir, access)
+ except:
+ error_exit("Can't create directory: %s.\nAccess is denied."%directory)
+ if dir == "%s/%s"%(existing, subdir):
+ root = dir
+ return root
+
+#==============================================================
+# substituteVars : performes environment variables substistution
+# the given string; if varibale is not defined
+# it is substituted by the empty string
+#==============================================================
+def substituteVars(str):
+ """
+ Performes environment variables substistution.
+ """
+ str = os.path.expanduser(str)
+ str = os.path.expandvars(str)
+ return str
+