소스 검색

init: Start in last used mapset with --gui like --text (#767)

When the grass executable is started with --text, it uses the last used mapset.
Now also grass --gui behaves the same way and starts the main GUI without using the startup
window to ask about the mapset.

The checks for starting in mapset are different because --text assumes it is interactive
and can just fail and give optins to the user while --gui needs to provide a GUI way.
As a result, --gui shows the statup window when the mapset is not usable for starting
(both use the ask-for-permission paradigm).
Vaclav Petras 4 년 전
부모
커밋
69ca0a9f44
1개의 변경된 파일20개의 추가작업 그리고 1개의 파일을 삭제
  1. 20 1
      lib/init/grass.py

+ 20 - 1
lib/init/grass.py

@@ -1182,6 +1182,22 @@ def load_gisrc(gisrc, gisrcrc):
     return mapset_settings
 
 
+def can_start_in_gisrc_mapset(gisrc, ignore_lock=False):
+    """Check if a mapset from a gisrc file is usable for a new session"""
+    from grass.grassdb.checks import can_start_in_mapset
+
+    mapset_settings = MapsetSettings()
+    kv = read_gisrc(gisrc)
+    mapset_settings.gisdbase = kv.get('GISDBASE')
+    mapset_settings.location = kv.get('LOCATION_NAME')
+    mapset_settings.mapset = kv.get('MAPSET')
+    if not mapset_settings.is_valid():
+        return False
+    return can_start_in_mapset(
+        mapset_path=mapset_settings.full_mapset, ignore_lock=ignore_lock
+    )
+
+
 # load environmental variables from grass_env_file
 def load_env(grass_env_file):
     if not os.access(grass_env_file, os.R_OK):
@@ -2286,9 +2302,12 @@ def main():
 
     # Parsing argument to get LOCATION
     if not params.mapset and not params.tmp_location:
+        last_mapset_usable = can_start_in_gisrc_mapset(
+            gisrc=gisrc, ignore_lock=params.force_gislock_removal
+        )
         # Try interactive startup
         # User selects LOCATION and MAPSET if not set
-        if not set_mapset_interactive(grass_gui):
+        if not last_mapset_usable and not set_mapset_interactive(grass_gui):
             # No GUI available, update gisrc file
             fatal(_("<{0}> requested, but not available. Run GRASS in text "
                     "mode (--text) or install missing package (usually "