From 49025853fc49e7b159d214f3b6fe610892c7e735 Mon Sep 17 00:00:00 2001 From: Rolf Krahl Date: Fri, 1 Nov 2024 15:39:43 +0100 Subject: [PATCH] Add method Client.restoreData --- doc/src/client.rst | 2 ++ src/icat/client.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/doc/src/client.rst b/doc/src/client.rst index 051edac..31aa808 100644 --- a/doc/src/client.rst +++ b/doc/src/client.rst @@ -154,4 +154,6 @@ manages the interaction with an ICAT service as a client. .. automethod:: deleteData + .. automethod:: restoreData + .. _ICAT SOAP Manual: https://repo.icatproject.org/site/icat/server/4.10.0/soap.html diff --git a/src/icat/client.py b/src/icat/client.py index 8c0cf2c..8377515 100644 --- a/src/icat/client.py +++ b/src/icat/client.py @@ -1000,5 +1000,40 @@ def deleteData(self, objs): objs = DataSelection(objs) self.ids.delete(objs) + def restoreData(self, objs): + """Request IDS to restore data. + + Check the status of the data, request a restore if needed and + wait for the restore to complete. + + :param objs: either a dict having some of the keys + `investigationIds`, `datasetIds`, and `datafileIds` + with a list of object ids as value respectively, or a list + of entity objects, or a data selection. + :type objs: :class:`dict`, :class:`list` of + :class:`icat.entity.Entity`, or + :class:`icat.ids.DataSelection` + + .. versionadded:: 1.6.0 + """ + if not self.ids: + raise RuntimeError("no IDS.") + if not isinstance(objs, DataSelection): + objs = DataSelection(objs) + while True: + self.autoRefresh() + status = self.ids.getStatus(objs) + if status == "ONLINE": + break + elif status == "RESTORING": + pass + elif status == "ARCHIVED": + self.ids.restore(objs) + else: + # Should never happen + raise IDSResponseError("unexpected response from " + "IDS getStatus() call: %s" % status) + time.sleep(30) + atexit.register(Client.cleanupall)