From: Pascal Obry Date: Mon, 29 Apr 2024 11:45:38 +0000 (+0200) Subject: salomeContext.py: New routine removeFromVariable. X-Git-Tag: emc2p_2.0.0-rc2^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=1344514c8e47e290448ebb4ed3a36929e1068860;p=modules%2Fkernel.git salomeContext.py: New routine removeFromVariable. This removes a value from a string like PATH or LD_LIBRARY_PATH. --- diff --git a/bin/salomeContext.py b/bin/salomeContext.py index d9b42b06d..93a74d457 100755 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -231,6 +231,24 @@ class SalomeContext: os.environ[name] = env + separator + value return + """Remove value from environment variable""" + def removeFromVariable(self, name, value, separator=os.pathsep): + if value == '': + return + + value = os.path.expandvars(value) # expand environment variables + self.getLogger().debug("Remove from %s: %s", name, value) + env = os.getenv(name, None) + if env == value: + env = '' + else: + env = env.removeprefix(value + separator) + env = env.removesuffix(separator + value) + env = env.replace(separator + value + separator, ':') + + os.environ[name] = env + # + ################################### # This begins the private section # ###################################