Pārlūkot izejas kodu

wxGUI/startup: move search for grassdata to package

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73151 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 6 gadi atpakaļ
vecāks
revīzija
dac6d4add5

+ 5 - 24
gui/wxpython/gis_set.py

@@ -540,30 +540,11 @@ class GRASSStartup(wx.Frame):
         # only if nothing is set (<UNKNOWN> comes from init script)
         if self.GetRCValue("LOCATION_NAME") != "<UNKNOWN>":
             return
-        home = os.path.expanduser('~')
-        # try some common directories for grassdata
-        # grassdata (lowercase) in home for Linux (first choice)
-        # Documents and My Documents for Windows
-        # potential translations (old Windows and some Linux)
-        # but ~ and ~/Documents should cover most of the cases
-        # ordered by preference and then likelihood
-        candidates = [
-            os.path.join(home, "grassdata"),
-            os.path.join(home, "Documents", "grassdata"),
-            os.path.join(home, "My Documents", "grassdata"),
-        ]
-        try:
-            # here goes everything which has potential unicode issues
-            candidates.append(os.path.join(home, _("Documents"), "grassdata"))
-            candidates.append(os.path.join(home, _("My Documents"), "grassdata"))
-        except UnicodeDecodeError:
-            # just ignore the errors if it doesn't work
-            pass
-        path = None
-        for candidate in candidates:
-            if os.path.exists(candidate):
-                path = candidate
-                break  # get the first match
+
+        # lazy import
+        from startup.utils import get_possible_database_path
+
+        path = get_possible_database_path()
         if path:
             try:
                 self.tgisdbase.SetValue(path)

+ 1 - 0
gui/wxpython/startup/__init__.py

@@ -1,3 +1,4 @@
 all = [
     'locdownload',
+    'utils',
 ]

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

@@ -0,0 +1,49 @@
+"""
+@package startup.utils
+
+@brief General utilities for GUI startup of GRASS GIS
+
+(C) 2017-2018 by Vaclav Petras the GRASS Development Team
+
+This program is free software under the GNU General Public License
+(>=v2). Read the file COPYING that comes with GRASS for details.
+
+@author Vaclav Petras <wenzeslaus gmail com>
+"""
+
+
+import os
+
+
+def get_possible_database_path():
+    """Finds a path to what is possibly a GRASS Database. 
+
+    Looks for directory named grassdata in the usual locations.
+
+    Returns the path as a string or None if nothing was found.
+    """
+    home = os.path.expanduser('~')
+    # try some common directories for grassdata
+    # grassdata (lowercase) in home for Linux (first choice)
+    # Documents and My Documents for Windows
+    # potential translations (old Windows and some Linux)
+    # but ~ and ~/Documents should cover most of the cases
+    # ordered by preference and then likelihood
+    candidates = [
+        os.path.join(home, "grassdata"),
+        os.path.join(home, "Documents", "grassdata"),
+        os.path.join(home, "My Documents", "grassdata"),
+    ]
+    try:
+        # here goes everything which has potential unicode issues
+        candidates.append(os.path.join(home, _("Documents"), "grassdata"))
+        candidates.append(os.path.join(home, _("My Documents"), "grassdata"))
+    except UnicodeDecodeError:
+        # just ignore the errors if it doesn't work
+        pass
+    path = None
+    for candidate in candidates:
+        if os.path.exists(candidate):
+            path = candidate
+            break  # get the first match
+    return path