Skip to content

Commit 28f790a

Browse files
committed
ENH: add 'get_parent', 'get_nodes' methods
1 parent 8274d43 commit 28f790a

File tree

4 files changed

+242
-48
lines changed

4 files changed

+242
-48
lines changed

src/save_and_restore_api/_api_async.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import httpx
22

33
from ._api_base import _SaveRestoreAPI_Base
4+
from ._api_threads import _SaveRestoreAPI_Threads
45

56

67
class _SaveRestoreAPI_Async(_SaveRestoreAPI_Base):
@@ -43,24 +44,52 @@ async def login(self, *, username=None, password=None):
4344
method, url, params = self._prepare_login(username=username, password=password)
4445
return await self.send_request(method, url, params=params)
4546

46-
async def get_node(self, node_uid):
47-
method, url = self._prepare_get_node(node_uid=node_uid)
47+
# =============================================================================================
48+
# NODE-CONTROLLER API METHODS
49+
# =============================================================================================
50+
51+
async def get_node(self, uniqueNodeId):
52+
# Reusing docstrings from the threaded version
53+
method, url = self._prepare_get_node(uniqueNodeId=uniqueNodeId)
4854
return await self.send_request(method, url)
4955

56+
async def get_nodes(self, uniqueIds):
57+
# Reusing docstrings from the threaded version
58+
method, url, params = self._prepare_get_nodes(uniqueIds=uniqueIds)
59+
return await self.send_request(method, url, params=params)
60+
5061
async def add_node(self, parentNodeId, *, name, nodeType, **kwargs):
62+
# Reusing docstrings from the threaded version
5163
method, url, params = self._prepare_add_node(
5264
parentNodeId=parentNodeId, name=name, nodeType=nodeType, **kwargs
5365
)
5466
return await self.send_request(method, url, params=params)
5567

5668
async def delete_node(self, nodeId):
69+
# Reusing docstrings from the threaded version
5770
method, url = self._prepare_delete_node(nodeId=nodeId)
5871
return await self.send_request(method, url)
5972

6073
async def delete_nodes(self, uniqueIds):
74+
# Reusing docstrings from the threaded version
6175
method, url, params = self._prepare_delete_nodes(uniqueIds=uniqueIds)
6276
return await self.send_request(method, url, params=params)
6377

64-
async def get_children(self, node_uid):
65-
method, url = self._prepare_get_children(node_uid=node_uid)
78+
async def get_children(self, uniqueNodeId):
79+
# Reusing docstrings from the threaded version
80+
method, url = self._prepare_get_children(uniqueNodeId=uniqueNodeId)
6681
return await self.send_request(method, url)
82+
83+
async def get_parent(self, uniqueNodeId):
84+
# Reusing docstrings from the threaded version
85+
method, url = self._prepare_get_parent(uniqueNodeId=uniqueNodeId)
86+
return await self.send_request(method, url)
87+
88+
89+
_SaveRestoreAPI_Async.get_node.__doc__ = _SaveRestoreAPI_Threads.get_node.__doc__
90+
_SaveRestoreAPI_Async.get_nodes.__doc__ = _SaveRestoreAPI_Threads.get_nodes.__doc__
91+
_SaveRestoreAPI_Async.add_node.__doc__ = _SaveRestoreAPI_Threads.add_node.__doc__
92+
_SaveRestoreAPI_Async.delete_node.__doc__ = _SaveRestoreAPI_Threads.delete_node.__doc__
93+
_SaveRestoreAPI_Async.delete_nodes.__doc__ = _SaveRestoreAPI_Threads.delete_nodes.__doc__
94+
_SaveRestoreAPI_Async.get_children.__doc__ = _SaveRestoreAPI_Threads.get_children.__doc__
95+
_SaveRestoreAPI_Async.get_parent.__doc__ = _SaveRestoreAPI_Threads.get_parent.__doc__

src/save_and_restore_api/_api_base.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,19 @@ def _prepare_login(self, *, username=None, password=None):
143143
params = {"username": username, "password": password}
144144
return method, url, params
145145

146-
def _prepare_get_node(self, *, node_uid):
147-
method, url = "GET", f"/node/{node_uid}"
146+
# =============================================================================================
147+
# NODE-CONTROLLER API METHODS
148+
# =============================================================================================
149+
150+
def _prepare_get_node(self, *, uniqueNodeId):
151+
method, url = "GET", f"/node/{uniqueNodeId}"
148152
return method, url
149153

154+
def _prepare_get_nodes(self, *, uniqueIds):
155+
method, url = "GET", "/nodes"
156+
params = uniqueIds
157+
return method, url, params
158+
150159
def _prepare_add_node(self, *, parentNodeId, name, nodeType, **kwargs):
151160
node_types = ("FOLDER", "CONFIGURATION")
152161
if nodeType not in node_types:
@@ -165,10 +174,16 @@ def _prepare_delete_nodes(self, *, uniqueIds):
165174
params = uniqueIds
166175
return method, url, params
167176

168-
def _prepare_get_children(self, *, node_uid):
169-
method, url = "GET", f"/node/{node_uid}/children"
177+
def _prepare_get_children(self, *, uniqueNodeId):
178+
method, url = "GET", f"/node/{uniqueNodeId}/children"
170179
return method, url
171180

181+
def _prepare_get_parent(self, *, uniqueNodeId):
182+
method, url = "GET", f"/node/{uniqueNodeId}/parent"
183+
return method, url
184+
185+
# =============================================================================================
186+
172187
def create_config(self, parent_node_uid, name, pv_list):
173188
config_dict = {
174189
"configurationNode": {

src/save_and_restore_api/_api_threads.py

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,74 @@ def login(self, *, username=None, password=None):
4343
method, url, params = self._prepare_login(username=username, password=password)
4444
return self.send_request(method, url, params=params)
4545

46-
def get_node(self, node_uid):
46+
# =============================================================================================
47+
# NODE-CONTROLLER API METHODS
48+
# =============================================================================================
49+
50+
def get_node(self, uniqueNodeId):
4751
"""
4852
Returns the node with specified node UID.
53+
54+
API: GET /node/{uniqueNodeId}
4955
"""
50-
method, url = self._prepare_get_node(node_uid=node_uid)
56+
method, url = self._prepare_get_node(uniqueNodeId=uniqueNodeId)
5157
return self.send_request(method, url)
5258

59+
def get_nodes(self, uniqueIds):
60+
"""
61+
Returns nodes specified by a list of UIDs.
62+
63+
API: GET /nodes
64+
"""
65+
method, url, params = self._prepare_get_nodes(uniqueIds=uniqueIds)
66+
return self.send_request(method, url, params=params)
67+
5368
def add_node(self, parentNodeId, *, name, nodeType, **kwargs):
69+
"""
70+
Creates a new node under the specified parent node. Required parameters:
71+
``name`` and ``nodeType``. Supported types: ``"FOLDER"``, ``"CONFIGURATION"``.
72+
73+
API: PUT /node?parentNodeId={parentNodeId}
74+
"""
5475
method, url, params = self._prepare_add_node(
5576
parentNodeId=parentNodeId, name=name, nodeType=nodeType, **kwargs
5677
)
5778
return self.send_request(method, url, params=params)
5879

5980
def delete_node(self, nodeId):
81+
"""
82+
Deletes the node with specified node ID. The call fails if the node can
83+
not be deleted.
84+
85+
API: DELETE /node/{nodeId}
86+
"""
6087
method, url = self._prepare_delete_node(nodeId=nodeId)
61-
print(f"================= method={method}, url={url} =================") ##
6288
return self.send_request(method, url)
6389

6490
def delete_nodes(self, uniqueIds):
91+
"""
92+
Deletes multiple nodes specified as a list of UIDs. The call fails if
93+
any of the nodes can not be deleted.
94+
95+
API: DELETE /node
96+
"""
6597
method, url, params = self._prepare_delete_nodes(uniqueIds=uniqueIds)
6698
return self.send_request(method, url, params=params)
6799

68-
def get_children(self, node_uid):
69-
method, url = self._prepare_get_children(node_uid=node_uid)
100+
def get_children(self, uniqueNodeId):
101+
"""
102+
Returns the list of child nodes for the specified node UID.
103+
104+
API: GET /node/{uniqueNodeId}/children
105+
"""
106+
method, url = self._prepare_get_children(uniqueNodeId=uniqueNodeId)
107+
return self.send_request(method, url)
108+
109+
def get_parent(self, uniqueNodeId):
110+
"""
111+
Returns the parent node for the specified node UID.
112+
113+
API: GET /node/{uniqueNodeId}/parent
114+
"""
115+
method, url = self._prepare_get_parent(uniqueNodeId=uniqueNodeId)
70116
return self.send_request(method, url)

0 commit comments

Comments
 (0)