Mercurial > libervia-backend
comparison src/memory/params.py @ 916:1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 21 Mar 2014 16:27:09 +0100 |
parents | 1a3ba959f0ab |
children | fc7e0828b18e |
comparison
equal
deleted
inserted
replaced
915:6f96ee4d8cc0 | 916:1a759096ccbd |
---|---|
174 default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0] | 174 default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0] |
175 except IndexError: | 175 except IndexError: |
176 info(_('No profile exist yet')) | 176 info(_('No profile exist yet')) |
177 return "" | 177 return "" |
178 return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists | 178 return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists |
179 elif profile_key == '@NONE@': | 179 elif profile_key == C.PROF_KEY_NONE: |
180 raise exceptions.ProfileNotSetError | 180 raise exceptions.ProfileNotSetError |
181 elif return_profile_keys and profile_key in ["@ALL@"]: | 181 elif return_profile_keys and profile_key in ["@ALL@"]: |
182 return profile_key # this value must be managed by the caller | 182 return profile_key # this value must be managed by the caller |
183 if not self.storage.hasProfile(profile_key): | 183 if not self.storage.hasProfile(profile_key): |
184 info(_('Trying to access an unknown profile')) | 184 info(_('Trying to access an unknown profile')) |
321 """ convert result to string, according to its type """ | 321 """ convert result to string, according to its type """ |
322 if isinstance(result, bool): | 322 if isinstance(result, bool): |
323 return "true" if result else "false" | 323 return "true" if result else "false" |
324 return result | 324 return result |
325 | 325 |
326 def getStringParamA(self, name, category, attr="value", profile_key="@NONE@"): | 326 def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
327 """ Same as getParamA but for bridge: convert non string value to string """ | 327 """ Same as getParamA but for bridge: convert non string value to string """ |
328 return self.__type_to_string(self.getParamA(name, category, attr, profile_key)) | 328 return self.__type_to_string(self.getParamA(name, category, attr, profile_key)) |
329 | 329 |
330 def getParamA(self, name, category, attr="value", profile_key="@NONE@"): | 330 def getParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
331 """Helper method to get a specific attribute | 331 """Helper method to get a specific attribute |
332 @param name: name of the parameter | 332 @param name: name of the parameter |
333 @param category: category of the parameter | 333 @param category: category of the parameter |
334 @param attr: name of the attribute (default: "value") | 334 @param attr: name of the attribute (default: "value") |
335 @param profile: owner of the param (@ALL@ for everyone) | 335 @param profile: owner of the param (@ALL@ for everyone) |
358 | 358 |
359 if attr == "value": | 359 if attr == "value": |
360 value = self._getParam(category, name, profile=profile) | 360 value = self._getParam(category, name, profile=profile) |
361 return self._getAttr(node[1], attr, value) | 361 return self._getAttr(node[1], attr, value) |
362 | 362 |
363 def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key="@NONE@"): | 363 def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
364 d = self.asyncGetParamA(name, category, attr, security_limit, profile_key) | 364 d = self.asyncGetParamA(name, category, attr, security_limit, profile_key) |
365 d.addCallback(self.__type_to_string) | 365 d.addCallback(self.__type_to_string) |
366 return d | 366 return d |
367 | 367 |
368 def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key="@NONE@"): | 368 def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
369 """Helper method to get a specific attribute | 369 """Helper method to get a specific attribute |
370 @param name: name of the parameter | 370 @param name: name of the parameter |
371 @param category: category of the parameter | 371 @param category: category of the parameter |
372 @param attr: name of the attribute (default: "value") | 372 @param attr: name of the attribute (default: "value") |
373 @param profile: owner of the param (@ALL@ for everyone)""" | 373 @param profile: owner of the param (@ALL@ for everyone)""" |
400 except exceptions.ProfileNotInCacheError: | 400 except exceptions.ProfileNotInCacheError: |
401 #We have to ask data to the storage manager | 401 #We have to ask data to the storage manager |
402 d = self.storage.getIndParam(category, name, profile) | 402 d = self.storage.getIndParam(category, name, profile) |
403 return d.addCallback(lambda value: self._getAttr(node[1], attr, value)) | 403 return d.addCallback(lambda value: self._getAttr(node[1], attr, value)) |
404 | 404 |
405 def _getParam(self, category, name, type_=C.INDIVIDUAL, cache=None, profile="@NONE@"): | 405 def _getParam(self, category, name, type_=C.INDIVIDUAL, cache=None, profile=C.PROF_KEY_NONE): |
406 """Return the param, or None if it doesn't exist | 406 """Return the param, or None if it doesn't exist |
407 @param category: param category | 407 @param category: param category |
408 @param name: param name | 408 @param name: param name |
409 @param type_: GENERAL or INDIVIDUAL | 409 @param type_: GENERAL or INDIVIDUAL |
410 @param cache: temporary cache, to use when profile is not logged | 410 @param cache: temporary cache, to use when profile is not logged |
414 if type_ == C.GENERAL: | 414 if type_ == C.GENERAL: |
415 if (category, name) in self.params_gen: | 415 if (category, name) in self.params_gen: |
416 return self.params_gen[(category, name)] | 416 return self.params_gen[(category, name)] |
417 return None # This general param has the default value | 417 return None # This general param has the default value |
418 assert (type_ == C.INDIVIDUAL) | 418 assert (type_ == C.INDIVIDUAL) |
419 if profile == "@NONE@": | 419 if profile == C.PROF_KEY_NONE: |
420 raise exceptions.ProfileNotSetError | 420 raise exceptions.ProfileNotSetError |
421 if profile in self.params: | 421 if profile in self.params: |
422 cache = self.params[profile] # if profile is in main cache, we use it, | 422 cache = self.params[profile] # if profile is in main cache, we use it, |
423 # ignoring the temporary cache | 423 # ignoring the temporary cache |
424 elif cache is None: # else we use the temporary cache if it exists, or raise an exception | 424 elif cache is None: # else we use the temporary cache if it exists, or raise an exception |
606 name = cat.getAttribute("name") | 606 name = cat.getAttribute("name") |
607 if name not in categories: | 607 if name not in categories: |
608 categories.append(cat.getAttribute("name")) | 608 categories.append(cat.getAttribute("name")) |
609 return categories | 609 return categories |
610 | 610 |
611 def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key='@NONE@'): | 611 def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
612 """Set a parameter, return None if the parameter is not in param xml""" | 612 """Set a parameter, return None if the parameter is not in param xml""" |
613 #TODO: use different behaviour depending of the data type (e.g. password encrypted) | 613 #TODO: use different behaviour depending of the data type (e.g. password encrypted) |
614 if profile_key != "@NONE@": | 614 if profile_key != C.PROF_KEY_NONE: |
615 profile = self.getProfileName(profile_key) | 615 profile = self.getProfileName(profile_key) |
616 if not profile: | 616 if not profile: |
617 error(_('Trying to set parameter for an unknown profile')) | 617 error(_('Trying to set parameter for an unknown profile')) |
618 return # TODO: throw an error | 618 return # TODO: throw an error |
619 | 619 |
636 self.host.bridge.paramUpdate(name, value, category, profile) | 636 self.host.bridge.paramUpdate(name, value, category, profile) |
637 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) | 637 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) |
638 return | 638 return |
639 | 639 |
640 assert (node[0] == C.INDIVIDUAL) | 640 assert (node[0] == C.INDIVIDUAL) |
641 assert (profile_key != "@NONE@") | 641 assert (profile_key != C.PROF_KEY_NONE) |
642 | 642 |
643 type_ = node[1].getAttribute("type") | 643 type_ = node[1].getAttribute("type") |
644 if type_ == "button": | 644 if type_ == "button": |
645 print "clique", node.toxml() | 645 print "clique", node.toxml() |
646 else: | 646 else: |