Skip to content

Commit

Permalink
init: Start in last used mapset with --gui like --text (#767)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
wenzeslaus committed Aug 19, 2020
1 parent e391950 commit 69ca0a9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/init/grass.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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 "
Expand Down

0 comments on commit 69ca0a9

Please sign in to comment.