Ver código fonte

grass.py: do not override already set GRASS environmental variables

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61051 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 10 anos atrás
pai
commit
05094f02eb
1 arquivos alterados com 19 adições e 3 exclusões
  1. 19 3
      lib/init/grass.py

+ 19 - 3
lib/init/grass.py

@@ -746,7 +746,17 @@ def load_env():
             k, v = map(lambda x: x.strip(), line.strip().split(' ', 1)[1].split('=', 1))
         except:
             continue
-        os.environ[k] = v
+        
+        evalue = os.getenv(k)
+        if evalue:
+            if k == 'GRASS_ADDON_PATH':
+                os.environ[k] = evalue + os.pathsep + v
+            else:
+                warning(_("Environmental variable '%s' already set, ignoring value '%s'") % \
+                            (k, v))
+        else:
+            os.environ[k] = v
+    
     # Allow for mixed ISIS-GRASS Environment
     if os.getenv('ISISROOT'):
         isis = os.getenv('ISISROOT')
@@ -1131,8 +1141,14 @@ PROMPT_COMMAND=grass_prompt\n""" % (_("2D and 3D raster MASKs present"),
     path = os.path.join(userhome, ".grass.bashrc") # left for backward compatibility
     if os.access(path, os.R_OK):
         f.write(readfile(path) + '\n')
-    if os.access(grass_env_file, os.R_OK):
-        f.write(readfile(grass_env_file) + '\n')
+    for env in os.environ.keys():
+        if env.startswith('GRASS'):
+            val = os.environ[env]
+            if ' ' in val:
+                val = '"%s"' % val
+            f.write('export %s=%s\n' % (env, val))
+    #    if os.access(grass_env_file, os.R_OK):
+    #        f.write(readfile(grass_env_file) + '\n')
 
     f.write("export PATH=\"%s\"\n" % os.getenv('PATH'))
     f.write("export HOME=\"%s\"\n" % userhome) # restore user home path