Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grass.temporal.abstract_space_time_dataset: Use Path.read_text() to load sql template files #232

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,11 @@ ignore = [
"python/grass/script/db.py" = ["SIM115"]
"python/grass/script/raster.py" = ["SIM115"]
"python/grass/script/utils.py" = ["SIM115"]
"python/grass/temporal/*.py" = ["SIM115"]
"python/grass/temporal/aggregation.py" = ["SIM115"]
"python/grass/temporal/register.py" = ["SIM115"]
"python/grass/temporal/stds_export.py" = ["SIM115"]
"python/grass/temporal/stds_import.py" = ["SIM115"]
"python/grass/temporal/univar_statistics.py" = ["SIM115"]
"python/grass/utils/download.py" = ["SIM115"]
"raster/r.*/testsuite/*.py" = ["SIM115"]
"raster/r.topidx/*.py" = ["SIM115"]
Expand Down
34 changes: 13 additions & 21 deletions python/grass/temporal/abstract_space_time_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class that is the base class for all space time datasets.
import uuid
from abc import ABCMeta, abstractmethod
from datetime import datetime
from pathlib import Path

from .abstract_dataset import AbstractDataset, AbstractDatasetComparisonKeyStartTime
from .core import (
Expand Down Expand Up @@ -395,9 +396,7 @@ def insert(self, dbif=None, execute=True):
# %s;"%(stds_register_table + "_index", stds_register_table))

# Read the SQL template
sql = open(
os.path.join(sql_path, "stds_map_register_table_template.sql"), "r"
).read()
sql = Path(sql_path, "stds_map_register_table_template.sql").read_text()

# Create a raster, raster3d or vector tables
sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
Expand Down Expand Up @@ -2818,13 +2817,10 @@ def update_from_registered_maps(self, dbif=None):
)
if old_sqlite_version:
template_suffix = "_old"
sql = open(
os.path.join(
sql_path,
f"update_stds_spatial_temporal_extent_template{template_suffix}.sql",
),
"r",
).read()
sql = Path(
sql_path,
f"update_stds_spatial_temporal_extent_template{template_suffix}.sql",
).read_text()
sql = sql.replace("GRASS_MAP", self.get_new_map_instance(None).get_type())
sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
sql = sql.replace("SPACETIME_ID", self.base.get_id())
Expand All @@ -2834,13 +2830,10 @@ def update_from_registered_maps(self, dbif=None):
sql_script += "\n"

# Update type specific metadata
sql = open(
os.path.join(
sql_path,
f"update_{self.get_type()}_metadata_template{template_suffix}.sql",
),
"r",
).read()
sql = Path(
sql_path,
f"update_{self.get_type()}_metadata_template{template_suffix}.sql",
).read_text()

# Comment out update of semantic labels for DB version < 3
if get_tgis_db_version_from_metadata() < 3:
Expand All @@ -2853,10 +2846,9 @@ def update_from_registered_maps(self, dbif=None):
"-- count(distinct semantic_label)",
)
elif old_sqlite_version and self.get_type() == "strds":
semantic_label_sql = open(
os.path.join(sql_path, "update_strds_metadata_template_v3.sql"),
"r",
).read()
semantic_label_sql = Path(
sql_path, "update_strds_metadata_template_v3.sql"
).read_text()
sql = sql + "\n" + semantic_label_sql

sql = sql.replace("SPACETIME_REGISTER_TABLE", stds_register_table)
Expand Down
Loading