Skip to content

Commit 3b7c95c

Browse files
committed
DOC: docstrings for the 'node' and 'config' API
1 parent 5f69171 commit 3b7c95c

File tree

1 file changed

+155
-15
lines changed

1 file changed

+155
-15
lines changed

src/save_and_restore_api/_api_threads.py

Lines changed: 155 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,61 @@ def login(self, *, username=None, password=None):
214214

215215
def node_get(self, uniqueNodeId):
216216
"""
217-
Returns the node with specified node UID.
217+
Returns the metadata for the node with specified node UID.
218218
219219
API: GET /node/{uniqueNodeId}
220+
221+
Parameters
222+
----------
223+
uniqueNodeId : str
224+
Unique ID of the node.
225+
226+
Returns
227+
-------
228+
dict
229+
Node metadata as returned by the server.
230+
231+
Examples
232+
--------
233+
234+
.. code-block:: python
235+
236+
from save_and_restore_api import SaveRestoreAPI
237+
238+
with SaveRestoreAPI(base_url="http://localhost:8080/save-restore") as SR:
239+
root_folder_uid = SR.ROOT_NODE_UID
240+
root_folder = SR.node_get(root_folder_uid)
241+
print(f"Root folder metadata: {root_folder}")
242+
243+
Async version:
244+
.. code-block:: python
245+
246+
from save_and_restore_api.aio import SaveRestoreAPI
247+
248+
async with SaveRestoreAPI(base_url="http://localhost:8080/save-restore") as SR:
249+
root_folder_uid = SR.ROOT_NODE_UID
250+
root_folder = await SR.node_get(root_folder_uid)
251+
print(f"Root folder metadata: {root_folder}")
220252
"""
221253
method, url = self._prepare_node_get(uniqueNodeId=uniqueNodeId)
222254
return self.send_request(method, url)
223255

224256
def nodes_get(self, uniqueIds):
225257
"""
226-
Returns nodes specified by a list of UIDs.
258+
Returns metadata for multiple nodes specified by a list of UIDs. This API is
259+
similar to calling ``node_get()`` multiple times, but is more efficient.
227260
228261
API: GET /nodes
262+
263+
Parameters
264+
----------
265+
uniqueIds : list of str
266+
List of node unique IDs.
267+
268+
Returns
269+
-------
270+
list of dict
271+
List of node metadata as returned by the server.
229272
"""
230273
method, url, body_json = self._prepare_nodes_get(uniqueIds=uniqueIds)
231274
return self.send_request(method, url, body_json=body_json)
@@ -262,7 +305,8 @@ def node_add(self, parentNodeId, *, node, auth=None, **kwargs):
262305
with SaveRestoreAPI(base_url="http://localhost:8080/save-restore") as SR:
263306
SR.auth_set(username="user", password="user_password")
264307
root_folder_uid = SR.ROOT_NODE_UID
265-
folder = SR.node_add(root_folder_uid, node={"name": "My Folder", "nodeType": "FOLDER"})
308+
node = {"name": "My Folder", "nodeType": "FOLDER"}
309+
folder = SR.node_add(root_folder_uid, node=node)
266310
print(f"Created folder metadata: {folder}")
267311
268312
Async version:
@@ -274,7 +318,8 @@ def node_add(self, parentNodeId, *, node, auth=None, **kwargs):
274318
async with SaveRestoreAPI(base_url="http://localhost:8080/save-restore") as SR:
275319
await SR.auth_set(username="user", password="user_password")
276320
root_folder_uid = SR.ROOT_NODE_UID
277-
folder = await SR.node_add(root_folder_uid, node={"name": "My Folder", "nodeType": "FOLDER"})
321+
node = {"name": "My Folder", "nodeType": "FOLDER"}
322+
folder = await SR.node_add(root_folder_uid, node=node)
278323
print(f"Created folder metadata: {folder}")
279324
"""
280325
method, url, params, body_json = self._prepare_node_add(parentNodeId=parentNodeId, node=node)
@@ -283,28 +328,64 @@ def node_add(self, parentNodeId, *, node, auth=None, **kwargs):
283328
def node_delete(self, nodeId, *, auth=None):
284329
"""
285330
Deletes the node with specified node ID. The call fails if the node can
286-
not be deleted.
331+
not be deleted, e.g. the node is a non-empty folder.
287332
288333
API: DELETE /node/{nodeId}
334+
335+
Parameters
336+
----------
337+
nodeId : str
338+
Unique ID of the node to be deleted.
339+
auth : httpx.BasicAuth
340+
Object with authentication data (generated using ``auth_gen`` method). If not specified or None,
341+
then the authentication set using ``auth_set`` method is used.
342+
343+
Returns
344+
-------
345+
None
289346
"""
290347
method, url = self._prepare_node_delete(nodeId=nodeId)
291348
return self.send_request(method, url, auth=auth)
292349

293350
def nodes_delete(self, uniqueIds, *, auth=None):
294351
"""
295-
Deletes multiple nodes specified as a list of UIDs. The call fails if
296-
any of the nodes can not be deleted.
352+
Deletes multiple nodes specified by the list of UIDs. The API goes through the nodes in the list
353+
and deletes the nodes. It fails if the node can not be deleted and does not try to delete the
354+
following nodes.
297355
298356
API: DELETE /node
357+
358+
Parameters
359+
----------
360+
uniqueIds : list[str]
361+
List of UIDs of the nodes to delete.
362+
auth : httpx.BasicAuth
363+
Object with authentication data (generated using ``auth_gen`` method). If not specified or None,
364+
then the authentication set using ``auth_set`` method is used.
365+
366+
Returns
367+
-------
368+
None
299369
"""
300370
method, url, body_json = self._prepare_nodes_delete(uniqueIds=uniqueIds)
301371
return self.send_request(method, url, body_json=body_json, auth=auth)
302372

303373
def node_get_children(self, uniqueNodeId):
304374
"""
305-
Returns the list of child nodes for the specified node UID.
375+
Returns the list of child nodes for the node with specified UID.
306376
307377
API: GET /node/{uniqueNodeId}/children
378+
379+
Parameters
380+
----------
381+
uniqueNodeId : str
382+
Unique ID of the node.
383+
384+
Returns
385+
-------
386+
list[dict]
387+
List of child node nodes. The list elements are dictionaries containing
388+
the node metadata as returned by the server.
308389
"""
309390
method, url = self._prepare_node_get_children(uniqueNodeId=uniqueNodeId)
310391
return self.send_request(method, url)
@@ -314,6 +395,16 @@ def node_get_parent(self, uniqueNodeId):
314395
Returns the parent node for the specified node UID.
315396
316397
API: GET /node/{uniqueNodeId}/parent
398+
399+
Parameters
400+
----------
401+
uniqueNodeId : str
402+
Unique ID of the node.
403+
404+
Returns
405+
-------
406+
dict
407+
Parent node metadata as returned by the server.
317408
"""
318409
method, url = self._prepare_node_get_parent(uniqueNodeId=uniqueNodeId)
319410
return self.send_request(method, url)
@@ -324,10 +415,20 @@ def node_get_parent(self, uniqueNodeId):
324415

325416
def config_get(self, uniqueNodeId):
326417
"""
327-
Returns the config data for the node with specified node UID. Returns only the configuration
328-
data. To get the node metadata use ``node_get()``.
418+
Returns the configuration data for the node with specified node UID. Returns only
419+
the configuration data. To get the node metadata use ``node_get()``.
329420
330421
API: GET /config/{uniqueNodeId}
422+
423+
Parameters
424+
----------
425+
uniqueNodeId : str
426+
Unique ID of the configuration node.
427+
428+
Returns
429+
-------
430+
dict
431+
Configuration data (``configurationData``) as returned by the server.
331432
"""
332433
method, url = self._prepare_config_get(uniqueNodeId=uniqueNodeId)
333434
return self.send_request(method, url)
@@ -339,8 +440,10 @@ def config_add(self, parentNodeId, *, configurationNode, configurationData, auth
339440
340441
Minimum required fields:
341442
342-
configurationNode = {"name": "test_config"}
343-
configurationData = {"pvList": [{"pvName": "PV1"}, {"pvName": "PV2"}]}
443+
.. code-block:: python
444+
445+
configurationNode = {"name": "test_config"}
446+
configurationData = {"pvList": [{"pvName": "PV1"}, {"pvName": "PV2"}]}
344447
345448
The fields ``uniqueId``, ``nodeType``, ``userName`` in ``configurationNode`` are ignored
346449
and overwritten by the server.
@@ -349,6 +452,22 @@ def config_add(self, parentNodeId, *, configurationNode, configurationData, auth
349452
as returned by the server.
350453
351454
API: PUT /config?parentNodeId={parentNodeId}
455+
456+
Parameters
457+
----------
458+
parentNodeId : str
459+
Unique ID of the parent node.
460+
configurationNode : dict
461+
Configuration node (``configurationNode``) metadata. The required field is ``name``.
462+
configurationData : dict
463+
Configuration data (``configurationData``). The required field is ``pvList``.
464+
465+
Returns
466+
-------
467+
dict
468+
Dictionary contains configuration node metadata and configuration data of the node
469+
that was added. The dictionary contains two keys: ``configurationNode`` and
470+
``configurationData`` as returned by the server.
352471
"""
353472
method, url, body_json = self._prepare_config_add(
354473
parentNodeId=parentNodeId, configurationNode=configurationNode, configurationData=configurationData
@@ -357,11 +476,32 @@ def config_add(self, parentNodeId, *, configurationNode, configurationData, auth
357476

358477
def config_update(self, *, configurationNode, configurationData, auth=None):
359478
"""
360-
Updates an existing configuration node. Parameters ``configurationNode`` and ``configurationData``
361-
should be loaded using ``node_get()`` and ``config_get()`` respectively. Both parameters must
362-
contain correct ``uniqueID`` field values.
479+
Update an existing configuration node. It is best if ``configurationNode`` and ``configurationData``
480+
are loaded using ``node_get()`` and ``config_get()`` APIs respectively and then modified in the
481+
application code. Both dictionaries can also be created from scratch in the application code if
482+
necessary. Both dictionaries must contain correct correct UID (``uniqueID``) of an existing
483+
configuration node.
363484
364485
API: POST /config
486+
487+
Parameters
488+
----------
489+
configurationNode : dict
490+
Configuration node (``configurationNode``) metadata. ``uniqueId`` field must be point to
491+
an existing configuration node.
492+
configurationData : dict
493+
Configuration data (``configurationData``). ``uniqueId`` field must be identical to the
494+
``uniqueId`` field in ``configurationNode``.
495+
auth : httpx.BasicAuth
496+
Object with authentication data (generated using ``auth_gen`` method). If not specified or None,
497+
then the authentication set using ``auth_set`` method is used.
498+
499+
Returns
500+
-------
501+
dict
502+
Dictionary contains configuration node metadata and configuration data of the node
503+
that was updated. The dictionary contains two keys: ``configurationNode`` and
504+
``configurationData`` as returned by the server.
365505
"""
366506
method, url, body_json = self._prepare_config_update(
367507
configurationNode=configurationNode, configurationData=configurationData

0 commit comments

Comments
 (0)