[GRASS-SVN] r73175 - in grass/trunk/gui/wxpython: . startup

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 24 18:14:51 PDT 2018


Author: wenzeslaus
Date: 2018-08-24 18:14:50 -0700 (Fri, 24 Aug 2018)
New Revision: 73175

Modified:
   grass/trunk/gui/wxpython/gis_set.py
   grass/trunk/gui/wxpython/startup/utils.py
Log:
wxGUI/startup: read_gisrc as a function

Modified: grass/trunk/gui/wxpython/gis_set.py
===================================================================
--- grass/trunk/gui/wxpython/gis_set.py	2018-08-25 01:06:26 UTC (rev 73174)
+++ grass/trunk/gui/wxpython/gis_set.py	2018-08-25 01:14:50 UTC (rev 73175)
@@ -63,7 +63,7 @@
         # GRASS variables
         #
         self.gisbase = os.getenv("GISBASE")
-        self.grassrc = self._readGisRC()
+        self.grassrc = sutils.read_gisrc()
         self.gisdbase = self.GetRCValue("GISDBASE")
 
         #
@@ -473,28 +473,6 @@
         sizer.SetSizeHints(self)
         self.Layout()
 
-    def _readGisRC(self):
-        """Read variables from $HOME/.grass7/rc file
-        """
-        grassrc = {}
-
-        gisrc = os.getenv("GISRC")
-
-        if gisrc and os.path.isfile(gisrc):
-            try:
-                rc = open(gisrc, "r")
-                for line in rc.readlines():
-                    try:
-                        key, val = line.split(":", 1)
-                    except ValueError as e:
-                        sys.stderr.write(
-                            _('Invalid line in GISRC file (%s):%s\n' % (e, line)))
-                    grassrc[key.strip()] = DecodeString(val.strip())
-            finally:
-                rc.close()
-
-        return grassrc
-
     def _showWarning(self, text):
         """Displays a warning, hint or info message to the user.
 

Modified: grass/trunk/gui/wxpython/startup/utils.py
===================================================================
--- grass/trunk/gui/wxpython/startup/utils.py	2018-08-25 01:06:26 UTC (rev 73174)
+++ grass/trunk/gui/wxpython/startup/utils.py	2018-08-25 01:14:50 UTC (rev 73175)
@@ -96,3 +96,29 @@
 def delete_location(database, location):
     """Deletes a specified location"""
     shutil.rmtree(os.path.join(database, location))
+
+
+# TODO: similar to (but not the same as) read_gisrc function in grass.py
+def read_gisrc(self):
+    """Read variables from a current GISRC file
+
+    Returns a dictionary representation of the file content.
+    """
+    grassrc = {}
+
+    gisrc = os.getenv("GISRC")
+
+    if gisrc and os.path.isfile(gisrc):
+        try:
+            rc = open(gisrc, "r")
+            for line in rc.readlines():
+                try:
+                    key, val = line.split(":", 1)
+                except ValueError as e:
+                    sys.stderr.write(
+                        _('Invalid line in GISRC file (%s):%s\n' % (e, line)))
+                grassrc[key.strip()] = DecodeString(val.strip())
+        finally:
+            rc.close()
+
+    return grassrc



More information about the grass-commit mailing list