Explorar el Código

wxGUI/startup: read_gisrc as a function

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73175 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras hace 6 años
padre
commit
b177cbad50
Se han modificado 2 ficheros con 27 adiciones y 23 borrados
  1. 1 23
      gui/wxpython/gis_set.py
  2. 26 0
      gui/wxpython/startup/utils.py

+ 1 - 23
gui/wxpython/gis_set.py

@@ -63,7 +63,7 @@ class GRASSStartup(wx.Frame):
         # 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 @@ class GRASSStartup(wx.Frame):
         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.
 

+ 26 - 0
gui/wxpython/startup/utils.py

@@ -96,3 +96,29 @@ def delete_mapset(database, location, mapset):
 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