Skip to content

Commit

Permalink
init: Remove duplicate mapset cleaning code, use verbose (#2455)
Browse files Browse the repository at this point in the history
* Remove code duplication between init code in grass.py and grass.script.setup for mapset temporary directory cleaning.
* Simplify the code by using subprocess.DEVNULL instead of os.devnull.
* Change the cleaning message to verbose.
* Document both functions.
  • Loading branch information
wenzeslaus committed Jul 27, 2022
1 parent d59581e commit 908325a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 8 additions & 4 deletions lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -2109,10 +2109,14 @@ def done_message():


def clean_temp():
message(_("Cleaning up temporary files..."))
nul = open(os.devnull, "w")
call([gpath("etc", "clean_temp")], stdout=nul)
nul.close()
"""Clean mapset temporary directory
Simple wrapper around the library function avoiding the need to solve imports at
the top level. This can hopefully be avoided in the future.
"""
from grass.script import setup as gsetup

gsetup.clean_temp()


def clean_all():
Expand Down
11 changes: 6 additions & 5 deletions python/grass/script/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,14 @@ def call(cmd, **kwargs):


def clean_temp():
from grass.script import core as gcore
"""Clean mapset temporary directory"""
# Lazy-importing to reduce dependencies (this can be eventually removed).
# pylint: disable=import-outside-toplevel
import grass.script as gs

gcore.message(_("Cleaning up temporary files..."))
nul = open(os.devnull, "w")
gs.verbose(_("Cleaning up temporary files..."))
gisbase = os.environ["GISBASE"]
call([os.path.join(gisbase, "etc", "clean_temp")], stdout=nul)
nul.close()
call([os.path.join(gisbase, "etc", "clean_temp")], stdout=subprocess.DEVNULL)


def finish():
Expand Down

0 comments on commit 908325a

Please sign in to comment.