X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FfileEnviron.py;h=d2dffd2f954623e2cc0295e9c9cc9b1117284c37;hb=7a30e0dd5c2855e93ce92f1197bcb07a4ae4414c;hp=dbf0938545537fbe2e056f8434032a343a34c19e;hpb=56c74d69fd4fd80a99154c700eed7db01a8a387d;p=tools%2Fsat.git diff --git a/src/fileEnviron.py b/src/fileEnviron.py index dbf0938..d2dffd2 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -489,11 +489,6 @@ class LauncherFileEnviron(FileEnviron): if not self.environ.is_defined("PATH"): self.environ.set("PATH","") - if self.init_path: - self.output.write('\n'+self.indent) - self.add_echo("Modifier cette variable pour ne pas réinitialiser les PATHS") - self.output.write(self.indent+'reinitialise_paths=True\n\n') - def add_echo(self, text): """Add a comment @@ -550,7 +545,7 @@ class LauncherFileEnviron(FileEnviron): (self.specialKeys[key], self.value_filter(value))) else: # else we use the general salomeContext addToVariable function - self.output.write(self.indent+'appendPath(r"%s", r"%s",separator="%s")\n' + self.output.write(self.begin+'appendVariable(r"%s", r"%s",separator="%s")\n' % (key, self.value_filter(value), sep)) def append(self, key, value, sep=":"): @@ -749,9 +744,10 @@ then # check that the user is not using another shell echo echo "Warning! SALOME environment not initialized" - echo "You must run this script in a bash shell." + echo "You must run this script in a BASH shell." echo "As you are using another shell. Please first run: bash" echo + exit 1 fi ########################################################################## # @@ -820,15 +816,40 @@ def main(args): if args == ['--help']: from salomeContext import usage - usage() + appended_opt_doc = \""" +--keep-paths +============ + With this option the environment variables PATH, PYTHONPATH and LD_LIBRARY_PATH defined into the starting shell are kept. + Without this option all values set before starting SALOME are simply ignored. +\""" + usage(appended_opt_doc=appended_opt_doc) sys.exit(0) + reinitialise_paths=True + if '--keep-paths' in args: + reinitialise_paths=False + args.remove('--keep-paths') + # Create a SalomeContext which parses configFileNames to initialize environment try: from salomeContext import SalomeContext, SalomeContextException + if 'appendVariable' not in dir(SalomeContext): + # check whether the appendVariable method is implemented + def appendVariable(self, name, value, separator=os.pathsep): + if value == '': + return + value = os.path.expandvars(value) # expand environment variables + env = os.getenv(name, None) + if env is None: + os.environ[name] = value + else: + os.environ[name] = env + separator + value + return + SalomeContext.appendVariable = appendVariable + context = SalomeContext(None) - + # Here set specific variables, if needed # context.addToPath('mypath') # context.addToLdLibraryPath('myldlibrarypath') @@ -892,11 +913,22 @@ def main(args): # Identify application path then locate configuration files __initialize() - if args == ['--help']: + if '--help' in args: from salomeContext import usage - usage() + appended_opt_doc = \""" +--keep-paths +============ + With this option the environment variables PATH, PYTHONPATH and LD_LIBRARY_PATH defined into the starting shell are kept. + Without this option all values set before starting SALOME are simply ignored. +\""" + usage(appended_opt_doc=appended_opt_doc) sys.exit(0) + reinitialise_paths=True + if '--keep-paths' in args: + reinitialise_paths=False + args.remove('--keep-paths') + #from salomeContextUtils import getConfigFileNames #configFileNames, args, unexisting = getConfigFileNames( args, checkExistence=True ) #if len(unexisting) > 0: @@ -906,8 +938,21 @@ def main(args): # Create a SalomeContext which parses configFileNames to initialize environment try: from salomeContext import SalomeContext, SalomeContextException + if 'appendVariable' not in dir(SalomeContext): + # check whether the appendVariable method is implemented + def appendVariable(self, name, value, separator=os.pathsep): + if value == '': + return + value = os.path.expandvars(value) # expand environment variables + env = os.getenv(name, None) + if env is None: + os.environ[name] = value + else: + os.environ[name] = env + separator + value + return + SalomeContext.appendVariable = appendVariable + context = SalomeContext(None) - # Here set specific variables, if needed # context.addToPath('mypath') # context.addToLdLibraryPath('myldlibrarypath') @@ -952,19 +997,6 @@ launcher_tail_py2="""\ import logging logging.getLogger("salome").error(e) sys.exit(1) -# -# salomeContext only prepend variables, we use our own appendPath when required -def appendPath(name, value, separator=os.pathsep): - if value == '': - return - - value = os.path.expandvars(value) # expand environment variables - env = os.getenv(name, None) - if env is None: - os.environ[name] = value - else: - os.environ[name] = env + separator + value - if __name__ == "__main__": args = sys.argv[1:] @@ -980,7 +1012,8 @@ launcher_tail_py3="""\ extradir=out_dir_Path + r"/extra.env.d" if os.path.exists(extradir): - import imp + import importlib + import importlib.util sys.path.insert(0, os.path.join(os.getcwd(), extradir)) for filename in sorted( filter(lambda x: os.path.isfile(os.path.join(extradir, x)), @@ -989,10 +1022,10 @@ launcher_tail_py3="""\ if filename.endswith(".py"): f = os.path.join(extradir, filename) module_name = os.path.splitext(os.path.basename(f))[0] - fp, path, desc = imp.find_module(module_name) - module = imp.load_module(module_name, fp, path, desc) - module.init(context, out_dir_Path) - + _specs = importlib.util.find_spec(module_name) + _module = importlib.util.module_from_spec(_specs) + _specs.loader.exec_module(_module) + _module.init(context, out_dir_Path) #[manage salome doc command] if len(args) >1 and args[0]=='doc': _showDoc(args[1:]) @@ -1007,18 +1040,6 @@ launcher_tail_py3="""\ logging.getLogger("salome").error(e) sys.exit(1) -# salomeContext only prepend variables, we use our own appendPath when required -def appendPath(name, value, separator=os.pathsep): - if value == '': - return - - value = os.path.expandvars(value) # expand environment variables - env = os.getenv(name, None) - if env is None: - os.environ[name] = value - else: - os.environ[name] = env + separator + value - if __name__ == "__main__": args = sys.argv[1:]