diff src/core/sat_main.py @ 1626:63cef4dbf2a4

core, plugins file, XEP-0234, bridge: progression api enhancement: - progressStarted have a new metadata parameter, useful to know the kind of progression, direction, etc. Check bridge doc - progressGetAllMetadata can be used to retrieve this data and discover on currently running progressions - progressFinished also have a new metadata parameter, used to e.g. indicate that hash is checked - core: fixed progressGetAll - file, XEP-0234: implemented the API modifications, hash is returned on progressFinished - file: SatFile.checkSize allows to check size independently of close (be sure that all the data have been transfered though)
author Goffi <goffi@goffi.org>
date Thu, 19 Nov 2015 18:13:26 +0100
parents 7e749e8eefd0
children 98a2eb768bb0
line wrap: on
line diff
--- a/src/core/sat_main.py	Thu Nov 19 11:15:06 2015 +0100
+++ b/src/core/sat_main.py	Thu Nov 19 18:13:26 2015 +0100
@@ -824,12 +824,14 @@
         client = self.getClient(profile)
         return [action_tuple[:-1] for action_tuple in client.actions.itervalues()]
 
-    def registerProgressCb(self, progress_id, callback, profile):
+    def registerProgressCb(self, progress_id, callback, metadata=None, profile=C.PROF_KEY_NONE):
         """Register a callback called when progress is requested for id"""
+        if metadata is None:
+            metadata = {}
         client = self.getClient(profile)
         if progress_id in client._progress_cb:
             raise exceptions.ConflictError(u"Progress ID is not unique !")
-        client._progress_cb[progress_id] = callback
+        client._progress_cb[progress_id] = (callback, metadata)
 
     def removeProgressCb(self, progress_id, profile):
         """Remove a progress callback"""
@@ -855,7 +857,7 @@
         """
         client = self.getClient(profile)
         try:
-            data = client._progress_cb[progress_id](progress_id, profile)
+            data = client._progress_cb[progress_id][0](progress_id, profile)
         except KeyError:
             data = {}
         return data
@@ -868,11 +870,30 @@
                     data[key] = unicode(value)
         return progress_all
 
-    def progressGetAll(self, profile_key):
-        """Return all progress informations
+    def progressGetAllMetadata(self, profile_key):
+        """Return all progress metadata at once
 
-        @param profile_key: %(doc_profile)s get all progress from this profile
-            if C.PROF_KEY_ALL is used, all progress from all profiles are returned
+        @param profile_key: %(doc_profile)s
+            if C.PROF_KEY_ALL is used, all progress metadata from all profiles are returned
+        @return (dict[dict[dict]]): a dict which map profile to progress_dict
+            progress_dict map progress_id to progress_data
+            progress_metadata is the same dict as sent by [progressStarted]
+        """
+        clients = self.getClients(profile_key)
+        progress_all = {}
+        for client in clients:
+            profile = client.profile
+            progress_dict = {}
+            progress_all[profile] = progress_dict
+            for progress_id, (dummy, progress_metadata) in client._progress_cb.iteritems():
+                progress_dict[progress_id] = progress_metadata
+        return progress_all
+
+    def progressGetAll(self, profile_key):
+        """Return all progress status at once
+
+        @param profile_key: %(doc_profile)s
+            if C.PROF_KEY_ALL is used, all progress status from all profiles are returned
         @return (dict[dict[dict]]): a dict which map profile to progress_dict
             progress_dict map progress_id to progress_data
             progress_data is the same dict as returned by [progressGet]
@@ -883,10 +904,8 @@
             profile = client.profile
             progress_dict = {}
             progress_all[profile] = progress_dict
-            for progress_id, progress_cb in client._progress_cb.iteritems():
-                data = {}
-                progress_dict[progress_id] = data
-                progress_dict[progress_id] = progress_cb(progress_id, data, profile)
+            for progress_id, (progress_cb, dummy) in client._progress_cb.iteritems():
+                progress_dict[progress_id] = progress_cb(progress_id, profile)
         return progress_all
 
     def registerCallback(self, callback, *args, **kwargs):