Skip to content

Commit

Permalink
Fix some flake8 warnings after the rebase on master
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Jun 11, 2021
1 parent fd3eabe commit 9317102
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -49,7 +49,7 @@ Once installed, the `wmtscache` cache command can be used to manage the cache co
- list cache content infos
- delete project cache content
- delete specific layer cached tiles

## WMTS Cache manager API

The WMTS Cache manager API provides these URLs:
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Expand Up @@ -22,6 +22,8 @@ ignore =
E231,
# E241 multiple spaces after ','
E241,
# E251 unexpected spaces around keyword / parameter equals
E251,
# E252 missing whitespace around parameter equals
E252,
# E302 expected 2 blank lines
Expand Down
24 changes: 11 additions & 13 deletions tests/test_wmts_cachemngrapi.py
@@ -1,14 +1,12 @@
import sys
import os
import logging
import json
import lxml.etree
import logging
import os

from shutil import rmtree

from qgis.core import Qgis, QgsProject
from qgis.server import (QgsBufferServerRequest,
QgsBufferServerResponse)
import lxml.etree

from qgis.core import QgsProject

LOGGER = logging.getLogger('server')

Expand Down Expand Up @@ -125,7 +123,7 @@ def test_wmts_cachemngrapi_cache_info(client):
qs = "?" + "&".join("%s=%s" % item for item in parameters.items())
rv = client.get(qs, project.fileName())

original_content = rv.content
# original_content = rv.content

if rv.status_code != 200:
LOGGER.error(lxml.etree.tostring(rv.xml, pretty_print=True))
Expand Down Expand Up @@ -369,7 +367,7 @@ def test_wmts_cachemngrapi_delete_layer(client):
qs = "?" + "&".join("%s=%s" % item for item in parameters.items())
rv = client.get(qs, project.fileName())

original_content = rv.content
# original_content = rv.content

if rv.status_code != 200:
LOGGER.error(lxml.etree.tostring(rv.xml, pretty_print=True))
Expand Down Expand Up @@ -491,7 +489,7 @@ def test_wmts_cachemngrapi_delete_layers(client):
qs = "?" + "&".join("%s=%s" % item for item in parameters.items())
rv = client.get(qs, project.fileName())

original_content = rv.content
# original_content = rv.content

if rv.status_code != 200:
LOGGER.error(lxml.etree.tostring(rv.xml, pretty_print=True))
Expand Down Expand Up @@ -623,7 +621,7 @@ def test_wmts_cachemngrapi_delete_collection(client):
qs = "?" + "&".join("%s=%s" % item for item in parameters.items())
rv = client.get(qs, project.fileName())

original_content = rv.content
# original_content = rv.content

if rv.status_code != 200:
LOGGER.error(lxml.etree.tostring(rv.xml, pretty_print=True))
Expand Down Expand Up @@ -759,7 +757,7 @@ def test_wmts_cachemngrapi_layerid_error(client):
qs = "?" + "&".join("%s=%s" % item for item in parameters.items())
rv = client.get(qs, project.fileName())

original_content = rv.content
# original_content = rv.content

if rv.status_code != 200:
LOGGER.error(lxml.etree.tostring(rv.xml, pretty_print=True))
Expand Down Expand Up @@ -850,4 +848,4 @@ def test_wmts_cachemngrapi_collectionid_error(client):

json_content = json.loads(rv.content)
assert 'code' in json_content
assert json_content['code'] == 'API not found error'
assert json_content['code'] == 'API not found error'
60 changes: 33 additions & 27 deletions wmtsCacheServer/cachemngrapi.py
Expand Up @@ -3,19 +3,16 @@
from pathlib import Path
from shutil import rmtree

from qgis.PyQt.QtCore import (
QRegularExpression,
)

from qgis.PyQt.QtCore import QRegularExpression
from qgis.server import (
QgsServerException,
QgsServerOgcApiHandler,
QgsServerOgcApi,
QgsServerOgcApiHandler,
QgsServerRequest,
)

from .helper import CacheHelper


def read_metadata(rootdir: Path) -> dict:
""" Read metadata
"""
Expand All @@ -32,18 +29,18 @@ def read_metadata(rootdir: Path) -> dict:
h = d.name

tiledir = d / 'tiles'
layers = [l.name for l in tiledir.glob('*') if l.is_dir()]
layers = [layer.name for layer in tiledir.glob('*') if layer.is_dir()]

data[h] = {
'project': c.read_text(),
'layers': layers,
'project': c.read_text(),
'layers': layers,
}
#metadata.update(data=data)
# metadata.update(data=data)
metadata['data'] = data
return metadata


class QgsServerApiException():
class QgsServerApiException:

def __init__(self, code, message, mime_type = 'application/json', response_code = 200):
self.code = code
Expand Down Expand Up @@ -82,7 +79,7 @@ def sendException(self, ex, context):
resp_content, mime_type = ex.formatResponse()
resp = context.response()
resp.clear()
resp.setStatusCode(ex.responseCode());
resp.setStatusCode(ex.responseCode())
resp.setHeader("Content-Type", mime_type)
resp.write(resp_content)

Expand All @@ -91,7 +88,7 @@ class CacheMngrLandingPageHandler(CacheMngrApiHandler):
"""Project listing handler"""

def path(self):
return QRegularExpression("(\.json|\.html|/)")
return QRegularExpression(r"(\.json|\.html|/)")

def operationId(self):
return "getLandingPage"
Expand All @@ -112,7 +109,7 @@ def handleRequest(self, context):
"""List projects"""

data = {
"links": [] #self.links(context)
"links": [] # self.links(context)
}
data['links'].append({
"href": self.href(context, "/collections"),
Expand Down Expand Up @@ -140,7 +137,7 @@ class CacheMngrCollectionsHandler(CacheMngrApiHandler):
"""Project listing handler"""

def path(self):
return QRegularExpression("/collections(\.json|\.html|/)")
return QRegularExpression(r"/collections(\.json|\.html|/)")

def operationId(self):
return "describeCollections"
Expand All @@ -165,7 +162,7 @@ def handleRequest(self, context):
data = {
"cache_layout": metadata['layout'],
"collections": [],
"links": [] #self.links(context),
"links": [] # self.links(context),
}

for h, v in metadata['data'].items():
Expand Down Expand Up @@ -202,7 +199,7 @@ class CacheMngrCollectionHandler(CacheMngrApiHandler):
"""Project listing handler"""

def path(self):
return QRegularExpression("/collections/(?<collectionId>[^/]+?)(\.json|\.html|/)")
return QRegularExpression(r"/collections/(?<collectionId>[^/]+?)(\.json|\.html|/)")

def operationId(self):
return "describeCollection"
Expand Down Expand Up @@ -266,13 +263,17 @@ def handleRequest(self, context):
data['layers'].append({
'id': layer,
'links': [{
"href": self.href(context, "/layers/{}".format(layer), QgsServerOgcApi.contentTypeToExtension(QgsServerOgcApi.JSON)),
"href": self.href(
context,
"/layers/{}".format(layer),
QgsServerOgcApi.contentTypeToExtension(QgsServerOgcApi.JSON)
),
"rel": QgsServerOgcApi.relToString(QgsServerOgcApi.item),
"type": QgsServerOgcApi.mimeType(QgsServerOgcApi.JSON),
"title": "Cache layer",
}]
})
data['links'] = [] #self.links(context)
data['links'] = [] # self.links(context)
data['links'].append({
"href": self.href(context, "/docs", QgsServerOgcApi.contentTypeToExtension(QgsServerOgcApi.JSON)),
"rel": QgsServerOgcApi.relToString(QgsServerOgcApi.item),
Expand Down Expand Up @@ -311,7 +312,7 @@ class CacheMngrCollectionDocsHandler(CacheMngrApiHandler):
"""Project listing handler"""

def path(self):
return QRegularExpression("/collections/(?<collectionId>[^/]+?)/docs(\.json|\.html|/)")
return QRegularExpression(r"/collections/(?<collectionId>[^/]+?)/docs(\.json|\.html|/)")

def operationId(self):
return "describeDocs"
Expand Down Expand Up @@ -362,7 +363,7 @@ def handleRequest(self, context):
data['id'] = h
data['project'] = project
data['documents'] = 0
data['links'] = [] #self.links(context)
data['links'] = [] # self.links(context)

docroot = cache.get_documents_root(project)
for _ in docroot.glob('*.xml'):
Expand Down Expand Up @@ -396,7 +397,7 @@ class CacheMngrCollectionLayersHandler(CacheMngrApiHandler):
"""Project listing handler"""

def path(self):
return QRegularExpression("/collections/(?<collectionId>[^/]+?)/layers(\.json|\.html|/)")
return QRegularExpression(r"/collections/(?<collectionId>[^/]+?)/layers(\.json|\.html|/)")

def operationId(self):
return "describeLayers"
Expand Down Expand Up @@ -450,13 +451,17 @@ def handleRequest(self, context):
data['layers'].append({
'id': layer,
'links': [{
"href": self.href(context, "/layers/{}".format(layer), QgsServerOgcApi.contentTypeToExtension(QgsServerOgcApi.JSON)),
"href": self.href(
context,
"/layers/{}".format(layer),
QgsServerOgcApi.contentTypeToExtension(QgsServerOgcApi.JSON)
),
"rel": QgsServerOgcApi.relToString(QgsServerOgcApi.item),
"type": QgsServerOgcApi.mimeType(QgsServerOgcApi.JSON),
"title": "Cache layer",
}]
})
data['links'] = [] #self.links(context)
data['links'] = [] # self.links(context)

html_metadata = {
"pageTitle": self.linkTitle(),
Expand Down Expand Up @@ -486,7 +491,7 @@ class CacheMngrCollectionLayerHandler(CacheMngrApiHandler):
"""Project listing handler"""

def path(self):
return QRegularExpression("/collections/(?<collectionId>[^/]+?)/layers/(?<layerId>[^/]+?)(\.json|\.html|/)")
return QRegularExpression(r"/collections/(?<collectionId>[^/]+?)/layers/(?<layerId>[^/]+?)(\.json|\.html|/)")

def operationId(self):
return "describeLayer"
Expand Down Expand Up @@ -541,7 +546,7 @@ def handleRequest(self, context):
self.write(data, context)
else:
data['id'] = layer_id
data['links'] = [] #self.links(context)
data['links'] = [] # self.links(context)

html_metadata = {
"pageTitle": self.linkTitle(),
Expand Down Expand Up @@ -569,6 +574,7 @@ def templatePath(self, context):
def parameters(self, context):
return []


class CacheMngrApi(QgsServerOgcApi):

def __init__(self, serverIface, rootpath):
Expand All @@ -581,4 +587,4 @@ def __init__(self, serverIface, rootpath):
self.registerHandler(CacheMngrCollectionHandler(rootpath))
self.registerHandler(CacheMngrCollectionsHandler(rootpath))
self.registerHandler(CacheMngrLandingPageHandler(rootpath))
self.rootpath = rootpath
self.rootpath = rootpath

0 comments on commit 9317102

Please sign in to comment.