Mercurial > libervia-backend
comparison src/memory/params.py @ 1226:72f25d671368
memory (params): use more generic param attribute "constraint" instead of "min" and "max"
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 06 Oct 2014 11:18:37 +0200 |
parents | e6e0ea4dc835 |
children | 4da2e4d58bd0 |
comparison
equal
deleted
inserted
replaced
1225:82dabb442e2e | 1226:72f25d671368 |
---|---|
42 <general> | 42 <general> |
43 </general> | 43 </general> |
44 <individual> | 44 <individual> |
45 <category name="General" label="%(category_general)s"> | 45 <category name="General" label="%(category_general)s"> |
46 <param name="Password" value="" type="password" /> | 46 <param name="Password" value="" type="password" /> |
47 <param name="%(history_param)s" label="%(label_history)s" value="20" min="0" max="100" type="int" security="0" /> | 47 <param name="%(history_param)s" label="%(history_label)s" value="20" constraint="0;100" type="int" security="0" /> |
48 </category> | 48 </category> |
49 <category name="Connection" label="%(category_connection)s"> | 49 <category name="Connection" label="%(category_connection)s"> |
50 <param name="JabberID" value="name@example.org/SàT" type="string" /> | 50 <param name="JabberID" value="name@example.org/SàT" type="string" /> |
51 <param name="Password" value="" type="password" /> | 51 <param name="Password" value="" type="password" /> |
52 <param name="Priority" value="50" type="int" min="-128" max="127"/> | 52 <param name="Priority" value="50" type="int" constraint="-128;127"/> |
53 <param name="%(force_server_param)s" value="" type="string" /> | 53 <param name="%(force_server_param)s" value="" type="string" /> |
54 <param name="%(force_port_param)s" value="" type="int" min="80" max="65535" /> | 54 <param name="%(force_port_param)s" value="" type="int" constraint="1;65535" /> |
55 <param name="NewAccount" label="%(label_NewAccount)s" type="button" callback_id="registerNewAccount"/> | 55 <param name="NewAccount" label="%(new_account_label)s" type="button" callback_id="registerNewAccount"/> |
56 <param name="autoconnect" label="%(label_autoconnect)s" value="true" type="bool" /> | 56 <param name="autoconnect" label="%(autoconnect_label)s" value="true" type="bool" /> |
57 <param name="autodisconnect" label="%(label_autodisconnect)s" value="false" type="bool" /> | 57 <param name="autodisconnect" label="%(autodisconnect_label)s" value="false" type="bool" /> |
58 </category> | 58 </category> |
59 <category name="Misc" label="%(category_misc)s"> | 59 <category name="Misc" label="%(category_misc)s"> |
60 <param name="Watched" value="test@Jabber.goffi.int" type="string" /> | 60 <param name="Watched" value="test@Jabber.goffi.int" type="string" /> |
61 </category> | 61 </category> |
62 </individual> | 62 </individual> |
63 </params> | 63 </params> |
64 """ % { | 64 """ % { |
65 'category_general': D_("General"), | 65 'category_general': D_("General"), |
66 'category_connection': D_("Connection"), | 66 'category_connection': D_("Connection"), |
67 'history_param': C.HISTORY_LIMIT, | 67 'history_param': C.HISTORY_LIMIT, |
68 'label_history': D_('Chat history limit'), | 68 'history_label': D_('Chat history limit'), |
69 'label_NewAccount': D_("Register new account"), | |
70 'label_autoconnect': D_('Connect on frontend startup'), | |
71 'label_autodisconnect': D_('Disconnect on frontend closure'), | |
72 'category_misc': D_("Misc"), | |
73 'force_server_param': C.FORCE_SERVER_PARAM, | 69 'force_server_param': C.FORCE_SERVER_PARAM, |
74 'force_port_param': C.FORCE_PORT_PARAM, | 70 'force_port_param': C.FORCE_PORT_PARAM, |
71 'new_account_label': D_("Register new account"), | |
72 'autoconnect_label': D_('Connect on frontend startup'), | |
73 'autodisconnect_label': D_('Disconnect on frontend closure'), | |
74 'category_misc': D_("Misc"), | |
75 } | 75 } |
76 | 76 |
77 def load_default_params(self): | 77 def load_default_params(self): |
78 self.dom = minidom.parseString(Params.default_xml.encode('utf-8')) | 78 self.dom = minidom.parseString(Params.default_xml.encode('utf-8')) |
79 | 79 |
753 int(value) | 753 int(value) |
754 except ValueError: | 754 except ValueError: |
755 log.debug(_("Trying to set parameter '%(param)s' in category '%(cat)s' with an non-integer value" | 755 log.debug(_("Trying to set parameter '%(param)s' in category '%(cat)s' with an non-integer value" |
756 % {'param': name, 'cat': category})) | 756 % {'param': name, 'cat': category})) |
757 return defer.succeed(None) | 757 return defer.succeed(None) |
758 if node[1].hasAttribute("min"): | 758 if node[1].hasAttribute("constraint"): |
759 value = str(max(int(value), int(node[1].getAttribute("min")))) | 759 constraint = node[1].getAttribute("constraint") |
760 if node[1].hasAttribute("max"): | 760 try: |
761 value = str(min(int(value), int(node[1].getAttribute("max")))) | 761 min_, max_ = [int(limit) for limit in constraint.split(";")] |
762 except ValueError: | |
763 raise exceptions.InternalError("Invalid integer parameter constraint: %s" % constraint) | |
764 value = str(min(max(int(value), min_), max_)) | |
762 | 765 |
763 log.info(_("Setting parameter (%(category)s, %(name)s) = %(value)s") % | 766 log.info(_("Setting parameter (%(category)s, %(name)s) = %(value)s") % |
764 {'category': category, 'name': name, 'value': value if type_ != 'password' else '********'}) | 767 {'category': category, 'name': name, 'value': value if type_ != 'password' else '********'}) |
765 | 768 |
766 if node[0] == C.GENERAL: | 769 if node[0] == C.GENERAL: |