Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
veroandreo authored Aug 27, 2024
2 parents 7cad643 + 4aa4abf commit 6db252d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 57 deletions.
32 changes: 32 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Description
<!-- Describe your changes in detail -->

## Motivation and context
<!-- Why is this change required? What problem does it solve? -->
<!-- If it fixes an open issue, please link the issue here. -->

## How has this been tested?
<!-- Please describe how you tested your changes. -->

## Screenshots (if appropriate)

## Types of changes
<!-- What types of changes does your code introduce? -->
<!-- Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as before)

## Checklist
<!-- See the following points, and put an `x` in all the boxes that apply. -->
<!-- If you're unsure about any of these, please ask. We're here to help! -->
- [ ] PR title provides summary of the changes and starts with one of the
[pre-defined prefixes](../../utils/release.yml)
<!-- For example: "doc: Add example to db.describe documentation" -->
<!-- or if it is a fix use "db.describe: fix JSON output format" -->
- [ ] My code follows the [code style](../../doc/development/style_guide.md)
of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
2 changes: 2 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ default: true

# Fix any fixable errors (depending on the markdownlint wrapper tool used)
fix: true

MD041: false # first-line-h1
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import unicodedata
import argparse
import json
from pathlib import Path


# mechanism meant for debugging this script (only)
Expand Down Expand Up @@ -167,10 +168,7 @@ def fatal(msg):

def readfile(path):
debug("Reading %s" % path)
f = open(path, "r")
s = f.read()
f.close()
return s
return Path(path).read_text()


def writefile(path, s):
Expand Down
74 changes: 24 additions & 50 deletions python/grass/temporal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

# import traceback
import os
from pathlib import Path

import grass.script as gs
from grass.pygrass import messages
Expand Down Expand Up @@ -813,7 +814,7 @@ def _create_temporal_database_views(dbif):
:param dbif: The database interface to be used
"""
template_path = get_sql_template_path()
template_path = Path(get_sql_template_path())

for sql_filename in (
"raster_views",
Expand All @@ -823,9 +824,7 @@ def _create_temporal_database_views(dbif):
"str3ds_views",
"stvds_views",
):
sql_filepath = open(
os.path.join(template_path, sql_filename + ".sql"), "r"
).read()
sql_filepath = (template_path / f"{sql_filename}.sql").read_text()
dbif.execute_transaction(sql_filepath)


Expand All @@ -839,34 +838,18 @@ def create_temporal_database(dbif):
"""
global tgis_backend, tgis_version, tgis_db_version, tgis_database_string

template_path = get_sql_template_path()
template_path = Path(get_sql_template_path())
msgr = get_tgis_message_interface()

# Read all SQL scripts and templates
map_tables_template_sql = open(
os.path.join(template_path, "map_tables_template.sql"), "r"
).read()
raster_metadata_sql = open(
os.path.join(get_sql_template_path(), "raster_metadata_table.sql"), "r"
).read()
raster3d_metadata_sql = open(
os.path.join(template_path, "raster3d_metadata_table.sql"), "r"
).read()
vector_metadata_sql = open(
os.path.join(template_path, "vector_metadata_table.sql"), "r"
).read()
stds_tables_template_sql = open(
os.path.join(template_path, "stds_tables_template.sql"), "r"
).read()
strds_metadata_sql = open(
os.path.join(template_path, "strds_metadata_table.sql"), "r"
).read()
str3ds_metadata_sql = open(
os.path.join(template_path, "str3ds_metadata_table.sql"), "r"
).read()
stvds_metadata_sql = open(
os.path.join(template_path, "stvds_metadata_table.sql"), "r"
).read()
map_tables_template_sql = (template_path / "map_tables_template.sql").read_text()
raster_metadata_sql = (template_path / "raster_metadata_table.sql").read_text()
raster3d_metadata_sql = (template_path / "raster3d_metadata_table.sql").read_text()
vector_metadata_sql = (template_path / "vector_metadata_table.sql").read_text()
stds_tables_template_sql = (template_path / "stds_tables_template.sql").read_text()
strds_metadata_sql = (template_path / "strds_metadata_table.sql").read_text()
str3ds_metadata_sql = (template_path / "str3ds_metadata_table.sql").read_text()
stvds_metadata_sql = (template_path / "stvds_metadata_table.sql").read_text()

# Create the raster, raster3d and vector tables SQL statements
raster_tables_sql = map_tables_template_sql.replace("GRASS_MAP", "raster")
Expand Down Expand Up @@ -898,21 +881,15 @@ def create_temporal_database(dbif):

# Set up the trigger that takes care of
# the correct deletion of entries across the different tables
delete_trigger_sql = open(
os.path.join(template_path, "sqlite3_delete_trigger.sql"), "r"
).read()
indexes_sql = open(
os.path.join(template_path, "sqlite3_indexes.sql"), "r"
).read()
delete_trigger_sql = (template_path / "sqlite3_delete_trigger.sql").read_text()
indexes_sql = (template_path / "sqlite3_indexes.sql").read_text()
else:
# Set up the trigger that takes care of
# the correct deletion of entries across the different tables
delete_trigger_sql = open(
os.path.join(template_path, "postgresql_delete_trigger.sql"), "r"
).read()
indexes_sql = open(
os.path.join(template_path, "postgresql_indexes.sql"), "r"
).read()
delete_trigger_sql = (
template_path / "postgresql_delete_trigger.sql"
).read_text()
indexes_sql = (template_path / "postgresql_indexes.sql").read_text()

# Connect now to the database
if dbif.connected is not True:
Expand Down Expand Up @@ -989,22 +966,19 @@ def upgrade_temporal_database(dbif):
dbif.close()
return

template_path = get_sql_template_path()
template_path = Path(get_sql_template_path())
try:
upgrade_db_sql = open(
os.path.join(
template_path,
"upgrade_db_%s_to_%s.sql" % (upgrade_db_from, tgis_db_version),
),
"r",
).read()
upgrade_db_sql = (
template_path
/ "upgrade_db_{}_to_{}.sql".format(upgrade_db_from, tgis_db_version)
).read_text()
except FileNotFoundError:
msgr.fatal(
_("Unsupported TGIS DB upgrade scenario: from version %s to %s")
% (upgrade_db_from, tgis_db_version)
)

drop_views_sql = open(os.path.join(template_path, "drop_views.sql"), "r").read()
drop_views_sql = (template_path / "drop_views.sql").read_text()

msgr.message(
_("Upgrading temporal database <%s> from version %s to %s...")
Expand Down

0 comments on commit 6db252d

Please sign in to comment.