aboutsummaryrefslogtreecommitdiffstats
path: root/import_source.py
diff options
context:
space:
mode:
Diffstat (limited to 'import_source.py')
-rw-r--r--import_source.py47
1 files changed, 29 insertions, 18 deletions
diff --git a/import_source.py b/import_source.py
index c4cb96f..647c79e 100644
--- a/import_source.py
+++ b/import_source.py
@@ -28,6 +28,7 @@ from pathlib import Path
from datetime import datetime, timedelta, UTC
from typing import Any, Final, Optional
import traceback
+from enum import Enum, unique
from hashlib import sha256
import struct
@@ -435,6 +436,13 @@ def listArchiveMembers(namelist : list[str],
logging.debug('Ignoring archive member %s', name)
return members
+@unique
+class ImportStatus(Enum):
+ """Return value for importSources(): success, error, or no-change."""
+ IMPORT_SUCCESS = 0
+ IMPORT_ERROR = 1
+ IMPORT_NOCHANGE = 255
+
# pylint: disable-next=dangerous-default-value
def importSources(dso : gdal.Dataset, lyr : ogr.Layer,
sources : dict[str,Any] = {},
@@ -442,7 +450,7 @@ def importSources(dso : gdal.Dataset, lyr : ogr.Layer,
extent : ogr.Geometry|None = None,
dsoTransaction : bool = False,
lyrcache : ogr.Layer|None = None,
- force : bool = False) -> bool:
+ force : bool = False) -> ImportStatus:
"""Clear lyr and import source layers to it."""
layername = lyr.GetName()
@@ -462,7 +470,7 @@ def importSources(dso : gdal.Dataset, lyr : ogr.Layer,
layername)
lyrTransaction = False
- rv = True
+ rv = ImportStatus.IMPORT_NOCHANGE
now = datetime.now().astimezone()
fingerprint = sha256()
fingerprint_map = fingerprintLayerDefn(fingerprint, lyr)
@@ -482,20 +490,24 @@ def importSources(dso : gdal.Dataset, lyr : ogr.Layer,
dso.FlushCache()
fingerprint = fingerprint.digest()
- if lyrcache is not None:
- if not updateLayerCache(layername=layername,
- cache=lyrcache,
- ds=dso, lyr=lyr,
- force=force,
- lyrTransaction=lyrTransaction,
- last_updated=now,
- fingerprint=fingerprint):
- if isinstance(lyrTransaction, bool):
- # the transaction on lyr was already rolled back
- lyrTransaction = False
+ if lyrcache is None:
+ rv = ImportStatus.IMPORT_SUCCESS
+ elif updateLayerCache(layername=layername,
+ cache=lyrcache,
+ ds=dso, lyr=lyr,
+ force=force,
+ lyrTransaction=lyrTransaction,
+ last_updated=now,
+ fingerprint=fingerprint):
+ rv = ImportStatus.IMPORT_SUCCESS
+ else:
+ rv = ImportStatus.IMPORT_NOCHANGE
+ if isinstance(lyrTransaction, bool):
+ # the transaction on lyr was already rolled back
+ lyrTransaction = False
except Exception: # pylint: disable=broad-exception-caught
- rv = False
+ rv = ImportStatus.IMPORT_ERROR
if isinstance(lyrTransaction, str):
query = 'ROLLBACK TO ' + lyrTransaction
logging.exception('Exception occured within transaction: %s', query)
@@ -523,17 +535,16 @@ def importSources(dso : gdal.Dataset, lyr : ogr.Layer,
try:
dso.ExecuteSQL(query)
except Exception: # pylint: disable=broad-exception-caught
- rv = False
+ rv = ImportStatus.IMPORT_ERROR
logging.exception('Could not execute SQL: %s', query)
elif isinstance(lyrTransaction, bool) and lyrTransaction:
try:
if lyr.CommitTransaction() != ogr.OGRERR_NONE:
- rv = False
+ rv = ImportStatus.IMPORT_ERROR
logging.error('Could not commit transaction')
except Exception: # pylint: disable=broad-exception-caught
- rv = False
+ rv = ImportStatus.IMPORT_ERROR
logging.exception('Could not commit transaction on layer "%s"', layername)
-
return rv
# pylint: disable-next=dangerous-default-value