Skip to content

Commit

Permalink
switch_to_new_mapset changes to enable using existing mapset
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrunn committed Dec 17, 2024
1 parent 78fd280 commit 349d5b1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/grass_gis_helpers/mapset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import grass.script as grass


def switch_to_new_mapset(new_mapset):
def switch_to_new_mapset(new_mapset, new = True):
"""The function switches to a new mapset and changes the GISRC file for
parallel processing.
Args:
new_mapset (string): Unique name of the new mapset
new (boolean): Boolean if existing mapset should be used
or a new one created
Returns:
gisrc (string): The path of the old GISRC file
newgisrc (string): The path of the new GISRC file
Expand All @@ -39,8 +41,12 @@ def switch_to_new_mapset(new_mapset):
location = env["LOCATION_NAME"]
old_mapset = env["MAPSET"]

grass.message(_(f"New mapset {new_mapset}"))
grass.utils.try_rmdir(os.path.join(gisdbase, location, new_mapset))
if new:
grass.message(_(f"New mapset {new_mapset}"))
grass.utils.try_rmdir(os.path.join(gisdbase, location, new_mapset))
else:
grass.message(_(f"Using, not deleting mapset {new_mapset}"))
grass.try_remove(os.path.join(gisdbase, location, new_mapset, ".gislock"))

gisrc = os.environ["GISRC"]
newgisrc = f"{gisrc}_{os.getpid()}"
Expand Down

0 comments on commit 349d5b1

Please sign in to comment.