Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/core/components/tomo/tomovis_client.py: 18%
28 statements
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-15 02:12 +0000
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-15 02:12 +0000
1# coding: utf-8
2# License: MIT (c) ESRF 2022
3"""Client functions for tomovis"""
4from typing import Optional
6import requests
9def create_tiling(
10 base_url: str, h5file: str, scan_h5entry: str, timeout: Optional[float] = None
11) -> Optional[str]:
12 config = dict(
13 dataset=dict(
14 location=h5file,
15 hdf5_entry=scan_h5entry,
16 ),
17 )
19 try:
20 response = requests.post(
21 f"{base_url}/image_tiling/",
22 json=config,
23 timeout=timeout,
24 )
25 except requests.Timeout:
26 return None
28 if response.status_code != 202:
29 return None
30 content = response.json()
31 return str(content["id"])
34def delete_tiling(base_url: str, id_: str, timeout: Optional[float] = None) -> bool:
35 try:
36 response = requests.delete(f"{base_url}/image_tiling/{id_}", timeout=timeout)
37 except requests.Timeout:
38 return False
40 return response.status_code == 204
43def clear_tiling(base_url: str, timeout: Optional[float] = None) -> bool:
44 try:
45 response = requests.get(f"{base_url}/image_tiling/", timeout=timeout)
46 except requests.Timeout:
47 return False
49 if response.status_code != 200:
50 return False
51 content = response.json()
53 results = [delete_tiling(base_url, desc["id"]) for desc in content]
54 return all(results)