瀏覽代碼

wxGUI/startup: lock filename and check in one function

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73152 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 6 年之前
父節點
當前提交
dd3f0dfc7f
共有 2 個文件被更改,包括 25 次插入13 次删除
  1. 8 12
      gui/wxpython/gis_set.py
  2. 17 1
      gui/wxpython/startup/utils.py

+ 8 - 12
gui/wxpython/gis_set.py

@@ -37,6 +37,8 @@ from grass.script import core as grass
 
 from core.gcmd import GMessage, GError, DecodeString, RunCommand
 from core.utils import GetListOfLocations, GetListOfMapsets
+from startup.utils import (
+    get_lockfile_if_present, get_possible_database_path)
 from location_wizard.dialogs import RegionDef
 from gui_core.dialogs import TextEntryDialog
 from gui_core.widgets import GenericValidator, StaticWrapText
@@ -540,10 +542,6 @@ class GRASSStartup(wx.Frame):
         # only if nothing is set (<UNKNOWN> comes from init script)
         if self.GetRCValue("LOCATION_NAME") != "<UNKNOWN>":
             return
-
-        # lazy import
-        from startup.utils import get_possible_database_path
-
         path = get_possible_database_path()
         if path:
             try:
@@ -892,9 +890,8 @@ class GRASSStartup(wx.Frame):
         idx = 0
         for mapset in self.listOfMapsets:
             if mapset not in self.listOfMapsetsSelectable or \
-                    os.path.isfile(os.path.join(self.gisdbase,
-                                                locationName,
-                                                mapset, ".gislock")):
+                    get_lockfile_if_present(self.gisdbase,
+                                            locationName, mapset):
                 disabled.append(idx)
             idx += 1
 
@@ -926,9 +923,8 @@ class GRASSStartup(wx.Frame):
 
         for mapset in self.listOfMapsets:
             if mapset not in self.listOfMapsetsSelectable or \
-                    os.path.isfile(os.path.join(self.gisdbase,
-                                                locationName,
-                                                mapset, ".gislock")):
+                    get_lockfile_if_present(self.gisdbase,
+                                            locationName, mapset):
                 disabled.append(idx)
             idx += 1
 
@@ -1070,8 +1066,8 @@ class GRASSStartup(wx.Frame):
         location = self.listOfLocations[self.lblocations.GetSelection()]
         mapset = self.listOfMapsets[self.lbmapsets.GetSelection()]
 
-        lockfile = os.path.join(dbase, location, mapset, '.gislock')
-        if os.path.isfile(lockfile):
+        lockfile = get_lockfile_if_present(dbase, location, mapset)
+        if lockfile:
             dlg = wx.MessageDialog(
                 parent=self,
                 message=_(

+ 17 - 1
gui/wxpython/startup/utils.py

@@ -20,7 +20,8 @@ def get_possible_database_path():
 
     Looks for directory named grassdata in the usual locations.
 
-    Returns the path as a string or None if nothing was found.
+    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.
     """
     home = os.path.expanduser('~')
     # try some common directories for grassdata
@@ -47,3 +48,18 @@ def get_possible_database_path():
             path = candidate
             break  # get the first match
     return path
+
+
+def get_lockfile_if_present(database, location, mapset):
+    """Return path to lock if present, None otherwise
+
+    Returns the path as a string or None if nothing was found, so the
+    return value can be used to test if the lock is present.
+    """
+    lock_name = '.gislock'
+    lockfile = os.path.join(database, location, mapset, lock_name)
+    if os.path.isfile(lockfile):
+        return lockfile
+    else:
+        return None
+