Salome HOME
add appendVariable method to SalomeContext
authorNabil Ghodbane <nabil.ghodbane@cea.fr>
Wed, 15 Mar 2023 15:22:02 +0000 (16:22 +0100)
committerNabil Ghodbane <nabil.ghodbane@cea.fr>
Wed, 15 Mar 2023 15:22:02 +0000 (16:22 +0100)
bin/salomeContext.py

index 865b17557abc54b1e0a99e7c14d1d45546fa33ae..605c9cd16a2357b57f406606d94c230f48247ec9 100755 (executable)
@@ -199,7 +199,7 @@ class SalomeContext:
       del os.environ[name]
   #
 
-  """Append value to environment variable"""
+  """Prepend value to environment variable"""
   def addToVariable(self, name, value, separator=os.pathsep):
     if value == '':
       return
@@ -213,6 +213,19 @@ class SalomeContext:
       os.environ[name] = value + separator + env
   #
 
+  """Append a variable"""
+  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
+
   ###################################
   # This begins the private section #
   ###################################