Skip to content

Commit

Permalink
Support empty workspace, datastores, styles
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilleumierc committed Nov 14, 2024
1 parent 30b3bf0 commit 623507c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
32 changes: 20 additions & 12 deletions geoservercloud/geoservercloudsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def copy_pg_datastores(
datastores, status_code = self.src_instance.get_datastores(workspace_name)
if isinstance(datastores, str):
return datastores, status_code
elif datastores.aslist() == []:
return "", status_code
for datastore_name in datastores.aslist():
content, status_code = self.copy_pg_datastore(
workspace_name, datastore_name, deep_copy=deep_copy
Expand Down Expand Up @@ -119,6 +121,8 @@ def copy_feature_types(
)
if isinstance(feature_types, str):
return feature_types, status_code
elif feature_types.aslist() == []:
return "", status_code
for feature_type in feature_types.aslist():
content, status_code = self.copy_feature_type(
workspace_name, datastore_name, feature_type["name"]
Expand Down Expand Up @@ -165,17 +169,19 @@ def copy_styles(
"""
Copy all styles in a workspace (if a workspace is provided) or all global styles
"""
if include_images:
content, status_code = self.copy_style_images(workspace_name)
if self.not_ok(status_code):
return content, status_code
styles, status_code = self.src_instance.get_styles(workspace_name)
if isinstance(styles, str):
return styles, status_code
elif styles.aslist() == []:
return "", status_code
for style in styles.aslist():
content, status_code = self.copy_style(style, workspace_name)
if self.not_ok(status_code):
return content, status_code
if include_images:
content, status_code = self.copy_style_images(workspace_name)
if self.not_ok(status_code):
return content, status_code
return content, status_code

def copy_style(
Expand All @@ -200,14 +206,16 @@ def copy_style_images(self, workspace_name: str | None = None) -> tuple[str, int
)
if isinstance(resource_dir, str):
return resource_dir, status_code
for child in resource_dir.children:
if child.is_image():
content, status_code = self.copy_resource(
resource_dir="styles",
resource_name=child.name,
content_type=child.type,
workspace_name=workspace_name,
)
images = [child for child in resource_dir.children if child.is_image()]
if images == []:
return "", status_code
for image in images:
content, status_code = self.copy_resource(
resource_dir="styles",
resource_name=image.name,
content_type=image.type,
workspace_name=workspace_name,
)
return content, status_code

def copy_resource(
Expand Down
5 changes: 4 additions & 1 deletion geoservercloud/models/featuretypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def __init__(self, featuretypes: list = []) -> None:

@classmethod
def from_get_response_payload(cls, content: dict):
return cls(content["featureTypes"]["featureType"])
feature_types: str | dict = content["featureTypes"]
if not feature_types:
return cls()
return cls(feature_types["featureType"]) # type: ignore

def aslist(self) -> list[dict[str, str]]:
return self._featuretypes
Expand Down

0 comments on commit 623507c

Please sign in to comment.