Skip to content

Commit

Permalink
dynamic style types
Browse files Browse the repository at this point in the history
  • Loading branch information
petrus7 committed Jun 4, 2020
1 parent 71ec8a7 commit c088564
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/geoserver/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ def get_styles(self, names=None, workspaces=None):
# Add global styles
url = "{}/styles.xml".format(self.service_url)
styles = self.get_xml(url)
all_styles.extend([Style(self, s.find('name').text) for s in styles.findall("style")])
all_styles.extend(self.__build_style_list(styles))
workspaces = []
elif isinstance(workspaces, string_types):
workspaces = [s.strip() for s in workspaces.split(',') if s.strip()]
Expand All @@ -1069,8 +1069,7 @@ def get_styles(self, names=None, workspaces=None):
continue
else:
raise FailedRequestError("Failed to get styles: {}".format(e))

all_styles.extend([Style(self, s.find("name").text, _name(ws)) for s in styles.findall("style")])
all_styles.extend(self.__build_style_list(styles, ws))

if names is None:
names = []
Expand All @@ -1082,6 +1081,15 @@ def get_styles(self, names=None, workspaces=None):

return all_styles

def __build_style_list(self, styles_tree, ws=None):
all_styles = []
for s in styles_tree.findall("style"):
style_format = self.get_xml(s[1].attrib.get('href')).find('format').text
style_version = self.get_xml(s[1].attrib.get('href')).find('languageVersion').find(
'version').text.replace('.', '')[:-1]
all_styles.append(Style(self, s.find("name").text, _name(ws), style_format + style_version))
return all_styles

def get_style(self, name, workspace=None):
'''
returns a single style object.
Expand Down
11 changes: 9 additions & 2 deletions src/geoserver/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@


class Style(ResourceInfo):
supported_formats = ["sld10", "sld11", "zip"]
supported_formats = ["sld10", "sld11", "zip10", "css10"]
content_types = {
"sld10": "application/vnd.ogc.sld+xml",
"sld11": "application/vnd.ogc.se+xml",
"zip": "application/zip"
"zip10": "application/zip",
"css10": "application/vnd.geoserver.geocss+css",

}

def __init__(self, catalog, name, workspace=None, style_format="sld10"):
Expand Down Expand Up @@ -114,6 +116,11 @@ def sld_body(self):
resp = self.catalog.http_request(self.body_href)
return resp.content

@property
def body(self):
resp = self.catalog.http_request(self._build_href('.{}'.format(self.style_format)))
return resp.content

def update_body(self, body):
headers = {"Content-Type": self.content_type}
self.catalog.http.request(
Expand Down

0 comments on commit c088564

Please sign in to comment.