[GRASS-SVN] r53498 - grass/trunk/lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 19 06:48:50 PDT 2012


Author: martinl
Date: 2012-10-19 06:48:50 -0700 (Fri, 19 Oct 2012)
New Revision: 53498

Modified:
   grass/trunk/lib/init/grass.py
Log:
eliminate gisenv LANG


Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2012-10-19 12:41:01 UTC (rev 53497)
+++ grass/trunk/lib/init/grass.py	2012-10-19 13:48:50 UTC (rev 53498)
@@ -52,7 +52,7 @@
 else:
     grass_config_dirname = ".grass7"
     grass_config_dir = os.path.join(os.getenv('HOME'), grass_config_dirname)
-    grass_env_file = os.path.join(grass_config_dir, 'bashrc')
+    grass_env_file = None # see check_shell()
 
 gisbase = os.path.normpath(gisbase)
 
@@ -639,13 +639,25 @@
     
     location = os.path.join(gisdbase, location_name, mapset)
 
-def set_env_from_gisrc():
-    ### TODO: eliminate all env-from-gisrc
+def get_env_variable_from_file(key):
+    if not os.access(grass_env_file, os.R_OK):
+        return None
+    
+    for line in readfile(grass_env_file).split(os.linesep):
+        try:
+            k, v = map(lambda x: x.strip(), line.strip().split(' ', 1)[1].split('=', 1))
+        except:
+            continue
+        if k == key:
+            return v
+    
+    return None
+
+def set_language():
     import locale
-    kv = read_gisrc()
     
     ### language
-    language = kv.get('LANG')
+    language = get_env_variable_from_file('LANG')
     if language:
         language = language.split('.')[0] # Split off ignored .encoding part if present
         orig_language = language
@@ -722,7 +734,7 @@
         call(["g.mkfontcap"])
     
 def check_shell():
-    global sh, shellname
+    global sh, shellname, grass_env_file
     # cygwin has many problems with the shell setup
     # below, so i hardcoded everything here.
     if os.getenv('CYGWIN'):
@@ -745,6 +757,11 @@
         else:
             shellname = "shell"
     
+    if sh in ['csh', 'tcsh']:
+        grass_env_file = os.path.join(grass_config_dir, 'cshrc')
+    elif sh in ['bash', 'msh', 'cygwin']:
+        grass_env_file = os.path.join(grass_config_dir, 'bashrc')
+    
     # check for SHELL
     if not os.getenv('SHELL'):
         fatal(_("The SHELL variable is not set"))
@@ -847,9 +864,11 @@
     f.write("GRASS %s > '" % grass_version)
     f.write("set BOGUS=``;unset BOGUS")
     
-    path = os.path.join(userhome, ".grass.cshrc")
+    path = os.path.join(userhome, ".grass.cshrc") # left for backward compatibility
     if os.access(path, os.R_OK):
-        f.write(readfile(path))
+        f.write(readfile(path) + '\n')
+    if os.access(grass_env_file, os.R_OK):
+        f.write(readfile(grass_env_file) + '\n')
     
     mail_re = re.compile(r"^ *set  *mail *= *")
     
@@ -906,7 +925,7 @@
     f.write("export HOME=\"%s\"\n" % userhome) # restore user home path
     
     f.close()
-    
+
     exit_val = call([gfile("etc", "run"), os.getenv('SHELL')])
     
     os.environ['HOME'] = userhome
@@ -1094,9 +1113,6 @@
 # Ensure GUI is set
 read_gui()
 
-# Get environmental variables from gisenv variables
-set_env_from_gisrc()
-
 # Set PATH, PYTHONPATH
 set_paths()
 
@@ -1164,6 +1180,9 @@
 
 check_shell()
 
+# Set language
+set_language()
+
 check_batch_job()
 
 if not batch_job:       



More information about the grass-commit mailing list