[GRASS-SVN] r49910 - in grass/trunk: gui/wxpython/gui_core lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 25 18:28:31 EST 2011


Author: martinl
Date: 2011-12-25 15:28:31 -0800 (Sun, 25 Dec 2011)
New Revision: 49910

Modified:
   grass/trunk/gui/wxpython/gui_core/preferences.py
   grass/trunk/lib/init/grass.py
Log:
simplify language settings, use gisenv instead of environmental variable and expand by startup script


Modified: grass/trunk/gui/wxpython/gui_core/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/preferences.py	2011-12-25 23:08:45 UTC (rev 49909)
+++ grass/trunk/gui/wxpython/gui_core/preferences.py	2011-12-25 23:28:31 UTC (rev 49910)
@@ -156,36 +156,6 @@
         """!Button 'Cancel' pressed"""
         self.Close()
     
-    def _saveEnv(self, lang):
-        """!Save environmental variables
-
-        @param lang locale code (eg. 'C')
-        """
-        envFile = os.path.join(GetSettingsPath(), 'bashrc')
-        
-        # read variables
-        if os.path.exists(envFile):
-            rcfile = open(os.path.join(GetSettingsPath(), 'bashrc'), "r")
-            rclines = rcfile.readlines()
-            rcfile.close()
-        else:
-            rclines = []
-        
-        rcfile = open(envFile, "w")
-        
-        # save language settings
-        grasslang = False
-        for line in rclines:
-            if 'GRASS_LANG' in line:
-                rcfile.write('GRASS_LANG: %s\n' % lang)
-                grasslang = True
-            else:
-                rcfile.write(line)
-        if not grasslang:
-            rcfile.write('GRASS_LANG: %s\n' % lang)
-        
-        rcfile.close()
-        
     def OnSave(self, event):
         """!Button 'Save' pressed
         Posts event EVT_SETTINGS_CHANGED.
@@ -193,11 +163,9 @@
         if self._updateSettings():
             self.settings.SaveToFile()
             self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % self.settings.filePath)
-            fileSettings = {}
-            self.settings.ReadSettingsFile(settings = fileSettings)
-            
-            self._saveEnv(lang = fileSettings['language']['locale']['lc_all'])
-            
+            lang = UserSettings.Get(group = 'language', key = 'locale', subkey = 'lc_all')
+            if lang:
+                RunCommand('g.gisenv', set = 'LANG=%s' % lang)
             event = wxSettingsChanged()
             wx.PostEvent(self, event)
             self.Close()

Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2011-12-25 23:08:45 UTC (rev 49909)
+++ grass/trunk/lib/init/grass.py	2011-12-25 23:28:31 UTC (rev 49910)
@@ -236,16 +236,21 @@
     
 def read_gisrc():
     kv = {}
-    f = open(gisrc, 'r')
+    try:
+        f = open(gisrc, 'r')
+    except IOError:
+        return kv
+    
     for line in f:
 	k, v = line.split(':', 1)
 	kv[k.strip()] = v.strip()
     f.close()
+    
     return kv
 
-def read_bashrc():
+def read_env_file(path):
     kv = {}
-    f = open(os.path.join(grass_config_dir, "bashrc"), 'r')
+    f = open(path, 'r')
     for line in f:
         k, v = line.split(':', 1)
         kv[k.strip()] = v.strip()
@@ -292,28 +297,12 @@
 def get_locale():
     global locale
     locale = None
-    try:
-        kv = read_bashrc()
-    except:
-        kv = {}
-    if 'GRASS_LANG' in os.environ:
-        locale = os.environ['GRASS_LANG']
-        if locale[0:2] == 'en':
-          locale = None
-    elif 'GRASS_LANG' in kv:
-        locale = kv['GRASS_LANG']
-        if locale[0:2] == 'en':
-          locale = None
-    if locale:
-        for var in ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']:
-            os.environ[var] = locale
+    for var in ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']: 
+        loc = os.getenv(var) 
+        if loc: 
+            locale = loc[0:2] 
+        return 
 
-    for var in ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']:
-        loc = os.getenv(var)
-        if loc:
-            locale = loc[0:2]
-    return
-
 def path_prepend(dir, var):
     path = os.getenv(var)
     if path:
@@ -334,7 +323,7 @@
     # addons (path)
     addon_path = os.getenv('GRASS_ADDON_PATH')
     if addon_path:
-        for path in addons_path.split(os.pathsep):
+        for path in addon_path.split(os.pathsep):
             path_prepend(addon_path, 'PATH')
     
     # addons (base)
@@ -628,15 +617,21 @@
     
     location = os.path.join(gisdbase, location_name, mapset)
 
-    # convert selected gisenv variables to environmental variables
+def set_env_from_gisrc():
+    kv = read_gisrc()
+    
+    ### addons
     if kv.get('ADDON_PATH'):
         addon_path = kv.get('ADDON_PATH')
         if os.getenv('GRASS_ADDON_PATH'):
             os.environ['GRASS_ADDON_PATH'] += os.pathsep + addon_path
         else:
             os.environ['GRASS_ADDON_PATH'] = addon_path
-        path_prepend(addon_path, 'PATH')
     
+    ### language
+    if kv.get('LANG'):
+        os.environ['LANGUAGE'] = kv.get('LANG')
+    
 def check_lock():
     global lockfile
     if not os.path.exists(location):
@@ -860,11 +855,6 @@
     f.write("export PATH=\"%s\"\n" % os.getenv('PATH'))
     f.write("export HOME=\"%s\"\n" % userhome) # restore user home path
     
-    g7bashrc = os.path.join(grass_config_dir,'bashrc')
-    if not os.path.exists(g7bashrc):
-      fg7 = open(g7bashrc, 'w')
-      fg7.close()
-    
     for env, value in os.environ.iteritems():
         if env.find('GRASS_') < 0:
             continue
@@ -1059,6 +1049,9 @@
 # Ensure GUI is set
 read_gui()
 
+# Get environmental variables from gisenv variables
+set_env_from_gisrc()
+
 # Get Locale name
 get_locale()
 



More information about the grass-commit mailing list