From af61677a8482b671f9a3bb307263a7049b1940f6 Mon Sep 17 00:00:00 2001 From: crouzet Date: Thu, 17 Jan 2019 14:46:56 +0100 Subject: [PATCH] add get_value method to Environ classes, to conform with the API of FileEnviron --- commands/config.py | 1 + src/environment.py | 23 ++++++++++++++++++++++- src/fileEnviron.py | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/commands/config.py b/commands/config.py index c83aecf..b66f8e4 100644 --- a/commands/config.py +++ b/commands/config.py @@ -722,6 +722,7 @@ def show_product_info(config, name, logger): check_path(pinfo.environ.env_script), 2) + # display run-time environment zz = src.environment.SalomeEnviron(config, src.fileEnviron.ScreenEnviron(logger), False) diff --git a/src/environment.py b/src/environment.py index df6db67..2832519 100644 --- a/src/environment.py +++ b/src/environment.py @@ -167,6 +167,15 @@ class Environ: else: return "" + def get_value(self, key): + """\ + Get the value of the environment variable "key" + This method is added for API compatibility with FileEnviron class + + :param key str: the environment variable + """ + return self.get(key) + def command_value(self, key, command): """\ Get the value given by the system command "command" @@ -255,6 +264,18 @@ class SalomeEnviron: """ return self.environ.get(key) + def get_value(self, key): + """\ + Get the real value of the environment variable "key" + This method is added for API compatibility with FileEnviron class + + :param key str: the environment variable + """ + if key in self.environ: + return self.environ[key] + else: + return "" + def set(self, key, value): """\ Set the environment variable "key" to value "value" @@ -673,7 +694,7 @@ class SalomeEnviron: product_info.install_dir, product_info.version) else: - # at least this one is mandatoryi, + # at least this one is mandatory, # if set_env_build and set_env_build are not defined pyproduct.set_env(self, product_info.install_dir, diff --git a/src/fileEnviron.py b/src/fileEnviron.py index 0e40367..fa45497 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -636,7 +636,7 @@ class LauncherFileEnviron: self.environ[key] = value def get_value(self, key): - """Get the real value of the environment variable "key" + """Get the real value of the environment variable "key", not ${key} It can help env scripts :param key str: the environment variable """ -- 2.39.2