-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
546 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
from .common import KeyDollarListDict | ||
from .dataStore import PostGisDataStore | ||
from .dataStores import DataStores | ||
from .style import Style | ||
from .styles import Styles | ||
from .workspace import Workspace | ||
from .workspaces import Workspaces | ||
|
||
__all__ = [ | ||
"DataStores", | ||
"KeyDollarListDict", | ||
"PostGisDataStore", | ||
"Style", | ||
"Styles", | ||
"Workspaces", | ||
"Workspace", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
import logging | ||
|
||
import jsonschema | ||
import requests | ||
|
||
log = logging.getLogger() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import json | ||
|
||
import xmltodict | ||
|
||
|
||
class Style: | ||
|
||
def __init__( | ||
self, | ||
name: str, | ||
workspace: str | None = None, | ||
format: str | None = "sld", | ||
language_version: dict | None = {"version": "1.0.0"}, | ||
filename: str | None = None, | ||
date_created: str | None = None, | ||
date_modified: str | None = None, | ||
legend_url: str | None = None, | ||
legend_format: str | None = None, | ||
legend_width: str | None = None, | ||
legend_height: str | None = None, | ||
) -> None: | ||
self._workspace = workspace | ||
self._name = name | ||
self._format = format | ||
self._language_version = language_version | ||
self._filename = filename | ||
self._date_created = date_created | ||
self._date_modified = date_modified | ||
self.create_legend(legend_url, legend_format, legend_width, legend_height) | ||
|
||
# create one property for each attribute | ||
@property | ||
def workspace(self): | ||
return self._workspace | ||
|
||
@property | ||
def name(self): | ||
return self._name | ||
|
||
@property | ||
def format(self): | ||
return self._format | ||
|
||
@property | ||
def language_version(self): | ||
return self._language_version | ||
|
||
@property | ||
def filename(self): | ||
return self._filename | ||
|
||
@property | ||
def date_created(self): | ||
return self._date_created | ||
|
||
@property | ||
def date_modified(self): | ||
return self._date_modified | ||
|
||
@property | ||
def legend(self): | ||
return self._legend | ||
|
||
def create_legend(self, url, image_format, width, height): | ||
if any([url, image_format, width, height]): | ||
self._legend = {} | ||
if url: | ||
self.legend["onlineResource"] = url | ||
if image_format: | ||
self.legend["format"] = image_format | ||
if width: | ||
self.legend["width"] = width | ||
if height: | ||
self.legend["height"] = height | ||
else: | ||
self._legend = None | ||
|
||
def put_payload(self): | ||
payload = { | ||
"style": { | ||
"name": self.name, | ||
"format": self.format, | ||
"languageVersion": self.language_version, | ||
"filename": self.filename, | ||
} | ||
} | ||
if self.legend: | ||
payload["style"]["legend"] = self.legend | ||
return payload | ||
|
||
def post_payload(self): | ||
return self.put_payload() | ||
|
||
@classmethod | ||
def from_response(cls, response): | ||
json_data = response.json() | ||
style_data = json_data.get("style", {}) | ||
return cls( | ||
workspace=style_data.get("workspace"), | ||
name=style_data.get("name"), | ||
format=style_data.get("format"), | ||
language_version=style_data.get("languageVersion", None), | ||
filename=style_data.get("filename"), | ||
date_created=style_data.get("dateCreated"), | ||
date_modified=style_data.get("dateModified"), | ||
legend_url=style_data.get("legend", {}).get("onlineResource"), | ||
legend_format=style_data.get("legend", {}).get("format"), | ||
legend_width=style_data.get("legend", {}).get("width"), | ||
legend_height=style_data.get("legend", {}).get("height"), | ||
) | ||
|
||
def xml_post_payload(self): | ||
return xmltodict.unparse(self.post_payload()).split("\n", 1)[1] | ||
|
||
def xml_put_payload(self): | ||
return xmltodict.unparse(self.put_payload()).split("\n", 1)[1] | ||
|
||
def __repr__(self): | ||
return json.dumps(self.put_payload(), indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Styles: | ||
|
||
def __init__(self, styles: list[str], workspace: str | None = None) -> None: | ||
self._workspace = workspace | ||
self._styles = styles | ||
|
||
@property | ||
def workspace(self): | ||
return self._workspace | ||
|
||
@property | ||
def styles(self): | ||
return self._styles | ||
|
||
@classmethod | ||
def from_response(cls, response): | ||
json_data = response.json() | ||
styles = [] | ||
try: | ||
workspace = json_data["styles"]["workspace"] | ||
except KeyError: | ||
workspace = None | ||
try: | ||
for style in json_data.get("styles", {}).get("style", []): | ||
styles.append(style["name"]) | ||
except AttributeError: | ||
styles = [] | ||
return cls(styles, workspace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
import logging | ||
|
||
import jsonschema | ||
import requests | ||
|
||
log = logging.getLogger() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.