From 71ea9419b0747a94b55469edec6199bc1d2e05bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Thu, 29 Aug 2024 18:16:20 -0400 Subject: [PATCH] grass.temporal.stds_import: Use pathlib Path.read_text and Path.write_text for proj string (#4236) --- python/grass/temporal/stds_import.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/python/grass/temporal/stds_import.py b/python/grass/temporal/stds_import.py index e8684d9ecb4..03810e49b89 100644 --- a/python/grass/temporal/stds_import.py +++ b/python/grass/temporal/stds_import.py @@ -32,6 +32,7 @@ import os import os.path import tarfile +from pathlib import Path import grass.script as gs from grass.exceptions import CalledModuleError @@ -302,16 +303,12 @@ def import_stds( # from other programs than g.proj into # new line format so that the grass file comparison function # can be used to compare the projections - proj_name_tmp = temp_name + "_in_projection" - proj_file = open(proj_name, "r") - proj_content = proj_file.read() + proj_content = Path(proj_name).read_text() proj_content = proj_content.replace(" +", "\n+") proj_content = proj_content.replace("\t+", "\n+") - proj_file.close() - proj_file = open(proj_name_tmp, "w") - proj_file.write(proj_content) - proj_file.close() + proj_name_tmp = f"{temp_name}_in_projection" + Path(proj_name_tmp).write_text(proj_content) p = gs.start_command("g.proj", flags="j", stdout=temp_file) p.communicate() @@ -336,7 +333,7 @@ def import_stds( old_env = gs.gisenv() if location: try: - proj4_string = open(proj_file_name, "r").read() + proj4_string = Path(proj_file_name).read_text() gs.create_location( dbase=old_env["GISDBASE"], location=location, proj4=proj4_string )