From 1344514c8e47e290448ebb4ed3a36929e1068860 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Mon, 29 Apr 2024 13:45:38 +0200 Subject: [PATCH] salomeContext.py: New routine removeFromVariable. This removes a value from a string like PATH or LD_LIBRARY_PATH. --- bin/salomeContext.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 # ################################### -- 2.39.2