Mercurial > libervia-backend
comparison src/memory/memory.py @ 639:99eee75ec1b7
core: better handling of profile_key and don't write the param file anymore
- new error ProfileNotSetError and some methods use the default @NONE@ instead of @DEFAULT@
- do not output the .sat/param file anymore, it is not needed and created confusion
- plugin XEP-0054: remove an error message at startup
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 05 Sep 2013 21:03:52 +0200 |
parents | eff8772fd472 |
children | 49587e170f53 |
comparison
equal
deleted
inserted
replaced
638:6821fc06a324 | 639:99eee75ec1b7 |
---|---|
193 default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0] | 193 default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0] |
194 except IndexError: | 194 except IndexError: |
195 info(_('No profile exist yet')) | 195 info(_('No profile exist yet')) |
196 return "" | 196 return "" |
197 return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists | 197 return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists |
198 elif profile_key == '@NONE@': | |
199 raise exceptions.ProfileNotSetError | |
198 if not self.storage.hasProfile(profile_key): | 200 if not self.storage.hasProfile(profile_key): |
199 info(_('Trying to access an unknown profile')) | 201 info(_('Trying to access an unknown profile')) |
200 return "" | 202 return "" |
201 return profile_key | 203 return profile_key |
202 | 204 |
273 """ convert result to string, according to its type """ | 275 """ convert result to string, according to its type """ |
274 if isinstance(result, bool): | 276 if isinstance(result, bool): |
275 return "true" if result else "false" | 277 return "true" if result else "false" |
276 return result | 278 return result |
277 | 279 |
278 def getStringParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): | 280 def getStringParamA(self, name, category, attr="value", profile_key="@NONE@"): |
279 """ Same as getParamA but for bridge: convert non string value to string """ | 281 """ Same as getParamA but for bridge: convert non string value to string """ |
280 return self.__type_to_string(self.getParamA(name, category, attr, profile_key)) | 282 return self.__type_to_string(self.getParamA(name, category, attr, profile_key)) |
281 | 283 |
282 def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): | 284 def getParamA(self, name, category, attr="value", profile_key="@NONE@"): |
283 """Helper method to get a specific attribute | 285 """Helper method to get a specific attribute |
284 @param name: name of the parameter | 286 @param name: name of the parameter |
285 @param category: category of the parameter | 287 @param category: category of the parameter |
286 @param attr: name of the attribute (default: "value") | 288 @param attr: name of the attribute (default: "value") |
287 @param profile: owner of the param (@ALL@ for everyone) | 289 @param profile: owner of the param (@ALL@ for everyone) |
310 | 312 |
311 if attr == "value": | 313 if attr == "value": |
312 value = self.__getParam(profile, category, name) | 314 value = self.__getParam(profile, category, name) |
313 return self.__getAttr(node[1], attr, value) | 315 return self.__getAttr(node[1], attr, value) |
314 | 316 |
315 def asyncGetStringParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): | 317 def asyncGetStringParamA(self, name, category, attr="value", profile_key="@NONE@"): |
316 d = self.asyncGetParamA(name, category, attr, profile_key) | 318 d = self.asyncGetParamA(name, category, attr, profile_key) |
317 d.addCallback(self.__type_to_string) | 319 d.addCallback(self.__type_to_string) |
318 return d | 320 return d |
319 | 321 |
320 def asyncGetParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): | 322 def asyncGetParamA(self, name, category, attr="value", profile_key="@NONE@"): |
321 """Helper method to get a specific attribute | 323 """Helper method to get a specific attribute |
322 @param name: name of the parameter | 324 @param name: name of the parameter |
323 @param category: category of the parameter | 325 @param category: category of the parameter |
324 @param attr: name of the attribute (default: "value") | 326 @param attr: name of the attribute (default: "value") |
325 @param profile: owner of the param (@ALL@ for everyone)""" | 327 @param profile: owner of the param (@ALL@ for everyone)""" |
676 """Save parameters and all memory things to file/db""" | 678 """Save parameters and all memory things to file/db""" |
677 #TODO: need to encrypt files (at least passwords !) and set permissions | 679 #TODO: need to encrypt files (at least passwords !) and set permissions |
678 param_file_xml = os.path.expanduser(self.getConfig('', 'local_dir') + | 680 param_file_xml = os.path.expanduser(self.getConfig('', 'local_dir') + |
679 self.host.get_const('savefile_param_xml')) | 681 self.host.get_const('savefile_param_xml')) |
680 | 682 |
681 self.params.save_xml(param_file_xml) | 683 # TODO: check if this method is still needed |
684 #self.params.save_xml(param_file_xml) | |
682 debug(_("params saved")) | 685 debug(_("params saved")) |
683 | 686 |
684 def getProfilesList(self): | 687 def getProfilesList(self): |
685 return self.storage.getProfilesList() | 688 return self.storage.getProfilesList() |
686 | 689 |
892 if profile not in self.subscriptions: | 895 if profile not in self.subscriptions: |
893 return {} | 896 return {} |
894 | 897 |
895 return self.subscriptions[profile] | 898 return self.subscriptions[profile] |
896 | 899 |
897 def getStringParamA(self, name, category, attr="value", profile_key='@DEFAULT@'): | 900 def getStringParamA(self, name, category, attr="value", profile_key='@NONE@'): |
898 return self.params.getStringParamA(name, category, attr, profile_key) | 901 return self.params.getStringParamA(name, category, attr, profile_key) |
899 | 902 |
900 def getParamA(self, name, category, attr="value", profile_key='@DEFAULT@'): | 903 def getParamA(self, name, category, attr="value", profile_key='@NONE@'): |
901 return self.params.getParamA(name, category, attr, profile_key) | 904 return self.params.getParamA(name, category, attr, profile_key) |
902 | 905 |
903 def asyncGetParamA(self, name, category, attr="value", profile_key='@DEFAULT@'): | 906 def asyncGetParamA(self, name, category, attr="value", profile_key='@NONE@'): |
904 return self.params.asyncGetParamA(name, category, attr, profile_key) | 907 return self.params.asyncGetParamA(name, category, attr, profile_key) |
905 | 908 |
906 def asyncGetStringParamA(self, name, category, attr="value", profile_key='@DEFAULT@'): | 909 def asyncGetStringParamA(self, name, category, attr="value", profile_key='@NONE@'): |
907 return self.params.asyncGetStringParamA(name, category, attr, profile_key) | 910 return self.params.asyncGetStringParamA(name, category, attr, profile_key) |
908 | 911 |
909 def getParamsUI(self, security_limit, profile_key): | 912 def getParamsUI(self, security_limit, profile_key): |
910 return self.params.getParamsUI(security_limit, profile_key) | 913 return self.params.getParamsUI(security_limit, profile_key) |
911 | 914 |