fix links, logging

This commit is contained in:
Tom Kralidis
2018-04-05 16:42:09 +00:00
parent 8ebd980c76
commit c8b94c9a10
5 changed files with 58 additions and 39 deletions
+18 -18
View File
@@ -58,11 +58,13 @@ datasets:
- CRS84
links:
- type: text/csv
description: data
url: https://github.com/mapserver/mapserver/blob/branch-7-0/msautotest/wxs/data/obs.csv
rel: canonical
title: data
href: https://github.com/mapserver/mapserver/blob/branch-7-0/msautotest/wxs/data/obs.csv
- type: text/csv
description: data
url: https://raw.githubusercontent.com/mapserver/mapserver/branch-7-0/msautotest/wxs/data/obs.csv
rel: alternate
title: data
href: https://raw.githubusercontent.com/mapserver/mapserver/branch-7-0/msautotest/wxs/data/obs.csv
extents:
spatial:
bbox: [-180,-90,180,90]
@@ -85,11 +87,13 @@ datasets:
- CRS84
links:
- type: text/html
description: information
url: http://www.naturalearthdata.com/downloads/110m-cultural-vectors/110m-populated-places/
rel: canonical
title: information
href: http://www.naturalearthdata.com/downloads/110m-cultural-vectors/110m-populated-places/
- type: application/gzip
description: download
url: http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_populated_places_simple.zip
rel: canonical
title: download
href: http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_populated_places_simple.zip
extents:
spatial:
bbox: [-180,-90,180,90]
@@ -107,11 +111,9 @@ datasets:
- CRS84
links:
- type: text/html
description: information
url: http://www.naturalearthdata.com/
- type: text/html
description: download
url: http://www.naturalearthdata.com/
rel: canonical
title: information
href: http://www.naturalearthdata.com/
extents:
spatial:
bbox: [-180,-90,180,90]
@@ -134,11 +136,9 @@ datasets:
- CRS84
links:
- type: text/html
description: information
url: http://www.naturalearthdata.com/
- type: text/html
description: download
url: http://www.naturalearthdata.com/
rel: canonical
title: information
href: http://www.naturalearthdata.com/
extents:
spatial:
bbox: [-180,-90,180,90]
+27 -7
View File
@@ -35,6 +35,7 @@ import os
from jinja2 import Environment, FileSystemLoader
from pygeoapi import __version__
from pygeoapi.log import setup_logger
from pygeoapi.provider import load_provider
from pygeoapi.provider.base import ProviderConnectionError, ProviderQueryError
@@ -59,6 +60,8 @@ class API(object):
self.config = config
self.config['server']['url'] = self.config['server']['url'].rstrip('/')
setup_logger(config['logging'])
def root(self, headers, args):
"""
Provide API
@@ -131,7 +134,7 @@ class API(object):
"""
headers_ = {
'Content-type': 'application/json'
'Content-type': 'application/openapi+json;version=3.0'
}
return headers_, 200, json.dumps(openapi)
@@ -230,9 +233,10 @@ class API(object):
for link in v['links']:
lnk = {
'rel': 'alternate',
'type': link['type'],
'href': link['url']
'rel': link['rel'],
'title': link['title'],
'href': link['href']
}
collection['links'].append(lnk)
@@ -295,6 +299,13 @@ class API(object):
try:
bbox = args.get('bbox').split(',')
if len(bbox) != 4:
exception = {
'code': 'InvalidParameterValue',
'description': 'bbox values should be minx,miny,maxx,maxy'
}
LOGGER.error(exception)
return headers_, 400, json.dumps(exception)
except AttributeError:
bbox = []
@@ -333,20 +344,30 @@ class API(object):
LOGGER.error(exception)
return headers_, 500, json.dumps(exception)
prev = startindex - self.config['server']['limit']
next_ = startindex + self.config['server']['limit']
content['links'] = [{
'rel': 'self',
'type': 'application/json',
'rel': 'self',
'title': 'Collection items',
'href': '/collections/{}/items'.format(dataset)
}, {
'rel': 'next',
'type': 'application/json',
'rel': 'prev',
'title': 'items (prev)',
'href': '/collections/{}/items/?startindex={}'.format(dataset,
prev)
}, {
'type': 'application/json',
'rel': 'next',
'title': 'items (next)',
'href': '/collections/{}/items/?startindex={}'.format(dataset,
next_)
}, {
'rel': 'collection',
'type': 'application/json',
'title': 'Collection',
'rel': 'collection',
'href': '/collections/{}'.format(dataset)
}
]
@@ -425,6 +446,5 @@ def _render_j2_template(config, template, data):
"""
env = Environment(loader=FileSystemLoader(TEMPLATES))
print(TEMPLATES)
template = env.get_template(template)
return template.render(config=config, data=data, version=__version__)
+1 -2
View File
@@ -37,7 +37,6 @@ from flask import Flask, make_response, request
from flask_cors import CORS
from pygeoapi.api import API
from pygeoapi.log import setup_logger
APP = Flask(__name__)
APP.url_map.strict_slashes = False
@@ -134,6 +133,6 @@ def serve(ctx, debug=False):
if api_.config['server']['cors']:
CORS(APP)
setup_logger(CONFIG['logging'])
# setup_logger(CONFIG['logging'])
APP.run(debug=True, host=api_.config['server']['bind']['host'],
port=api_.config['server']['bind']['port'])
+7 -11
View File
@@ -44,6 +44,7 @@ def setup_logger(logging_config):
log_format = \
'[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s'
date_format = '%Y-%m-%dT%H:%M:%SZ'
loglevels = {
'CRITICAL': logging.CRITICAL,
@@ -53,20 +54,15 @@ def setup_logger(logging_config):
'DEBUG': logging.DEBUG,
'NOTSET': logging.NOTSET,
}
formatter = logging.Formatter(log_format)
log_handler = logging.NullHandler()
if 'level' in logging_config:
loglevel = loglevels[logging_config['level']]
log_handler = logging.StreamHandler(sys.stdout)
loglevel = loglevels[logging_config['level']]
if 'logfile' in logging_config:
log_handler = logging.FileHandler(logging_config['logfile'])
logging.basicConfig(level=loglevel, datefmt=date_format,
format=log_format, filename=logging_config['logfile'])
else:
logging.basicConfig(level=loglevel, datefmt=date_format,
format=log_format, stream=sys.stdout)
log_handler.setLevel(loglevel)
log_handler.setFormatter(formatter)
LOGGER.addHandler(log_handler)
LOGGER.debug('Logging initialized')
return
+5 -1
View File
@@ -14,13 +14,17 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
{% for link in data['links'] %}
<link rel="{{ link['rel'] }}" type="{{ link['type'] }}" title="{{ link['title'] }}" href="{{ link['href'] }}"/>
{% endfor %}
{% block extrahead %}
{% endblock %}
</head>
<body>
<header>
<h1><a title="{{ config['metadata']['identification']['title'] }}" href="{{ config['server']['url'] }}?f=html">{{ config['metadata']['identification']['title'] }}</a><a title="JSON" href="{{ config['server']['url'] }}"><img alt="JSON" src="{{ config['server']['url'] }}/static/img/json.png" width="30" height="30"/></a></h1>
<h1><a title="{{ config['metadata']['identification']['title'] }}" href="{{ config['server']['url'] }}/?f=html">{{ config['metadata']['identification']['title'] }}</a><a title="JSON" href="{{ config['server']['url'] }}/"><img alt="JSON" src="{{ config['server']['url'] }}/static/img/json.png" width="30" height="30"/></a></h1>
<span itemprop="description">{{ config['metadata']['identification']['description'] }}</span>
</header>