Browse Source

wxGUI startup: automatic detection of grassdata #644 (#664)

Detects a grassdata (case insensitive) directory if present in usual locations (home, home/Documents)
Linda Kladivova 5 năm trước cách đây
mục cha
commit
80a7b3fb84
1 tập tin đã thay đổi với 13 bổ sung25 xóa
  1. 13 25
      gui/wxpython/startup/utils.py

+ 13 - 25
gui/wxpython/startup/utils.py

@@ -21,38 +21,26 @@ import shutil
 
 
 
 
 def get_possible_database_path():
 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, so the
-    return value can be used to test if the directory was found.
+    """Looks for directory 'grassdata' (case-insensitive) in standard 
+    locations to detect existing GRASS Database.
+    
+    Returns the path as a string or None if nothing was found.
     """
     """
     home = os.path.expanduser('~')
     home = os.path.expanduser('~')
+
     # try some common directories for grassdata
     # 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 = [
     candidates = [
-        os.path.join(home, "grassdata"),
-        os.path.join(home, "Documents", "grassdata"),
-        os.path.join(home, "My Documents", "grassdata"),
+        home,
+        os.path.join(home, "Documents"),
     ]
     ]
-    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
+
+    # find possible database path
     for candidate in candidates:
     for candidate in candidates:
         if os.path.exists(candidate):
         if os.path.exists(candidate):
-            path = candidate
-            break  # get the first match
-    return path
+            for subdir in next(os.walk(candidate))[1]:
+                if 'grassdata' in subdir.lower():
+                    return os.path.join(candidate,subdir)
+    return None
 
 
 
 
 def get_lockfile_if_present(database, location, mapset):
 def get_lockfile_if_present(database, location, mapset):