Skip to content

Commit

Permalink
More verbose logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Oct 30, 2018
1 parent 1b3773a commit 282c764
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
36 changes: 20 additions & 16 deletions geoportal/c2cgeoportal_geoportal/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_url(url, request, default=None, errors=None):
server = request.registry.settings.get("servers", {}).get(obj.netloc)
if server is None:
if default is None and errors is not None:
errors.add("The server '{0!s}' is not found in the config".format(obj.netloc))
errors.add("The server '{}' is not found in the config".format(obj.netloc))
return default
else:
return "{0!s}{1!s}?{2!s}".format(server, obj.path, obj.query)
Expand Down Expand Up @@ -133,7 +133,10 @@ def get_url2(name, url, request, errors):
server = request.registry.settings.get("servers", {}).get(url_split.netloc)
if server is None:
errors.add(
"The server '{}' is not found in the config".format(url_split.netloc)
"{}: The server '{}' ({}) is not found in the config: [{}]".format(
name, url_split.netloc, url,
', '.join(request.registry.settings.get("servers", {}).keys())
)
)
return None
if url_split.path != "":
Expand All @@ -147,13 +150,14 @@ def get_url2(name, url, request, errors):
)


def get_typed(name, value, types, request, errors):
def get_typed(name, value, types, request, errors, layer_name=None):
prefix = "Layer '{}': ".format(layer_name) if layer_name is not None else ""
type_ = {
"type": "not init"
}
try:
if name not in types:
errors.add("Type '{}' not defined.".format(name))
errors.add("{}Type '{}' not defined.".format(prefix, name))
return None
type_ = types[name]
if type_.get("type", "string") == "string":
Expand All @@ -168,9 +172,9 @@ def get_typed(name, value, types, request, errors):
return False
else:
errors.add(
"The boolean attribute '{}'='{}' is not in "
"{}The boolean attribute '{}'='{}' is not in "
"[yes, y, on, 1, true, no, n, off, 0, false].".format(
name, value.lower()
prefix, name, value.lower()
)
)
elif type_["type"] == "integer":
Expand All @@ -182,8 +186,8 @@ def get_typed(name, value, types, request, errors):
value, default=datetime.datetime(1, 1, 1, 0, 0, 0)
)
if date.time() != datetime.time(0, 0, 0):
errors.add("The date attribute '{}'='{}' should not have any time".format(
name, value,
errors.add("{}The date attribute '{}'='{}' should not have any time".format(
prefix, name, value,
))
else:
return datetime.date.strftime(
Expand All @@ -194,8 +198,8 @@ def get_typed(name, value, types, request, errors):
value, default=datetime.datetime(1, 1, 1, 0, 0, 0)
)
if date.date() != datetime.date(1, 1, 1):
errors.add("The time attribute '{}'='{}' should not have any date".format(
name, value,
errors.add("{}The time attribute '{}'='{}' should not have any date".format(
prefix, name, value,
))
else:
return datetime.time.strftime(
Expand All @@ -209,21 +213,21 @@ def get_typed(name, value, types, request, errors):
date, "%Y-%m-%dT%H:%M:%S"
)
elif type_["type"] == "url":
return get_url2("The attribute '{}'".format(name), value, request, errors)
return get_url2("{}The attribute '{}'".format(prefix, name), value, request, errors)
elif type_["type"] == "json":
try:
return json.loads(value)
except Exception as e:
errors.append("The attribute '{}'='{}' has an error: {}".format(
name, value, str(e),
errors.append("{}The attribute '{}'='{}' has an error: {}".format(
prefix, name, value, str(e),
))
else:
errors.add("Unknown type '{}'.".format(type_["type"]))
errors.add("{}Unknown type '{}'.".format(prefix, type_["type"]))
except Exception as e:
errors.add(
"Unable to parse the attribute '{}'='{}' with the type '{}', error:\n{}"
"{}Unable to parse the attribute '{}'='{}' with the type '{}', error:\n{}"
.format(
name, value, type_.get("type", "string"), str(e)
prefix, name, value, type_.get("type", "string"), str(e)
)
)
return None
Expand Down
6 changes: 4 additions & 2 deletions geoportal/c2cgeoportal_geoportal/lib/functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ def _get_config_functionality(name, registered, types, request, errors):

if registered:
result = get_setting(
request.registry.settings, ("functionalities", "registered", name))
request.registry.settings, ("functionalities", "registered", name)
)
if result is None:
result = get_setting(
request.registry.settings, ("functionalities", "anonymous", name))
request.registry.settings, ("functionalities", "anonymous", name)
)

if result is None:
result = []
Expand Down
3 changes: 2 additions & 1 deletion geoportal/c2cgeoportal_geoportal/views/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def _get_metadata(self, item, metadata, errors):
None if len(metadatas) == 0 \
else get_typed(
metadata, metadatas[0].value,
self.metadata_type, self.request, errors
self.metadata_type, self.request, errors,
layer_name=item.name
)

def _get_metadatas(self, item, errors):
Expand Down
2 changes: 1 addition & 1 deletion geoportal/tests/functional/test_themes_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def static_url(url, **kwargs):
"The attribute 'url12'='static://test' cannot have an empty path.",
"The attribute 'url13'='static://test/' cannot have an empty path.",
"The attribute 'url14'='config:///static/icon.png' cannot have an empty netloc.",
"The server 'unknown_server' is not found in the config",
"The attribute 'url15': The server 'unknown_server' (config://unknown_server) is not found in the config: [server]",
"The attribute 'url16'='https://' is not a valid URL.",
"The attribute 'url17'='https:///' is not a valid URL.",
"The attribute 'url18'='https:///static' is not a valid URL.",
Expand Down
2 changes: 1 addition & 1 deletion geoportal/tests/test_get_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ def static_url(path, **kwargs):
self.assertEqual(get_url2("test", "https://example.com/icon.png", request, set()), "https://example.com/icon.png")
errors = set()
self.assertEqual(get_url2("test", "config://srv2/icon.png", request, errors=errors), None)
self.assertEqual(errors, set(["The server 'srv2' is not found in the config"]))
self.assertEqual(errors, set(["test: The server 'srv2' (config://srv2/icon.png) is not found in the config: [srv, srv_alt, full_url]"]))

0 comments on commit 282c764

Please sign in to comment.