aboutsummaryrefslogtreecommitdiffstats
path: root/webmap-download
diff options
context:
space:
mode:
Diffstat (limited to 'webmap-download')
-rwxr-xr-xwebmap-download42
1 files changed, 20 insertions, 22 deletions
diff --git a/webmap-download b/webmap-download
index 8897cf4..edb624e 100755
--- a/webmap-download
+++ b/webmap-download
@@ -18,7 +18,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#----------------------------------------------------------------------
-# pylint: disable=invalid-name,missing-module-docstring
+# pylint: disable=invalid-name, missing-module-docstring, fixme
# pylint: enable=invalid-name
from os import (
@@ -49,6 +49,7 @@ from typing import Optional, NoReturn, Never
import requests
import common
+from common import BadConfiguration
def download_trystream(url : str, **kwargs) -> requests.Response:
"""GET a url, trying a number of times. Return immediately after the
@@ -170,13 +171,6 @@ def download(dest : str,
common.format_time(elapsed),
common.format_bytes(int(size/elapsed)))
-class BadConfiguration(Exception):
- """Exception raised when there is a bad configuration"""
- def __init__(self, message : str, config_path : Optional[Path] = None) -> Never:
- if config_path is not None:
- message = str(config_path) + ': ' + message
- super().__init__(message)
-
def _check_key_type(k : str, v : str, known_keys : list[type, tuple[set[str]]]) -> bool:
for t, ks in known_keys:
if k in ks and isinstance(v, t):
@@ -235,7 +229,8 @@ def parse_config_dl(downloads) -> dict[str, dict[str, str|int]]:
return destinations
-def main() -> NoReturn: # pylint: disable=missing-function-docstring
+# pylint: disable-next=missing-function-docstring
+def main() -> NoReturn:
common.init_logger(app=os_path.basename(__file__), level=logging.INFO)
parser = argparse.ArgumentParser(description='Download or update GIS layers.')
@@ -254,7 +249,7 @@ def main() -> NoReturn: # pylint: disable=missing-function-docstring
parser.add_argument('groupname', nargs='*', help='group layer name(s) to process')
args = parser.parse_args()
- if args.debug > 0:
+ if args.debug > 0: # pylint: disable=duplicate-code
logging.getLogger().setLevel(logging.DEBUG)
if args.debug > 1:
from http.client import HTTPConnection # pylint: disable=import-outside-toplevel
@@ -269,19 +264,22 @@ def main() -> NoReturn: # pylint: disable=missing-function-docstring
rv = 0
download_paths = set()
for layername, layerdef in config.get('layers', {}).items():
- source = layerdef.get('source', None)
- if source is None:
- logging.error('Layer "%s" has no source, ignoring', layername)
- rv = 1
+ sources = layerdef.get('sources', None)
+ if sources is None or len(sources) < 1:
+ logging.warning('Layer "%s" has no source, ignoring', layername)
continue
- path = source.get('path', None)
- if path is None:
- logging.error('Layer "%s" has no source path, ignoring', layername)
- rv = 1
- elif path not in downloads:
- logging.warning('Ignoring unknown source of path "%s" from layer "%s"', path, layername)
- else:
- download_paths.add(path)
+ for idx, source in enumerate(sources):
+ source = source.get('source', None)
+ path = None if source is None else source.get('path', None)
+ if path is None:
+ logging.error('Source #%d of layer "%s" has no path, ignoring',
+ idx, layername)
+ rv = 1
+ elif path not in downloads:
+ logging.warning('Ignoring unknown source of path "%s" from layer "%s"',
+ path, layername)
+ else:
+ download_paths.add(path)
if args.quiet or not sys.stderr.isatty():
pbar = None