Skip to content

Commit

Permalink
Merge pull request #23 from pblottiere/more_error_log
Browse files Browse the repository at this point in the history
Deactivate multithreading
  • Loading branch information
pblottiere authored May 22, 2024
2 parents 0919f75 + afdcdd8 commit a1e77d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion qsa-api/qsa_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, cfg: QSAConfig, monitor: QSAMonitor) -> None:
self.app.register_blueprint(instances, url_prefix="/api/instances")

def run(self):
self.app.run(host="0.0.0.0")
self.app.run(host="0.0.0.0", threaded=False)


@click.command()
Expand Down
21 changes: 17 additions & 4 deletions qsa-api/qsa_api/mapproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,27 @@ def write(self) -> None:
with open(self._mapproxy_project, "w") as file:
yaml.safe_dump(self.cfg, file, sort_keys=False)

def read(self) -> None:
with open(self._mapproxy_project, "r") as file:
self.cfg = yaml.safe_load(file)
def read(self) -> bool:
try:
with open(self._mapproxy_project, "r") as file:
self.cfg = yaml.safe_load(file)
except yaml.scanner.ScannerError as e:
return False, f"Failed to load MapProxy configuration file {self._mapproxy_project}"

if self.cfg is None:
return False, f"Failed to load MapProxy configuration file {self._mapproxy_project}"

return True, ""

def clear_cache(self, layer_name: str) -> None:
cache_dir = self._mapproxy_project.parent
for d in cache_dir.glob(f"**/{layer_name}_cache_*"):
shutil.rmtree(d)

def add_layer(self, name: str, bbox: list, srs: int, is_raster: bool) -> None:
def add_layer(self, name: str, bbox: list, srs: int, is_raster: bool) -> (bool, str):
if self.cfg is None:
return False, "Invalid MapProxy configuration"

if "layers" not in self.cfg:
self.cfg["layers"] = []
self.cfg["caches"] = {}
Expand Down Expand Up @@ -65,6 +76,8 @@ def add_layer(self, name: str, bbox: list, srs: int, is_raster: bool) -> None:
}
self.cfg["sources"][f"{name}_wms"] = s

return True, ""

def remove_layer(self, name: str) -> None:
# early return
if "layers" not in self.cfg:
Expand Down
12 changes: 9 additions & 3 deletions qsa-api/qsa_api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def add_layer(
lyr.setCrs(crs)

if not lyr.isValid():
return False, "Invalid layer"
return False, f"Invalid layer ({lyr.error()})"

# create project
project = QgsProject()
Expand Down Expand Up @@ -376,8 +376,14 @@ def add_layer(
epsg_code = int(lyr.crs().authid().split(':')[1])

mp = QSAMapProxy(self.name)
mp.read()
mp.add_layer(name, bbox, epsg_code, t == Qgis.LayerType.Raster)
rc, err = mp.read()
if not rc:
return False, err

rc, err = mp.add_layer(name, bbox, epsg_code, t == Qgis.LayerType.Raster)
if not rc:
return False, err

mp.write()

return True, ""
Expand Down

0 comments on commit a1e77d4

Please sign in to comment.