[GRASS-SVN] r73152 - in grass/trunk/gui/wxpython: . startup
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 23 19:45:39 PDT 2018
Author: wenzeslaus
Date: 2018-08-23 19:45:39 -0700 (Thu, 23 Aug 2018)
New Revision: 73152
Modified:
grass/trunk/gui/wxpython/gis_set.py
grass/trunk/gui/wxpython/startup/utils.py
Log:
wxGUI/startup: lock filename and check in one function
Modified: grass/trunk/gui/wxpython/gis_set.py
===================================================================
--- grass/trunk/gui/wxpython/gis_set.py 2018-08-24 01:50:21 UTC (rev 73151)
+++ grass/trunk/gui/wxpython/gis_set.py 2018-08-24 02:45:39 UTC (rev 73152)
@@ -37,6 +37,8 @@
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 @@
# 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 @@
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 @@
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 @@
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=_(
Modified: grass/trunk/gui/wxpython/startup/utils.py
===================================================================
--- grass/trunk/gui/wxpython/startup/utils.py 2018-08-24 01:50:21 UTC (rev 73151)
+++ grass/trunk/gui/wxpython/startup/utils.py 2018-08-24 02:45:39 UTC (rev 73152)
@@ -20,7 +20,8 @@
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 @@
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
+
More information about the grass-commit
mailing list