Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
1625:8b8b1af5905f | 1626:63cef4dbf2a4 |
---|---|
822 @param profile: %(doc_profile)s | 822 @param profile: %(doc_profile)s |
823 """ | 823 """ |
824 client = self.getClient(profile) | 824 client = self.getClient(profile) |
825 return [action_tuple[:-1] for action_tuple in client.actions.itervalues()] | 825 return [action_tuple[:-1] for action_tuple in client.actions.itervalues()] |
826 | 826 |
827 def registerProgressCb(self, progress_id, callback, profile): | 827 def registerProgressCb(self, progress_id, callback, metadata=None, profile=C.PROF_KEY_NONE): |
828 """Register a callback called when progress is requested for id""" | 828 """Register a callback called when progress is requested for id""" |
829 if metadata is None: | |
830 metadata = {} | |
829 client = self.getClient(profile) | 831 client = self.getClient(profile) |
830 if progress_id in client._progress_cb: | 832 if progress_id in client._progress_cb: |
831 raise exceptions.ConflictError(u"Progress ID is not unique !") | 833 raise exceptions.ConflictError(u"Progress ID is not unique !") |
832 client._progress_cb[progress_id] = callback | 834 client._progress_cb[progress_id] = (callback, metadata) |
833 | 835 |
834 def removeProgressCb(self, progress_id, profile): | 836 def removeProgressCb(self, progress_id, profile): |
835 """Remove a progress callback""" | 837 """Remove a progress callback""" |
836 client = self.getClient(profile) | 838 client = self.getClient(profile) |
837 try: | 839 try: |
853 'size' (int): end_position | 855 'size' (int): end_position |
854 if id doesn't exists (may be a finished progression), and empty dict is returned | 856 if id doesn't exists (may be a finished progression), and empty dict is returned |
855 """ | 857 """ |
856 client = self.getClient(profile) | 858 client = self.getClient(profile) |
857 try: | 859 try: |
858 data = client._progress_cb[progress_id](progress_id, profile) | 860 data = client._progress_cb[progress_id][0](progress_id, profile) |
859 except KeyError: | 861 except KeyError: |
860 data = {} | 862 data = {} |
861 return data | 863 return data |
862 | 864 |
863 def _progressGetAll(self, profile_key): | 865 def _progressGetAll(self, profile_key): |
866 for progress_id, data in progress_dict.iteritems(): | 868 for progress_id, data in progress_dict.iteritems(): |
867 for key, value in data.iteritems(): | 869 for key, value in data.iteritems(): |
868 data[key] = unicode(value) | 870 data[key] = unicode(value) |
869 return progress_all | 871 return progress_all |
870 | 872 |
871 def progressGetAll(self, profile_key): | 873 def progressGetAllMetadata(self, profile_key): |
872 """Return all progress informations | 874 """Return all progress metadata at once |
873 | 875 |
874 @param profile_key: %(doc_profile)s get all progress from this profile | 876 @param profile_key: %(doc_profile)s |
875 if C.PROF_KEY_ALL is used, all progress from all profiles are returned | 877 if C.PROF_KEY_ALL is used, all progress metadata from all profiles are returned |
876 @return (dict[dict[dict]]): a dict which map profile to progress_dict | 878 @return (dict[dict[dict]]): a dict which map profile to progress_dict |
877 progress_dict map progress_id to progress_data | 879 progress_dict map progress_id to progress_data |
878 progress_data is the same dict as returned by [progressGet] | 880 progress_metadata is the same dict as sent by [progressStarted] |
879 """ | 881 """ |
880 clients = self.getClients(profile_key) | 882 clients = self.getClients(profile_key) |
881 progress_all = {} | 883 progress_all = {} |
882 for client in clients: | 884 for client in clients: |
883 profile = client.profile | 885 profile = client.profile |
884 progress_dict = {} | 886 progress_dict = {} |
885 progress_all[profile] = progress_dict | 887 progress_all[profile] = progress_dict |
886 for progress_id, progress_cb in client._progress_cb.iteritems(): | 888 for progress_id, (dummy, progress_metadata) in client._progress_cb.iteritems(): |
887 data = {} | 889 progress_dict[progress_id] = progress_metadata |
888 progress_dict[progress_id] = data | 890 return progress_all |
889 progress_dict[progress_id] = progress_cb(progress_id, data, profile) | 891 |
892 def progressGetAll(self, profile_key): | |
893 """Return all progress status at once | |
894 | |
895 @param profile_key: %(doc_profile)s | |
896 if C.PROF_KEY_ALL is used, all progress status from all profiles are returned | |
897 @return (dict[dict[dict]]): a dict which map profile to progress_dict | |
898 progress_dict map progress_id to progress_data | |
899 progress_data is the same dict as returned by [progressGet] | |
900 """ | |
901 clients = self.getClients(profile_key) | |
902 progress_all = {} | |
903 for client in clients: | |
904 profile = client.profile | |
905 progress_dict = {} | |
906 progress_all[profile] = progress_dict | |
907 for progress_id, (progress_cb, dummy) in client._progress_cb.iteritems(): | |
908 progress_dict[progress_id] = progress_cb(progress_id, profile) | |
890 return progress_all | 909 return progress_all |
891 | 910 |
892 def registerCallback(self, callback, *args, **kwargs): | 911 def registerCallback(self, callback, *args, **kwargs): |
893 """Register a callback. | 912 """Register a callback. |
894 | 913 |