aboutsummaryrefslogtreecommitdiffstats
path: root/webmap-import
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2025-05-27 23:20:26 +0200
committerGuilhem Moulin <guilhem@fripost.org>2025-06-04 15:16:29 +0200
commit052536f62d2e58f6b9b142e035c49cb033458d7f (patch)
tree9487344ce453dfa3493dc2a0c9dd899a0070cfb5 /webmap-import
parent3e9586f0a9708afca40ab50a2987fc0090256e2f (diff)
MVT: Generate metadata.json with copyright and timing information.
So the information can be exposed to the webmap's info dialog.
Diffstat (limited to 'webmap-import')
-rwxr-xr-xwebmap-import30
1 files changed, 29 insertions, 1 deletions
diff --git a/webmap-import b/webmap-import
index c86e7a2..e5a1426 100755
--- a/webmap-import
+++ b/webmap-import
@@ -47,6 +47,7 @@ from osgeo import gdalconst
import common
from common import (
BadConfiguration,
+ parse_config_dl,
escape_identifier,
escape_literal_str,
getSourcePathLockFileName
@@ -524,6 +525,26 @@ def areSourceFilesNewer(layername : str,
source_path, dt.astimezone().isoformat(timespec='seconds'))
return ret
+def getLastMTimes(layerdefs : dict[str,Any], basedir : Optional[Path] = None) -> dict[str,int]:
+ """Return a directing mapping source paths to their last modification time
+ (as a timestamp in milliseconds)."""
+ ret = {}
+ for layerdef in layerdefs:
+ for source in layerdef['sources']:
+ source_path = source['source']['path']
+ if source_path in ret:
+ continue
+ path = source_path if basedir is None else str(basedir.joinpath(source_path))
+ try:
+ st = os.stat(path)
+ if not S_ISREG(st.st_mode):
+ raise FileNotFoundError
+ ret[source_path] = st.st_mtime_ns // 1000000
+ except (OSError, ValueError):
+ #logging.warning('Could not stat(%s)', path)
+ pass
+ return ret
+
def lockSourcePaths(layerdefs : dict[str,Any], lockdir: str) -> dict[str,int]:
"""Place shared locks on each source path and return their respective file
descriptors. We could do that one layerdef at a time (one output layer at a
@@ -703,6 +724,9 @@ def main() -> NoReturn:
elapsed = time_monotonic() - start
logging.info('Processed %d destination layers in %s', n, common.format_time(elapsed))
+ # get mtimes before releasing the source locks
+ last_modified = getLastMTimes(layerdefs=layers.values(), basedir=args.cachedir)
+
if sourcePathLocks is not None:
releaseSourcePathLocks(sourcePathLocks)
@@ -716,7 +740,11 @@ def main() -> NoReturn:
logging.info('Skipping MVT export for group %s (no changes)',
', '.join(args.groupname) if args.groupname is not None else '*')
else:
- exportMVT(dso, layers=export_layers,
+ exportMVT(dso,
+ layers=export_layers,
+ sources=parse_config_dl(config.get('downloads', [])),
+ license_info=config.get('license-info', {}),
+ last_modified=last_modified,
dst=args.mvtdir,
default_options=config.get('vector-tiles', None),
compress=args.mvt_compress)