Skip to content

Commit

Permalink
Set proxied server name, async generate metadata file of layer
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Dec 23, 2019
1 parent 0a91ad5 commit c626c1f
Show file tree
Hide file tree
Showing 16 changed files with 410 additions and 16 deletions.
1 change: 1 addition & 0 deletions .env.demo
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ LAYMAN_SKIP_REDIS_LOADING=false

# Flask-style server name (domain and port)
LAYMAN_SERVER_NAME=layman:8000
LAYMAN_PROXY_SERVER_NAME=layman:8000

# internal settings
LAYMAN_TIMGEN_URL=http://hslayers:8080/
Expand Down
1 change: 1 addition & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ LAYMAN_SKIP_REDIS_LOADING=false

# Flask-style server name (domain and port)
LAYMAN_SERVER_NAME=layman_dev:8000
LAYMAN_PROXY_SERVER_NAME=layman_dev:8000

# internal settings
LAYMAN_TIMGEN_URL=http://hslayers:8080/
Expand Down
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ LAYMAN_SKIP_REDIS_LOADING=false

# Flask-style server name (domain and port)
LAYMAN_SERVER_NAME=layman_test_run_1:8000
LAYMAN_PROXY_SERVER_NAME=layman_test_run_1:8000

# internal settings
LAYMAN_TIMGEN_URL=http://hslayers:8080/
Expand Down
1 change: 1 addition & 0 deletions src/layman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

app = Flask(__name__)
app.secret_key = os.environ['FLASK_SECRET_KEY']
app.config['SERVER_NAME'] = settings.LAYMAN_PROXY_SERVER_NAME


from .http import LaymanError
Expand Down
File renamed without changes.
26 changes: 14 additions & 12 deletions src/layman/metadata/util.py → src/layman/common/metadata/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import template
from xml.etree import ElementTree as ET
from io import BytesIO


NAMESPACES = {
Expand Down Expand Up @@ -28,21 +28,23 @@ def indent(elem, level=0):
elem.tail = i


def fill_template(template_path, filled_path=None):
def fill_template(template_path, template_values):
with open(template_path, 'r') as template_file:
template_str = template_file.read()
defaults = template.get_layer_values()
xml_str = template_str.format(**defaults)
xml_str = template_str.format(**template_values)
root_el = ET.fromstring(xml_str)

# for k, v in namespace_map.items():
# root_el.attrib[f"xmlns:{k}"] = v
indent(root_el)
el_tree = ET.ElementTree(root_el)

if filled_path is not None:
el_tree.write(
filled_path,
encoding='UTF-8',
xml_declaration=True,
)
file_object = BytesIO()

el_tree.write(
file_object,
encoding='UTF-8',
xml_declaration=True,
)

file_object.seek(0)

return file_object
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from multiprocessing import Process
import pytest
import time
import os
import filecmp
import difflib

import sys
del sys.modules['layman']

from layman import app as app
from layman import settings
from layman.layer.filesystem.metadata import _get_template_values

from . import util

Expand Down Expand Up @@ -47,4 +51,20 @@ def app_context():

@pytest.mark.usefixtures('app_context')
def test_fill_template(client):
xmlstr = util.fill_template('src/layman/metadata/layer-template.xml', filled_path='src/layman/metadata/INSPIRE2-min.xml')
xml_path = 'tmp/metadata-template.xml'
try:
os.remove(xml_path)
except OSError:
pass
file_object = util.fill_template('src/layman/layer/filesystem/metadata-template.xml', _get_template_values())
with open(xml_path, 'wb') as out:
out.write(file_object.read())

def get_diff(p1, p2):
diff = difflib.unified_diff(open(p1).readlines(), open(p2).readlines())
return f"diff={''.join(diff)}"

expected_path = 'src/layman/common/metadata/util_test_filled_template.xml'
assert filecmp.cmp(xml_path, expected_path), get_diff(xml_path, expected_path)


260 changes: 260 additions & 0 deletions src/layman/common/metadata/util_test_filled_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
<?xml version='1.0' encoding='UTF-8'?>
<gmd:MD_Metadata xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20060504/gmd/metadataEntity.xsd http://www.isotc211.org/2005/gmx http://schemas.opengis.net/iso/19139/20060504/gmx/gmx.xsd">
<gmd:fileIdentifier>
<gco:CharacterString>mca238200-8200-1a23-9399-42c9fca53542</gco:CharacterString>
</gmd:fileIdentifier>
<gmd:language>
<gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/" codeListValue="cze">cze</gmd:LanguageCode>
</gmd:language>
<gmd:hierarchyLevel>
<gmd:MD_ScopeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_ScopeCode" codeListValue="dataset">dataset</gmd:MD_ScopeCode>
</gmd:hierarchyLevel>
<gmd:contact>
<gmd:CI_ResponsibleParty>
<gmd:organisationName gco:nilReason="unknown" />
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
<gmd:CI_Address>
<gmd:electronicMailAddress gco:nilReason="unknown" />
</gmd:CI_Address>
</gmd:address>
<gmd:onlineResource>
<gmd:CI_OnlineResource>
<gmd:linkage gco:nilReason="unknown" />
</gmd:CI_OnlineResource>
</gmd:onlineResource>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_RoleCode" codeListValue="pointOfContact">pointOfContact</gmd:CI_RoleCode>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:contact>
<gmd:dateStamp gco:nilReason="template" />
<gmd:referenceSystemInfo>
<gmd:MD_ReferenceSystem>
<gmd:referenceSystemIdentifier>
<gmd:RS_Identifier>
<gmd:code>
<gmx:Anchor xlink:href="http://www.opengis.net/def/crs/EPSG/0/3857">EPSG:3857</gmx:Anchor>
</gmd:code>
</gmd:RS_Identifier>
</gmd:referenceSystemIdentifier>
</gmd:MD_ReferenceSystem>
</gmd:referenceSystemInfo>
<gmd:referenceSystemInfo>
<gmd:MD_ReferenceSystem>
<gmd:referenceSystemIdentifier>
<gmd:RS_Identifier>
<gmd:code>
<gmx:Anchor xlink:href="http://www.opengis.net/def/crs/EPSG/0/4326">EPSG:4326</gmx:Anchor>
</gmd:code>
</gmd:RS_Identifier>
</gmd:referenceSystemIdentifier>
</gmd:MD_ReferenceSystem>
</gmd:referenceSystemInfo>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:citation>
<gmd:CI_Citation>
<gmd:title>
<gco:CharacterString>CORINE - Krajinný pokryv CLC 90</gco:CharacterString>
</gmd:title>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<gco:Date>2007-05-25</gco:Date>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode" codeListValue="revision">revision</gmd:CI_DateTypeCode>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
<gmd:identifier>
<gmd:MD_Identifier>
<gmd:code>
<gmx:Anchor xlink:href="http://www.env.cz/data/corine/1990">MZP-CORINE</gmx:Anchor>
</gmd:code>
</gmd:MD_Identifier>
</gmd:identifier>
</gmd:CI_Citation>
</gmd:citation>
<gmd:abstract gco:nilReason="unknown" />
<gmd:pointOfContact>
<gmd:CI_ResponsibleParty>
<gmd:organisationName gco:nilReason="unknown" />
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
<gmd:CI_Address>
<gmd:electronicMailAddress gco:nilReason="unknown" />
</gmd:CI_Address>
</gmd:address>
<gmd:onlineResource>
<gmd:CI_OnlineResource>
<gmd:linkage gco:nilReason="unknown" />
</gmd:CI_OnlineResource>
</gmd:onlineResource>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_RoleCode" codeListValue="custodian">custodian</gmd:CI_RoleCode>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:pointOfContact>
<gmd:graphicOverview>
<gmd:MD_BrowseGraphic>
<gmd:fileName>
<gco:CharacterString>http://layman_test_run_1:8000/rest/browser/layers/layer/thumbnail</gco:CharacterString>
</gmd:fileName>
<gmd:fileType>
<gco:CharacterString>PNG</gco:CharacterString>
</gmd:fileType>
</gmd:MD_BrowseGraphic>
</gmd:graphicOverview>
<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
<gmd:keyword gco:nilReason="unknown" />
<gmd:thesaurusName>
<gmd:CI_Citation>
<gmd:title>
<gmx:Anchor xlink:href="http://www.eionet.europa.eu/gemet/inspire_themes">GEMET - INSPIRE themes, version 1.0</gmx:Anchor>
</gmd:title>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<gco:Date>2008-06-01</gco:Date>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode" codeListValue="publication">publication</gmd:CI_DateTypeCode>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
</gmd:CI_Citation>
</gmd:thesaurusName>
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>
<gmd:resourceConstraints>
<gmd:MD_LegalConstraints>
<gmd:accessConstraints>
<gmd:MD_RestrictionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_RestrictionCode" codeListValue="otherRestrictions">otherRestrictions</gmd:MD_RestrictionCode>
</gmd:accessConstraints>
<gmd:otherConstraints>
<gmx:Anchor xlink:href="http://inspire.ec.europa.eu/metadata-codelist/LimitationsOnPublicAccess/noLimitations">Bez omezení</gmx:Anchor>
</gmd:otherConstraints>
</gmd:MD_LegalConstraints>
</gmd:resourceConstraints>
<gmd:resourceConstraints>
<gmd:MD_LegalConstraints>
<gmd:useConstraints>
<gmd:MD_RestrictionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_RestrictionCode" codeListValue="otherRestrictions">otherRestrictions</gmd:MD_RestrictionCode>
</gmd:useConstraints>
<gmd:otherConstraints>
<gmx:Anchor xlink:href="http://inspire.ec.europa.eu/metadata-codelist/ConditionsApplyingToAccessAndUse/noConditionsApply">Žádné podmínky neplatí</gmx:Anchor>
</gmd:otherConstraints>
</gmd:MD_LegalConstraints>
</gmd:resourceConstraints>
<gmd:spatialRepresentationType>
<gmd:MD_SpatialRepresentationTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_SpatialRepresentationTypeCode" codeListValue="vector">vector</gmd:MD_SpatialRepresentationTypeCode>
</gmd:spatialRepresentationType>
<gmd:spatialResolution>
<gmd:MD_Resolution>
<gmd:equivalentScale>
<gmd:MD_RepresentativeFraction>
<gmd:denominator gco:nilReason="unknown" />
</gmd:MD_RepresentativeFraction>
</gmd:equivalentScale>
</gmd:MD_Resolution>
</gmd:spatialResolution>
<gmd:language gco:nilReason="unknown" />
<gmd:characterSet>
<gmd:MD_CharacterSetCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_CharacterSetCode" codeListValue="utf8">utf8</gmd:MD_CharacterSetCode>
</gmd:characterSet>
<gmd:topicCategory gco:nilReason="unknown" />
<gmd:extent>
<gmd:EX_Extent>
<gmd:geographicElement>
<gmd:EX_GeographicBoundingBox>
<gmd:westBoundLongitude>
<gco:Decimal>11.87</gco:Decimal>
</gmd:westBoundLongitude>
<gmd:eastBoundLongitude>
<gco:Decimal>19.13</gco:Decimal>
</gmd:eastBoundLongitude>
<gmd:southBoundLatitude>
<gco:Decimal>48.12</gco:Decimal>
</gmd:southBoundLatitude>
<gmd:northBoundLatitude>
<gco:Decimal>51.59</gco:Decimal>
</gmd:northBoundLatitude>
</gmd:EX_GeographicBoundingBox>
</gmd:geographicElement>
</gmd:EX_Extent>
</gmd:extent>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
<gmd:distributionInfo>
<gmd:MD_Distribution>
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://www.env.cz/corine/data/download.zip</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gmx:Anchor xlink:href="https://services.cuzk.cz/registry/codelist/OnlineResourceProtocolValue/OGC:WMS-1.3.0">OGC:WMS-1.3.0</gmx:Anchor>
</gmd:protocol>
<gmd:function>
<gmd:CI_OnLineFunctionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_OnLineFunctionCode" codeListValue="download">download</gmd:CI_OnLineFunctionCode>
</gmd:function>
</gmd:CI_OnlineResource>
</gmd:onLine>
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://www.env.cz/corine/data/download.zip</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gmx:Anchor xlink:href="https://services.cuzk.cz/registry/codelist/OnlineResourceProtocolValue/OGC:WFS-2.0.0">OGC:WFS-2.0.0</gmx:Anchor>
</gmd:protocol>
<gmd:function>
<gmd:CI_OnLineFunctionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_OnLineFunctionCode" codeListValue="download">download</gmd:CI_OnLineFunctionCode>
</gmd:function>
</gmd:CI_OnlineResource>
</gmd:onLine>
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://layman_test_run_1:8000/rest/browser/layers/layer</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gmx:Anchor xlink:href="https://services.cuzk.cz/registry/codelist/OnlineResourceProtocolValue/WWW:LINK-1.0-http--link">WWW:LINK-1.0-http--link</gmx:Anchor>
</gmd:protocol>
<gmd:function>
<gmd:CI_OnLineFunctionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_OnLineFunctionCode" codeListValue="information">information</gmd:CI_OnLineFunctionCode>
</gmd:function>
</gmd:CI_OnlineResource>
</gmd:onLine>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</gmd:MD_Distribution>
</gmd:distributionInfo>
<gmd:dataQualityInfo>
<gmd:DQ_DataQuality>
<gmd:scope>
<gmd:DQ_Scope>
<gmd:level>
<gmd:MD_ScopeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_ScopeCode" codeListValue="dataset">dataset</gmd:MD_ScopeCode>
</gmd:level>
</gmd:DQ_Scope>
</gmd:scope>
<gmd:lineage>
<gmd:LI_Lineage>
<gmd:statement gco:nilReason="unknown" />
</gmd:LI_Lineage>
</gmd:lineage>
</gmd:DQ_DataQuality>
</gmd:dataQualityInfo>
</gmd:MD_Metadata>
1 change: 1 addition & 0 deletions src/layman/layer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get_layer_sources():
'layman.layer.geoserver.wms',
'layman.layer.geoserver.sld',
'layman.layer.filesystem.thumbnail',
'layman.layer.filesystem.metadata',
],
'task_modules': [
'layman.layer.db.tasks',
Expand Down
File renamed without changes.
Loading

0 comments on commit c626c1f

Please sign in to comment.