[GRASS-SVN] r73151 - in grass/trunk/gui/wxpython: . startup
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 23 18:50:21 PDT 2018
Author: wenzeslaus
Date: 2018-08-23 18:50:21 -0700 (Thu, 23 Aug 2018)
New Revision: 73151
Added:
grass/trunk/gui/wxpython/startup/utils.py
Modified:
grass/trunk/gui/wxpython/gis_set.py
grass/trunk/gui/wxpython/startup/__init__.py
Log:
wxGUI/startup: move search for grassdata to package
Modified: grass/trunk/gui/wxpython/gis_set.py
===================================================================
--- grass/trunk/gui/wxpython/gis_set.py 2018-08-24 01:34:55 UTC (rev 73150)
+++ grass/trunk/gui/wxpython/gis_set.py 2018-08-24 01:50:21 UTC (rev 73151)
@@ -540,30 +540,11 @@
# 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)
Modified: grass/trunk/gui/wxpython/startup/__init__.py
===================================================================
--- grass/trunk/gui/wxpython/startup/__init__.py 2018-08-24 01:34:55 UTC (rev 73150)
+++ grass/trunk/gui/wxpython/startup/__init__.py 2018-08-24 01:50:21 UTC (rev 73151)
@@ -1,3 +1,4 @@
all = [
'locdownload',
+ 'utils',
]
Added: grass/trunk/gui/wxpython/startup/utils.py
===================================================================
--- grass/trunk/gui/wxpython/startup/utils.py (rev 0)
+++ grass/trunk/gui/wxpython/startup/utils.py 2018-08-24 01:50:21 UTC (rev 73151)
@@ -0,0 +1,49 @@
+"""
+ at package startup.utils
+
+ at 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.
+
+ at 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
Property changes on: grass/trunk/gui/wxpython/startup/utils.py
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/x-python
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
More information about the grass-commit
mailing list