Mercurial > libervia-backend
annotate sat/memory/params.py @ 4001:32d714a8ea51
plugin XEP-0045: dot not wait for MAM retrieval to be completed:
in `_join_MAM`, `room.fully_joined` is called before retrieving the MAM archive, as the
process can be very long, and is not necessary to have the room working (message can be
received after being in the room, and added out of order). This avoid blocking the `join`
workflow for an extended time.
Some renaming and coroutine integrations.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 10 Mar 2023 17:22:41 +0100 |
parents | 5f546dd910e0 |
children | 524856bd7b19 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3480
7550ae9cfbac
Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
3 # Libervia: an XMPP client |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
0 | 5 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
9 # (at your option) any later version. |
0 | 10 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
14 # GNU Affero General Public License for more details. |
0 | 15 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1220
diff
changeset
|
19 from sat.core.i18n import _, D_ |
0 | 20 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
21 from sat.core import exceptions |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
22 from sat.core.constants import Const as C |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
23 from sat.memory.crypto import BlockCipher, PasswordHasher |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
24 from xml.dom import minidom, NotFoundErr |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
25 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
26 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
27 log = getLogger(__name__) |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
28 from twisted.internet import defer |
645 | 29 from twisted.python.failure import Failure |
1744
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
30 from twisted.words.xish import domish |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
31 from twisted.words.protocols.jabber import jid |
1740
681fe91abcc0
memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents:
1739
diff
changeset
|
32 from sat.tools.xml_tools import paramsXML2XMLUI, getText |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
33 from sat.tools.common import data_format |
3105
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
34 from xml.sax.saxutils import quoteattr |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
35 |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
36 # TODO: params should be rewritten using Twisted directly instead of minidom |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
37 # general params should be linked to sat.conf and kept synchronised |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
38 # this need an overall simplification to make maintenance easier |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
39 |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
40 |
1744
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
41 def createJidElts(jids): |
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
42 """Generator which return <jid/> elements from jids |
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
43 |
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
44 @param jids(iterable[id.jID]): jids to use |
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
45 @return (generator[domish.Element]): <jid/> elements |
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
46 """ |
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
47 for jid_ in jids: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 jid_elt = domish.Element((None, "jid")) |
1744
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
49 jid_elt.addContent(jid_.full()) |
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
50 yield jid_elt |
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
51 |
9a48e09044eb
plugin extra_pep, params: fixed insecure building of jids_list
Goffi <goffi@goffi.org>
parents:
1740
diff
changeset
|
52 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
53 class Params(object): |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
54 """This class manage parameters with xml""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
56 ### TODO: add desciption in params |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
57 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 # TODO: when priority is changed, a new presence stanza must be emitted |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 # TODO: int type (Priority should be int instead of string) |
3028 | 60 default_xml = """ |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
61 <params> |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
62 <general> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
63 </general> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
64 <individual> |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
65 <category name="General" label="%(category_general)s"> |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
66 <param name="Password" value="" type="password" /> |
1226
72f25d671368
memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
67 <param name="%(history_param)s" label="%(history_label)s" value="20" constraint="0;100" type="int" security="0" /> |
1227
4da2e4d58bd0
memory (params): add parameters "Show offline contacts" and "Show empty groups"
souliane <souliane@mailoo.org>
parents:
1226
diff
changeset
|
68 <param name="%(show_offline_contacts)s" label="%(show_offline_contacts_label)s" value="false" type="bool" security="0" /> |
1238
ff58a49a7022
memory (params): set "Show empty groups" to True by default
souliane <souliane@mailoo.org>
parents:
1227
diff
changeset
|
69 <param name="%(show_empty_groups)s" label="%(show_empty_groups_label)s" value="true" type="bool" security="0" /> |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
70 </category> |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
71 <category name="Connection" label="%(category_connection)s"> |
1647
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
72 <param name="JabberID" value="name@example.org" type="string" security="10" /> |
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
73 <param name="Password" value="" type="password" security="10" /> |
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
74 <param name="Priority" value="50" type="int" constraint="-128;127" security="10" /> |
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
75 <param name="%(force_server_param)s" value="" type="string" security="50" /> |
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
76 <param name="%(force_port_param)s" value="" type="int" constraint="1;65535" security="50" /> |
3120 | 77 <param name="autoconnect_backend" label="%(autoconnect_backend_label)s" value="false" type="bool" security="50" /> |
1647
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
78 <param name="autoconnect" label="%(autoconnect_label)s" value="true" type="bool" security="50" /> |
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
79 <param name="autodisconnect" label="%(autodisconnect_label)s" value="false" type="bool" security="50" /> |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
80 <param name="check_certificate" label="%(check_certificate_label)s" value="true" type="bool" security="4" /> |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
81 </category> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
82 </individual> |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
83 </params> |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
84 """ % { |
3028 | 85 "category_general": D_("General"), |
86 "category_connection": D_("Connection"), | |
87 "history_param": C.HISTORY_LIMIT, | |
88 "history_label": D_("Chat history limit"), | |
89 "show_offline_contacts": C.SHOW_OFFLINE_CONTACTS, | |
90 "show_offline_contacts_label": D_("Show offline contacts"), | |
91 "show_empty_groups": C.SHOW_EMPTY_GROUPS, | |
92 "show_empty_groups_label": D_("Show empty groups"), | |
93 "force_server_param": C.FORCE_SERVER_PARAM, | |
94 "force_port_param": C.FORCE_PORT_PARAM, | |
3120 | 95 "autoconnect_backend_label": D_("Connect on backend startup"), |
3028 | 96 "autoconnect_label": D_("Connect on frontend startup"), |
97 "autodisconnect_label": D_("Disconnect on frontend closure"), | |
98 "check_certificate_label": D_("Check certificate (don't uncheck if unsure)"), | |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
99 } |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
100 |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
101 def load_default_params(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 self.dom = minidom.parseString(Params.default_xml.encode("utf-8")) |
38 | 103 |
557
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
104 def _mergeParams(self, source_node, dest_node): |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
105 """Look for every node in source_node and recursively copy them to dest if they don't exists""" |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
106 |
557
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
107 def getNodesMap(children): |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
108 ret = {} |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
109 for child in children: |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
110 if child.nodeType == child.ELEMENT_NODE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
111 ret[(child.tagName, child.getAttribute("name"))] = child |
557
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
112 return ret |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 |
557
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
114 source_map = getNodesMap(source_node.childNodes) |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
115 dest_map = getNodesMap(dest_node.childNodes) |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
116 source_set = set(source_map.keys()) |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
117 dest_set = set(dest_map.keys()) |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
118 to_add = source_set.difference(dest_set) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
119 |
557
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
120 for node_key in to_add: |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
121 dest_node.appendChild(source_map[node_key].cloneNode(True)) |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
122 |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
123 to_recurse = source_set - to_add |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
124 for node_key in to_recurse: |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
125 self._mergeParams(source_map[node_key], dest_map[node_key]) |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
126 |
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
127 def load_xml(self, xml_file): |
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
128 """Load parameters template from xml file""" |
557
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
129 self.dom = minidom.parse(xml_file) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 default_dom = minidom.parseString(Params.default_xml.encode("utf-8")) |
557
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
131 self._mergeParams(default_dom.documentElement, self.dom.documentElement) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
132 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
133 def loadGenParams(self): |
412 | 134 """Load general parameters data from storage |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
135 |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
136 @return: deferred triggered once params are loaded |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
137 """ |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
138 return self.storage.loadGenParams(self.params_gen) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
139 |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
140 def loadIndParams(self, profile, cache=None): |
412 | 141 """Load individual parameters |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
142 |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
143 set self.params cache or a temporary cache |
412 | 144 @param profile: profile to load (*must exist*) |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
145 @param cache: if not None, will be used to store the value, as a short time cache |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
146 @return: deferred triggered once params are loaded |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
147 """ |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
148 if cache is None: |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
149 self.params[profile] = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 return self.storage.loadIndParams( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 self.params[profile] if cache is None else cache, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
153 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
154 def purgeProfile(self, profile): |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
155 """Remove cache data of a profile |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
156 |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
157 @param profile: %(doc_profile)s |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
158 """ |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
159 try: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
160 del self.params[profile] |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
161 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 log.error( |
3028 | 163 _("Trying to purge cache of a profile not in memory: [%s]") % profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
164 ) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
165 |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
166 def save_xml(self, filename): |
61 | 167 """Save parameters template to xml file""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 with open(filename, "wb") as xml_file: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 xml_file.write(self.dom.toxml("utf-8")) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
170 |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
171 def __init__(self, host, storage): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
172 log.debug("Parameters init") |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
173 self.host = host |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
174 self.storage = storage |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
175 self.default_profile = None |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
176 self.params = {} |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
177 self.params_gen = {} |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
178 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
179 def createProfile(self, profile, component): |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
180 """Create a new profile |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
181 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
182 @param profile(unicode): name of the profile |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
183 @param component(unicode): entry point if profile is a component |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
184 @param callback: called when the profile actually exists in database and memory |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
866
diff
changeset
|
185 @return: a Deferred instance |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
186 """ |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
187 if self.storage.hasProfile(profile): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 log.info(_("The profile name already exists")) |
3752
5f546dd910e0
core (memory/param): fix unproper use of `Failure`
Goffi <goffi@goffi.org>
parents:
3711
diff
changeset
|
189 return defer.fail(exceptions.ConflictError()) |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
190 if not self.host.trigger.point("ProfileCreation", profile): |
3752
5f546dd910e0
core (memory/param): fix unproper use of `Failure`
Goffi <goffi@goffi.org>
parents:
3711
diff
changeset
|
191 return defer.fail(exceptions.CancelError()) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
192 return self.storage.createProfile(profile, component or None) |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
193 |
894
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
194 def asyncDeleteProfile(self, profile, force=False): |
68 | 195 """Delete an existing profile |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
938
diff
changeset
|
196 |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
866
diff
changeset
|
197 @param profile: name of the profile |
894
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
198 @param force: force the deletion even if the profile is connected. |
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
199 To be used for direct calls only (not through the bridge). |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
866
diff
changeset
|
200 @return: a Deferred instance |
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
866
diff
changeset
|
201 """ |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
202 if not self.storage.hasProfile(profile): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
203 log.info(_("Trying to delete an unknown profile")) |
1836
fb94f92dc740
core (params): return given profile for ProfileUnknownError
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
204 return defer.fail(Failure(exceptions.ProfileUnknownError(profile))) |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
205 if self.host.isConnected(profile): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
206 if force: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
207 self.host.disconnect(profile) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
208 else: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
209 log.info(_("Trying to delete a connected profile")) |
1624 | 210 return defer.fail(Failure(exceptions.ProfileConnected)) |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
866
diff
changeset
|
211 return self.storage.deleteProfile(profile) |
68 | 212 |
1263 | 213 def getProfileName(self, profile_key, return_profile_keys=False): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
214 """return profile according to profile_key |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
938
diff
changeset
|
215 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
216 @param profile_key: profile name or key which can be |
1519
fbe86b5d156f
core (memory, params): minor docstrings updates
Goffi <goffi@goffi.org>
parents:
1497
diff
changeset
|
217 C.PROF_KEY_ALL for all profiles |
fbe86b5d156f
core (memory, params): minor docstrings updates
Goffi <goffi@goffi.org>
parents:
1497
diff
changeset
|
218 C.PROF_KEY_DEFAULT for default profile |
3126
2b0f739f8a46
plugin manhole: added "C" to namespace
Goffi <goffi@goffi.org>
parents:
3123
diff
changeset
|
219 @param return_profile_keys: if True, return unmanaged profile keys (like |
2b0f739f8a46
plugin manhole: added "C" to namespace
Goffi <goffi@goffi.org>
parents:
3123
diff
changeset
|
220 C.PROF_KEY_ALL). This keys must be managed by the caller |
1460
c7fd121a6180
core: getProfileName no raise ProfileUnknownError + minor doc fixes
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
221 @return: requested profile name |
1590
ab54af2a9ab2
core (memory): fixed a case where getProfileName was returning an empty string instead of raising an errror
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
222 @raise exceptions.ProfileUnknownError: profile doesn't exists |
ab54af2a9ab2
core (memory): fixed a case where getProfileName was returning an empty string instead of raising an errror
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
223 @raise exceptions.ProfileNotSetError: if C.PROF_KEY_NONE is used |
1460
c7fd121a6180
core: getProfileName no raise ProfileUnknownError + minor doc fixes
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
224 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
225 if profile_key == "@DEFAULT@": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 default = self.host.memory.memory_data.get("Profile_default") |
443
7099ea9c1b12
core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents:
432
diff
changeset
|
227 if not default: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 log.info(_("No default profile, returning first one")) |
625
5646ecd3e35e
core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents:
620
diff
changeset
|
229 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
230 default = self.host.memory.memory_data[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 "Profile_default" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
232 ] = self.storage.getProfilesList()[0] |
625
5646ecd3e35e
core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents:
620
diff
changeset
|
233 except IndexError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 log.info(_("No profile exist yet")) |
1836
fb94f92dc740
core (params): return given profile for ProfileUnknownError
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
235 raise exceptions.ProfileUnknownError(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 return ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
237 default |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
238 ) # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
239 elif profile_key == C.PROF_KEY_NONE: |
639
99eee75ec1b7
core: better handling of profile_key and don't write the param file anymore
souliane <souliane@mailoo.org>
parents:
635
diff
changeset
|
240 raise exceptions.ProfileNotSetError |
1519
fbe86b5d156f
core (memory, params): minor docstrings updates
Goffi <goffi@goffi.org>
parents:
1497
diff
changeset
|
241 elif return_profile_keys and profile_key in [C.PROF_KEY_ALL]: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
242 return profile_key # this value must be managed by the caller |
412 | 243 if not self.storage.hasProfile(profile_key): |
3028 | 244 log.error(_("Trying to access an unknown profile (%s)") % profile_key) |
1836
fb94f92dc740
core (params): return given profile for ProfileUnknownError
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
245 raise exceptions.ProfileUnknownError(profile_key) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
246 return profile_key |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
247 |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
248 def __get_unique_node(self, parent, tag, name): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
249 """return node with given tag |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
250 |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
251 @param parent: parent of nodes to check (e.g. documentElement) |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
252 @param tag: tag to check (e.g. "category") |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
253 @param name: name to check (e.g. "JID") |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
254 @return: node if it exist or None |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
255 """ |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
256 for node in parent.childNodes: |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
257 if node.nodeName == tag and node.getAttribute("name") == name: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
258 # the node already exists |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
259 return node |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
260 # the node is new |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
261 return None |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
262 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
263 def updateParams(self, xml, security_limit=C.NO_SECURITY_LIMIT, app=""): |
833
9bac2fc74968
memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents:
813
diff
changeset
|
264 """import xml in parameters, update if the param already exists |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
265 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
266 If security_limit is specified and greater than -1, the parameters |
778
bfafed251b40
memory: fixed wrong information in the docstrings for security_limit
souliane <souliane@mailoo.org>
parents:
777
diff
changeset
|
267 that have a security level greater than security_limit are skipped. |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
268 @param xml: parameters in xml form |
778
bfafed251b40
memory: fixed wrong information in the docstrings for security_limit
souliane <souliane@mailoo.org>
parents:
777
diff
changeset
|
269 @param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
270 @param app: name of the frontend registering the parameters or empty value |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
271 """ |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
272 # TODO: should word with domish.Element |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 src_parent = minidom.parseString(xml.encode("utf-8")).documentElement |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
274 |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
275 def pre_process_app_node(src_parent, security_limit, app): |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
276 """Parameters that are registered from a frontend must be checked""" |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
277 to_remove = [] |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
278 for type_node in src_parent.childNodes: |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
279 if type_node.nodeName != C.INDIVIDUAL: |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
280 to_remove.append(type_node) # accept individual parameters only |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
281 continue |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
282 for cat_node in type_node.childNodes: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
283 if cat_node.nodeName != "category": |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
284 to_remove.append(cat_node) |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
285 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
286 to_remove_count = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
287 0 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
288 ) # count the params to be removed from current category |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
289 for node in cat_node.childNodes: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
290 if node.nodeName != "param" or not self.checkSecurityLimit( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 node, security_limit |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
292 ): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
293 to_remove.append(node) |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
294 to_remove_count += 1 |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
295 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
296 node.setAttribute("app", app) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
297 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
298 len(cat_node.childNodes) == to_remove_count |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
299 ): # remove empty category |
3028 | 300 for __ in range(0, to_remove_count): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
301 to_remove.pop() |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
302 to_remove.append(cat_node) |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
303 for node in to_remove: |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
304 node.parentNode.removeChild(node) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
305 |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
306 def import_node(tgt_parent, src_parent): |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
307 for child in src_parent.childNodes: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
308 if child.nodeName == "#text": |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
309 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
310 node = self.__get_unique_node( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
311 tgt_parent, child.nodeName, child.getAttribute("name") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
312 ) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
313 if not node: # The node is new |
1051
854880a31717
memory (params), test: fixes updateParams bug
souliane <souliane@mailoo.org>
parents:
1050
diff
changeset
|
314 tgt_parent.appendChild(child.cloneNode(True)) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
315 else: |
662
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
656
diff
changeset
|
316 if child.nodeName == "param": |
833
9bac2fc74968
memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents:
813
diff
changeset
|
317 # The child updates an existing parameter, we replace the node |
662
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
656
diff
changeset
|
318 tgt_parent.replaceChild(child, node) |
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
656
diff
changeset
|
319 else: |
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
656
diff
changeset
|
320 # the node already exists, we recurse 1 more level |
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
656
diff
changeset
|
321 import_node(node, child) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
322 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
323 if app: |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
324 pre_process_app_node(src_parent, security_limit, app) |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
325 import_node(self.dom.documentElement, src_parent) |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
326 |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
327 def paramsRegisterApp(self, xml, security_limit, app): |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
328 """Register frontend's specific parameters |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
329 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
330 If security_limit is specified and greater than -1, the parameters |
778
bfafed251b40
memory: fixed wrong information in the docstrings for security_limit
souliane <souliane@mailoo.org>
parents:
777
diff
changeset
|
331 that have a security level greater than security_limit are skipped. |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
332 @param xml: XML definition of the parameters to be added |
778
bfafed251b40
memory: fixed wrong information in the docstrings for security_limit
souliane <souliane@mailoo.org>
parents:
777
diff
changeset
|
333 @param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
334 @param app: name of the frontend registering the parameters |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
335 """ |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
336 if not app: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
337 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
338 _( |
3028 | 339 "Trying to register frontends parameters with no specified app: aborted" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
340 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
341 ) |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
342 return |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
343 if not hasattr(self, "frontends_cache"): |
833
9bac2fc74968
memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents:
813
diff
changeset
|
344 self.frontends_cache = [] |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
345 if app in self.frontends_cache: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
346 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
347 _( |
3028 | 348 "Trying to register twice frontends parameters for %(app)s: aborted" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
349 % {"app": app} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
350 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
351 ) |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
352 return |
833
9bac2fc74968
memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents:
813
diff
changeset
|
353 self.frontends_cache.append(app) |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
354 self.updateParams(xml, security_limit, app) |
3028 | 355 log.debug("Frontends parameters registered for %(app)s" % {"app": app}) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
356 |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
357 def __default_ok(self, value, name, category): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
358 # FIXME: will not work with individual parameters |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
359 self.setParam(name, value, category) |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
360 |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
361 def __default_ko(self, failure, name, category): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
362 log.error( |
3028 | 363 _("Can't determine default value for [%(category)s/%(name)s]: %(reason)s") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
364 % {"category": category, "name": name, "reason": str(failure.value)} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
365 ) |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
366 |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
367 def setDefault(self, name, category, callback, errback=None): |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
368 """Set default value of parameter |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
369 |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
370 'default_cb' attibute of parameter must be set to 'yes' |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
371 @param name: name of the parameter |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
372 @param category: category of the parameter |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
373 @param callback: must return a string with the value (use deferred if needed) |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
374 @param errback: must manage the error with args failure, name, category |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
375 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
376 # TODO: send signal param update if value changed |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
377 # TODO: manage individual paramaters |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
378 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
379 "setDefault called for %(category)s/%(name)s" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
380 % {"category": category, "name": name} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
381 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
382 node = self._getParamNode(name, category, "@ALL@") |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
383 if not node: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
384 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
385 _( |
3028 | 386 "Requested param [%(name)s] in category [%(category)s] doesn't exist !" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
387 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
388 % {"name": name, "category": category} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
389 ) |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
390 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
391 if node[1].getAttribute("default_cb") == "yes": |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
392 # del node[1].attributes['default_cb'] # default_cb is not used anymore as a flag to know if we have to set the default value, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
393 # and we can still use it later e.g. to call a generic setDefault method |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
394 value = self._getParam(category, name, C.GENERAL) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
395 if value is None: # no value set by the user: we have the default value |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
396 log.debug("Default value to set, using callback") |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
397 d = defer.maybeDeferred(callback) |
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
398 d.addCallback(self.__default_ok, name, category) |
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
399 d.addErrback(errback or self.__default_ko, name, category) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
400 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
401 def _getAttr_internal(self, node, attr, value): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
402 """Get attribute value. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
403 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
404 /!\ This method would return encrypted password values. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
405 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
406 @param node: XML param node |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
407 @param attr: name of the attribute to get (e.g.: 'value' or 'type') |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
408 @param value: user defined value |
1534
a5e0393a06cd
plugin ip, params: plugin IP discovery, first draft:
Goffi <goffi@goffi.org>
parents:
1519
diff
changeset
|
409 @return: value (can be str, bool, int, list, None) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
410 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
411 if attr == "value": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
412 value_to_use = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 value if value is not None else node.getAttribute(attr) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
414 ) # we use value (user defined) if it exist, else we use node's default value |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
415 if node.getAttribute("type") == "bool": |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
416 return C.bool(value_to_use) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
417 if node.getAttribute("type") == "int": |
3711
358a678e5bdf
core (memory/param): don't crash when getting unset int value
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
418 return int(value_to_use) if value_to_use else value_to_use |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
419 elif node.getAttribute("type") == "list": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
420 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
421 not value_to_use |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
422 ): # no user defined value, take default value from the XML |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
423 options = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
424 option |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
425 for option in node.childNodes |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
426 if option.nodeName == "option" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
427 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
428 selected = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
429 option |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
430 for option in options |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
431 if option.getAttribute("selected") == "true" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
432 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
433 cat, param = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
434 node.parentNode.getAttribute("name"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
435 node.getAttribute("name"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
436 ) |
1747
40b7f18ac704
memory (params): fixes loading user value and building params XML for jids_list type
souliane <souliane@mailoo.org>
parents:
1745
diff
changeset
|
437 if len(selected) == 1: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
438 value_to_use = selected[0].getAttribute("value") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
439 log.info( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
440 _( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
441 "Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
442 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
443 % {"cat": cat, "param": param, "value": value_to_use} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
444 ) |
1747
40b7f18ac704
memory (params): fixes loading user value and building params XML for jids_list type
souliane <souliane@mailoo.org>
parents:
1745
diff
changeset
|
445 return value_to_use |
40b7f18ac704
memory (params): fixes loading user value and building params XML for jids_list type
souliane <souliane@mailoo.org>
parents:
1745
diff
changeset
|
446 if len(selected) == 0: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
447 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
448 _( |
3028 | 449 "Parameter (%(cat)s, %(param)s) of type list has no default option!" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
450 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
451 % {"cat": cat, "param": param} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
452 ) |
1747
40b7f18ac704
memory (params): fixes loading user value and building params XML for jids_list type
souliane <souliane@mailoo.org>
parents:
1745
diff
changeset
|
453 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
454 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
455 _( |
3028 | 456 "Parameter (%(cat)s, %(param)s) of type list has more than one default option!" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
457 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
458 % {"cat": cat, "param": param} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
459 ) |
1747
40b7f18ac704
memory (params): fixes loading user value and building params XML for jids_list type
souliane <souliane@mailoo.org>
parents:
1745
diff
changeset
|
460 raise exceptions.DataError |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
461 elif node.getAttribute("type") == "jids_list": |
1747
40b7f18ac704
memory (params): fixes loading user value and building params XML for jids_list type
souliane <souliane@mailoo.org>
parents:
1745
diff
changeset
|
462 if value_to_use: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
463 jids = value_to_use.split( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
464 "\t" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
465 ) # FIXME: it's not good to use tabs as separator ! |
1747
40b7f18ac704
memory (params): fixes loading user value and building params XML for jids_list type
souliane <souliane@mailoo.org>
parents:
1745
diff
changeset
|
466 else: # no user defined value, take default value from the XML |
40b7f18ac704
memory (params): fixes loading user value and building params XML for jids_list type
souliane <souliane@mailoo.org>
parents:
1745
diff
changeset
|
467 jids = [getText(jid_) for jid_ in node.getElementsByTagName("jid")] |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
468 to_delete = [] |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
469 for idx, value in enumerate(jids): |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
470 try: |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
471 jids[idx] = jid.JID(value) |
1740
681fe91abcc0
memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents:
1739
diff
changeset
|
472 except (RuntimeError, jid.InvalidFormat, AttributeError): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
473 log.warning( |
3028 | 474 "Incorrect jid value found in jids list: [{}]".format(value) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
475 ) |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
476 to_delete.append(value) |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
477 for value in to_delete: |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
478 jids.remove(value) |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
479 return jids |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
480 return value_to_use |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
481 return node.getAttribute(attr) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
482 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
483 def _getAttr(self, node, attr, value): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
484 """Get attribute value (synchronous). |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
485 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
486 /!\ This method can not be used to retrieve password values. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
487 @param node: XML param node |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
488 @param attr: name of the attribute to get (e.g.: 'value' or 'type') |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
489 @param value: user defined value |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
490 @return (unicode, bool, int, list): value to retrieve |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
491 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
492 if attr == "value" and node.getAttribute("type") == "password": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
493 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
494 "To retrieve password values, use _asyncGetAttr instead of _getAttr" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
495 ) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
496 return self._getAttr_internal(node, attr, value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
497 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
498 def _asyncGetAttr(self, node, attr, value, profile=None): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
499 """Get attribute value. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
500 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
501 Profile passwords are returned hashed (if not empty), |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
502 other passwords are returned decrypted (if not empty). |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
503 @param node: XML param node |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
504 @param attr: name of the attribute to get (e.g.: 'value' or 'type') |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
505 @param value: user defined value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
506 @param profile: %(doc_profile)s |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
507 @return (unicode, bool, int, list): Deferred value to retrieve |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
508 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
509 value = self._getAttr_internal(node, attr, value) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
510 if attr != "value" or node.getAttribute("type") != "password": |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
511 return defer.succeed(value) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
512 param_cat = node.parentNode.getAttribute("name") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
513 param_name = node.getAttribute("name") |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
514 if ((param_cat, param_name) == C.PROFILE_PASS_PATH) or not value: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
515 return defer.succeed( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
516 value |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
517 ) # profile password and empty passwords are returned "as is" |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
518 if not profile: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
519 raise exceptions.ProfileNotSetError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
520 "The profile is needed to decrypt a password" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
521 ) |
3160
330a5f1d9eea
core (memory/crypto): replaced `PyCrypto` by `cryptography`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
522 password = self.host.memory.decryptValue(value, profile) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
523 |
3160
330a5f1d9eea
core (memory/crypto): replaced `PyCrypto` by `cryptography`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
524 if password is None: |
330a5f1d9eea
core (memory/crypto): replaced `PyCrypto` by `cryptography`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
525 raise exceptions.InternalError("password should never be None") |
330a5f1d9eea
core (memory/crypto): replaced `PyCrypto` by `cryptography`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
526 return defer.succeed(password) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
527 |
3040 | 528 def _type_to_str(self, result): |
529 """Convert result to string, according to its type """ | |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
530 if isinstance(result, bool): |
3040 | 531 return C.boolConst(result) |
532 elif isinstance(result, (list, set, tuple)): | |
533 return ', '.join(self._type_to_str(r) for r in result) | |
534 else: | |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
535 return str(result) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
536 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
537 def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
538 """ Same as getParamA but for bridge: convert non string value to string """ |
3040 | 539 return self._type_to_str( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
540 self.getParamA(name, category, attr, profile_key=profile_key) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
541 ) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
542 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
543 def getParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
544 self, name, category, attr="value", use_default=True, profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
545 ): |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
546 """Helper method to get a specific attribute. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
547 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
548 /!\ This method would return encrypted password values, |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
549 to get the plain values you have to use asyncGetParamA. |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
550 @param name: name of the parameter |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
551 @param category: category of the parameter |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
552 @param attr: name of the attribute (default: "value") |
1534
a5e0393a06cd
plugin ip, params: plugin IP discovery, first draft:
Goffi <goffi@goffi.org>
parents:
1519
diff
changeset
|
553 @parm use_default(bool): if True and attr=='value', return default value if not set |
a5e0393a06cd
plugin ip, params: plugin IP discovery, first draft:
Goffi <goffi@goffi.org>
parents:
1519
diff
changeset
|
554 else return None if not set |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
555 @param profile: owner of the param (@ALL@ for everyone) |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
556 @return: attribute |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
557 """ |
1647
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
558 # FIXME: looks really dirty and buggy, need to be reviewed/refactored |
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
559 # FIXME: security_limit is not managed here ! |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
560 node = self._getParamNode(name, category) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
561 if not node: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
562 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
563 _( |
3028 | 564 "Requested param [%(name)s] in category [%(category)s] doesn't exist !" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
565 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
566 % {"name": name, "category": category} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
567 ) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
568 raise exceptions.NotFound |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
569 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
570 if attr == "value" and node[1].getAttribute("type") == "password": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
571 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
572 "To retrieve password values, use asyncGetParamA instead of getParamA" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
573 ) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
574 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
575 if node[0] == C.GENERAL: |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
576 value = self._getParam(category, name, C.GENERAL) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
577 if value is None and attr == "value" and not use_default: |
1534
a5e0393a06cd
plugin ip, params: plugin IP discovery, first draft:
Goffi <goffi@goffi.org>
parents:
1519
diff
changeset
|
578 return value |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
579 return self._getAttr(node[1], attr, value) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
580 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
581 assert node[0] == C.INDIVIDUAL |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
582 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
583 profile = self.getProfileName(profile_key) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
584 if not profile: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
585 log.error(_("Requesting a param for an non-existant profile")) |
1836
fb94f92dc740
core (params): return given profile for ProfileUnknownError
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
586 raise exceptions.ProfileUnknownError(profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
587 |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
588 if profile not in self.params: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
589 log.error(_("Requesting synchronous param for not connected profile")) |
1624 | 590 raise exceptions.ProfileNotConnected(profile) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
591 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
592 if attr == "value": |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
593 value = self._getParam(category, name, profile=profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
594 if value is None and attr == "value" and not use_default: |
1534
a5e0393a06cd
plugin ip, params: plugin IP discovery, first draft:
Goffi <goffi@goffi.org>
parents:
1519
diff
changeset
|
595 return value |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
596 return self._getAttr(node[1], attr, value) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
597 |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
598 async def asyncGetStringParamA( |
3040 | 599 self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
600 profile=C.PROF_KEY_NONE): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
601 value = await self.asyncGetParamA( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
602 name, category, attr, security_limit, profile_key=profile) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
603 return self._type_to_str(value) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
604 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
605 def asyncGetParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
606 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
607 name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
608 category, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
609 attr="value", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
610 security_limit=C.NO_SECURITY_LIMIT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
611 profile_key=C.PROF_KEY_NONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
612 ): |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
613 """Helper method to get a specific attribute. |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
614 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
615 @param name: name of the parameter |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
616 @param category: category of the parameter |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
617 @param attr: name of the attribute (default: "value") |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
618 @param profile: owner of the param (@ALL@ for everyone) |
1534
a5e0393a06cd
plugin ip, params: plugin IP discovery, first draft:
Goffi <goffi@goffi.org>
parents:
1519
diff
changeset
|
619 @return (defer.Deferred): parameter value, with corresponding type (bool, int, list, etc) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
620 """ |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
621 node = self._getParamNode(name, category) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
622 if not node: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
623 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
624 _( |
3028 | 625 "Requested param [%(name)s] in category [%(category)s] doesn't exist !" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
626 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
627 % {"name": name, "category": category} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
628 ) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
629 raise ValueError("Requested param doesn't exist") |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
630 |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
631 if not self.checkSecurityLimit(node[1], security_limit): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
632 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
633 _( |
3028 | 634 "Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
635 % {"param": name, "cat": category} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
636 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
637 ) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1263
diff
changeset
|
638 raise exceptions.PermissionError |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
639 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
640 if node[0] == C.GENERAL: |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
641 value = self._getParam(category, name, C.GENERAL) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
642 return self._asyncGetAttr(node[1], attr, value) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
643 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
644 assert node[0] == C.INDIVIDUAL |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
645 |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
646 profile = self.getProfileName(profile_key) |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
647 if not profile: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
648 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
649 _("Requesting a param for a non-existant profile") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
650 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
651 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
652 if attr != "value": |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
653 return defer.succeed(node[1].getAttribute(attr)) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
654 try: |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
655 value = self._getParam(category, name, profile=profile) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
656 return self._asyncGetAttr(node[1], attr, value, profile) |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
657 except exceptions.ProfileNotInCacheError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
658 # We have to ask data to the storage manager |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
659 d = self.storage.getIndParam(category, name, profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
660 return d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
661 lambda value: self._asyncGetAttr(node[1], attr, value, profile) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
662 ) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
663 |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
664 def _getParamsValuesFromCategory( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
665 self, category, security_limit, app, extra_s, profile_key): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
666 client = self.host.getClient(profile_key) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
667 extra = data_format.deserialise(extra_s) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
668 return defer.ensureDeferred(self.getParamsValuesFromCategory( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
669 client, category, security_limit, app, extra)) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
670 |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
671 async def getParamsValuesFromCategory( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
672 self, client, category, security_limit, app='', extra=None): |
1587
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
673 """Get all parameters "attribute" for a category |
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
674 |
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
675 @param category(unicode): the desired category |
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
676 @param security_limit(int): NO_SECURITY_LIMIT (-1) to return all the params. |
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
677 Otherwise sole the params which have a security level defined *and* |
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
678 lower or equal to the specified value are returned. |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
679 @param app(str): see [getParams] |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
680 @param extra(dict): see [getParams] |
1587
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
681 @return (dict): key: param name, value: param value (converted to string if needed) |
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
682 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
683 # TODO: manage category of general type (without existant profile) |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
684 if extra is None: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
685 extra = {} |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
686 prof_xml = await self._constructProfileXml(client, security_limit, app, extra) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
687 ret = {} |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
688 for category_node in prof_xml.getElementsByTagName("category"): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
689 if category_node.getAttribute("name") == category: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
690 for param_node in category_node.getElementsByTagName("param"): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
691 name = param_node.getAttribute("name") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
692 if not name: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
693 log.warning( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
694 "ignoring attribute without name: {}".format( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
695 param_node.toxml() |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
696 ) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
697 ) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
698 continue |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
699 value = await self.asyncGetStringParamA( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
700 name, category, security_limit=security_limit, |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
701 profile=client.profile) |
1587
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
702 |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
703 ret[name] = value |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
704 break |
1587
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
705 |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
706 prof_xml.unlink() |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
707 return ret |
1587
698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
Goffi <goffi@goffi.org>
parents:
1586
diff
changeset
|
708 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
709 def _getParam( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
710 self, category, name, type_=C.INDIVIDUAL, cache=None, profile=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
711 ): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
712 """Return the param, or None if it doesn't exist |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
713 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
714 @param category: param category |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
715 @param name: param name |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
716 @param type_: GENERAL or INDIVIDUAL |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
717 @param cache: temporary cache, to use when profile is not logged |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
718 @param profile: the profile name (not profile key, i.e. name and not something like @DEFAULT@) |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
719 @return: param value or None if it doesn't exist |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
720 """ |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
721 if type_ == C.GENERAL: |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
722 if (category, name) in self.params_gen: |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
723 return self.params_gen[(category, name)] |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
724 return None # This general param has the default value |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
725 assert type_ == C.INDIVIDUAL |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
726 if profile == C.PROF_KEY_NONE: |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
727 raise exceptions.ProfileNotSetError |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
728 if profile in self.params: |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
729 cache = self.params[profile] # if profile is in main cache, we use it, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
730 # ignoring the temporary cache |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
731 elif ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
732 cache is None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
733 ): # else we use the temporary cache if it exists, or raise an exception |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
734 raise exceptions.ProfileNotInCacheError |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
735 if (category, name) not in cache: |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
736 return None |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
737 return cache[(category, name)] |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
738 |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
739 async def _constructProfileXml(self, client, security_limit, app, extra): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
740 """Construct xml for asked profile, filling values when needed |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
741 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
742 /!\ as noticed in doc, don't forget to unlink the minidom.Document |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
743 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params. |
642
e07a03d52321
core: fix for methods signature
souliane <souliane@mailoo.org>
parents:
641
diff
changeset
|
744 Otherwise sole the params which have a security level defined *and* |
e07a03d52321
core: fix for methods signature
souliane <souliane@mailoo.org>
parents:
641
diff
changeset
|
745 lower or equal to the specified value are returned. |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
746 @param app: name of the frontend requesting the parameters, or '' to get all parameters |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
747 @param profile: profile name (not key !) |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
748 @return: a deferred that fire a minidom.Document of the profile xml (cf warning above) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
749 """ |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
750 profile = client.profile |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
751 |
784
900987e1c0c4
memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents:
779
diff
changeset
|
752 def checkNode(node): |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
753 """Check the node against security_limit, app and extra""" |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
754 return (self.checkSecurityLimit(node, security_limit) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
755 and self.checkApp(node, app) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
756 and self.checkExtra(node, extra)) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
757 |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
758 if profile in self.params: |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
759 profile_cache = self.params[profile] |
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
760 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
761 # profile is not in cache, we load values in a short time cache |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
762 profile_cache = {} |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
763 await self.loadIndParams(profile, profile_cache) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
764 |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
765 # init the result document |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
766 prof_xml = minidom.parseString("<params/>") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
767 cache = {} |
395
79fe50fc8edc
memory: multiples params of the same category are now merged
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
768 |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
769 for type_node in self.dom.documentElement.childNodes: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
770 if type_node.nodeName != C.GENERAL and type_node.nodeName != C.INDIVIDUAL: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
771 continue |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
772 # we use all params, general and individual |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
773 for cat_node in type_node.childNodes: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
774 if cat_node.nodeName != "category": |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
775 continue |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
776 category = cat_node.getAttribute("name") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
777 dest_params = {} # result (merged) params for category |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
778 if category not in cache: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
779 # we make a copy for the new xml |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
780 cache[category] = dest_cat = cat_node.cloneNode(True) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
781 to_remove = [] |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
782 for node in dest_cat.childNodes: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
783 if node.nodeName != "param": |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
784 continue |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
785 if not checkNode(node): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
786 to_remove.append(node) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
787 continue |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
788 dest_params[node.getAttribute("name")] = node |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
789 for node in to_remove: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
790 dest_cat.removeChild(node) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
791 new_node = True |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
792 else: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
793 # It's not a new node, we use the previously cloned one |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
794 dest_cat = cache[category] |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
795 new_node = False |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
796 params = cat_node.getElementsByTagName("param") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
797 |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
798 for param_node in params: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
799 # we have to merge new params (we are parsing individual parameters, we have to add them |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
800 # to the previously parsed general ones) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
801 name = param_node.getAttribute("name") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
802 if not checkNode(param_node): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
803 continue |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
804 if name not in dest_params: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
805 # this is reached when a previous category exists |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
806 dest_params[name] = param_node.cloneNode(True) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
807 dest_cat.appendChild(dest_params[name]) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
808 |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
809 profile_value = self._getParam( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
810 category, |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
811 name, |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
812 type_node.nodeName, |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
813 cache=profile_cache, |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
814 profile=profile, |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
815 ) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
816 if profile_value is not None: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
817 # there is a value for this profile, we must change the default |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
818 if dest_params[name].getAttribute("type") == "list": |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
819 for option in dest_params[name].getElementsByTagName( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
820 "option" |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
821 ): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
822 if option.getAttribute("value") == profile_value: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
823 option.setAttribute("selected", "true") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
824 else: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
825 try: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
826 option.removeAttribute("selected") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
827 except NotFoundErr: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
828 pass |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
829 elif dest_params[name].getAttribute("type") == "jids_list": |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
830 jids = profile_value.split("\t") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
831 for jid_elt in dest_params[name].getElementsByTagName( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
832 "jid" |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
833 ): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
834 dest_params[name].removeChild( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
835 jid_elt |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
836 ) # remove all default |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
837 for jid_ in jids: # rebuilt the children with use values |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
838 try: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
839 jid.JID(jid_) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
840 except ( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
841 RuntimeError, |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
842 jid.InvalidFormat, |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
843 AttributeError, |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
844 ): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
845 log.warning( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
846 "Incorrect jid value found in jids list: [{}]".format( |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
847 jid_ |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
848 ) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
849 ) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
850 else: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
851 jid_elt = prof_xml.createElement("jid") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
852 jid_elt.appendChild(prof_xml.createTextNode(jid_)) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
853 dest_params[name].appendChild(jid_elt) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
854 else: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
855 dest_params[name].setAttribute("value", profile_value) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
856 if new_node: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
857 prof_xml.documentElement.appendChild(dest_cat) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
858 |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
859 to_remove = [] |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
860 for cat_node in prof_xml.documentElement.childNodes: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
861 # we remove empty categories |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
862 if cat_node.getElementsByTagName("param").length == 0: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
863 to_remove.append(cat_node) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
864 for node in to_remove: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
865 prof_xml.documentElement.removeChild(node) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
866 |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
867 return prof_xml |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
868 |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
869 |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
870 def _getParamsUI(self, security_limit, app, extra_s, profile_key): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
871 client = self.host.getClient(profile_key) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
872 extra = data_format.deserialise(extra_s) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
873 return defer.ensureDeferred(self.getParamsUI(client, security_limit, app, extra)) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
874 |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
875 async def getParamsUI(self, client, security_limit, app, extra=None): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
876 """Get XMLUI to handle parameters |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
877 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
878 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params. |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
879 Otherwise sole the params which have a security level defined *and* |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
880 lower or equal to the specified value are returned. |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
881 @param app: name of the frontend requesting the parameters, or '' to get all parameters |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
882 @param extra (dict, None): extra options. Key can be: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
883 - ignore: list of (category/name) values to remove from parameters |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
884 @return(str): a SàT XMLUI for parameters |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
885 """ |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
886 param_xml = await self.getParams(client, security_limit, app, extra) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
887 return paramsXML2XMLUI(param_xml) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
888 |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
889 async def getParams(self, client, security_limit, app, extra=None): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
890 """Construct xml for asked profile, take params xml as skeleton |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
891 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
892 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params. |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
893 Otherwise sole the params which have a security level defined *and* |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
894 lower or equal to the specified value are returned. |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
895 @param app: name of the frontend requesting the parameters, or '' to get all parameters |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
896 @param extra (dict, None): extra options. Key can be: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
897 - ignore: list of (category/name) values to remove from parameters |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
898 @param profile_key: Profile key which can be either a magic (eg: @DEFAULT@) or the name of an existing profile. |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
899 @return: XML of parameters |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
900 """ |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
901 if extra is None: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
902 extra = {} |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
903 prof_xml = await self._constructProfileXml(client, security_limit, app, extra) |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
904 return_xml = prof_xml.toxml() |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
905 prof_xml.unlink() |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
906 return "\n".join((line for line in return_xml.split("\n") if line)) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
907 |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
908 def _getParamNode(self, name, category, type_="@ALL@"): # FIXME: is type_ useful ? |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
909 """Return a node from the param_xml |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
910 @param name: name of the node |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
911 @param category: category of the node |
1019 | 912 @param type_: keyword for search: |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
913 @ALL@ search everywhere |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
914 @GENERAL@ only search in general type |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
915 @INDIVIDUAL@ only search in individual type |
1019 | 916 @return: a tuple (node type, node) or None if not found""" |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
917 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
918 for type_node in self.dom.documentElement.childNodes: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
919 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
920 (type_ == "@ALL@" or type_ == "@GENERAL@") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
921 and type_node.nodeName == C.GENERAL |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
922 ) or ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
923 (type_ == "@ALL@" or type_ == "@INDIVIDUAL@") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
924 and type_node.nodeName == C.INDIVIDUAL |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
925 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
926 for node in type_node.getElementsByTagName("category"): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
927 if node.getAttribute("name") == category: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
928 params = node.getElementsByTagName("param") |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
929 for param in params: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
930 if param.getAttribute("name") == name: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
931 return (type_node.nodeName, param) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
932 return None |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
933 |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
934 def getParamsCategories(self): |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
935 """return the categories availables""" |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
936 categories = [] |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
937 for cat in self.dom.getElementsByTagName("category"): |
396
cecd22241d56
memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
938 name = cat.getAttribute("name") |
cecd22241d56
memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
939 if name not in categories: |
cecd22241d56
memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
940 categories.append(cat.getAttribute("name")) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
941 return categories |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
942 |
3040 | 943 def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, |
944 profile_key=C.PROF_KEY_NONE): | |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
945 """Set a parameter, return None if the parameter is not in param xml. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
946 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
947 Parameter of type 'password' that are not the SàT profile password are |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
948 stored encrypted (if not empty). The profile password is stored hashed |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
949 (if not empty). |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
950 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
951 @param name (str): the parameter name |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
952 @param value (str): the new value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
953 @param category (str): the parameter category |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
954 @param security_limit (int) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
955 @param profile_key (str): %(doc_profile_key)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
956 @return: a deferred None value when everything is done |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
957 """ |
1534
a5e0393a06cd
plugin ip, params: plugin IP discovery, first draft:
Goffi <goffi@goffi.org>
parents:
1519
diff
changeset
|
958 # FIXME: setParam should accept the right type for value, not only str ! |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
959 if profile_key != C.PROF_KEY_NONE: |
392
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
960 profile = self.getProfileName(profile_key) |
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
961 if not profile: |
3028 | 962 log.error(_("Trying to set parameter for an unknown profile")) |
1836
fb94f92dc740
core (params): return given profile for ProfileUnknownError
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
963 raise exceptions.ProfileUnknownError(profile_key) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
964 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
965 node = self._getParamNode(name, category, "@ALL@") |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
966 if not node: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
967 log.error( |
3028 | 968 _("Requesting an unknown parameter (%(category)s/%(name)s)") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
969 % {"category": category, "name": name} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
970 ) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
971 return defer.succeed(None) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
972 |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
973 if not self.checkSecurityLimit(node[1], security_limit): |
3040 | 974 msg = _( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
975 "{profile!r} is trying to set parameter {name!r} in category " |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
976 "{category!r} without authorization!!!").format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
977 profile=repr(profile), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
978 name=repr(name), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
979 category=repr(category) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
980 ) |
3040 | 981 log.warning(msg) |
982 raise exceptions.PermissionError(msg) | |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
983 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
984 type_ = node[1].getAttribute("type") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
985 if type_ == "int": |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
986 if not value: # replace with the default value (which might also be '') |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
987 value = node[1].getAttribute("value") |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
988 else: |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
989 try: |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
990 int(value) |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
991 except ValueError: |
3040 | 992 log.warning(_( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
993 "Trying to set parameter {name} in category {category} with" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
994 "an non-integer value" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
995 ).format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
996 name=repr(name), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
997 category=repr(category) |
3040 | 998 )) |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
999 return defer.succeed(None) |
1226
72f25d671368
memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
1000 if node[1].hasAttribute("constraint"): |
72f25d671368
memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
1001 constraint = node[1].getAttribute("constraint") |
72f25d671368
memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
1002 try: |
72f25d671368
memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
1003 min_, max_ = [int(limit) for limit in constraint.split(";")] |
72f25d671368
memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
1004 except ValueError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1005 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1006 "Invalid integer parameter constraint: %s" % constraint |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1007 ) |
1226
72f25d671368
memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
1008 value = str(min(max(int(value), min_), max_)) |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
1009 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1010 log.info( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1011 _("Setting parameter (%(category)s, %(name)s) = %(value)s") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1012 % { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1013 "category": category, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1014 "name": name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1015 "value": value if type_ != "password" else "********", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1016 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1017 ) |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
639
diff
changeset
|
1018 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
1019 if node[0] == C.GENERAL: |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
1020 self.params_gen[(category, name)] = value |
412 | 1021 self.storage.setGenParam(category, name, value) |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
1022 for profile in self.storage.getProfilesList(): |
1688
59a94105b138
core(params): replaced isConnected by isSessionStarted for profile update signal when a general param is modified
Goffi <goffi@goffi.org>
parents:
1686
diff
changeset
|
1023 if self.host.memory.isSessionStarted(profile): |
392
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1024 self.host.bridge.paramUpdate(name, value, category, profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1025 self.host.trigger.point( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1026 "paramUpdateTrigger", name, value, category, node[0], profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1027 ) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1028 return defer.succeed(None) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1029 |
1477
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
1030 assert node[0] == C.INDIVIDUAL |
ac522c4dab0e
core (params): jids_list type management
Goffi <goffi@goffi.org>
parents:
1460
diff
changeset
|
1031 assert profile_key != C.PROF_KEY_NONE |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
1032 |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
1033 if type_ == "button": |
3028 | 1034 log.debug("Clicked param button %s" % node.toxml()) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1035 return defer.succeed(None) |
1686
1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
Goffi <goffi@goffi.org>
parents:
1651
diff
changeset
|
1036 elif type_ == "password": |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1037 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1038 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1039 C.MEMORY_CRYPTO_KEY |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1040 ] |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1041 except TypeError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1042 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1043 _("Trying to encrypt a password while the personal key is undefined!") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1044 ) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1045 if (category, name) == C.PROFILE_PASS_PATH: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1046 # using 'value' as the encryption key to encrypt another encryption key... could be confusing! |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1047 d = self.host.memory.encryptPersonalData( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1048 data_key=C.MEMORY_CRYPTO_KEY, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1049 data_value=personal_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1050 crypto_key=value, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1051 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1052 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1053 d.addCallback( |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
1054 lambda __: PasswordHasher.hash(value) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1055 ) # profile password is hashed (empty value stays empty) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1056 elif value: # other non empty passwords are encrypted with the personal key |
3160
330a5f1d9eea
core (memory/crypto): replaced `PyCrypto` by `cryptography`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1057 d = defer.succeed(BlockCipher.encrypt(personal_key, value)) |
1931
2c55e7e99ef3
core (memory/params): fixed exception when setting an empty password
Goffi <goffi@goffi.org>
parents:
1836
diff
changeset
|
1058 else: |
2c55e7e99ef3
core (memory/params): fixed exception when setting an empty password
Goffi <goffi@goffi.org>
parents:
1836
diff
changeset
|
1059 d = defer.succeed(value) |
1686
1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
Goffi <goffi@goffi.org>
parents:
1651
diff
changeset
|
1060 else: |
1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
Goffi <goffi@goffi.org>
parents:
1651
diff
changeset
|
1061 d = defer.succeed(value) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1062 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1063 def gotFinalValue(value): |
1686
1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
Goffi <goffi@goffi.org>
parents:
1651
diff
changeset
|
1064 if self.host.memory.isSessionStarted(profile): |
412 | 1065 self.params[profile][(category, name)] = value |
1686
1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
Goffi <goffi@goffi.org>
parents:
1651
diff
changeset
|
1066 self.host.bridge.paramUpdate(name, value, category, profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1067 self.host.trigger.point( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1068 "paramUpdateTrigger", name, value, category, node[0], profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1069 ) |
1686
1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
Goffi <goffi@goffi.org>
parents:
1651
diff
changeset
|
1070 return self.storage.setIndParam(category, name, value, profile) |
1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
Goffi <goffi@goffi.org>
parents:
1651
diff
changeset
|
1071 else: |
1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
Goffi <goffi@goffi.org>
parents:
1651
diff
changeset
|
1072 raise exceptions.ProfileNotConnected |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1073 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1074 d.addCallback(gotFinalValue) |
1686
1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
Goffi <goffi@goffi.org>
parents:
1651
diff
changeset
|
1075 return d |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1076 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1077 def _getNodesOfTypes(self, attr_type, node_type="@ALL@"): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1078 """Return all the nodes matching the given types. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1079 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1080 TODO: using during the dev but not anymore... remove if not needed |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1081 |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
1082 @param attr_type (str): the attribute type (string, text, password, bool, int, button, list) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1083 @param node_type (str): keyword for filtering: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1084 @ALL@ search everywhere |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1085 @GENERAL@ only search in general type |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1086 @INDIVIDUAL@ only search in individual type |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1087 @return: dict{tuple: node}: a dict {key, value} where: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1088 - key is a couple (attribute category, attribute name) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1089 - value is a node |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1090 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1091 ret = {} |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1092 for type_node in self.dom.documentElement.childNodes: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1093 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1094 (node_type == "@ALL@" or node_type == "@GENERAL@") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1095 and type_node.nodeName == C.GENERAL |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1096 ) or ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1097 (node_type == "@ALL@" or node_type == "@INDIVIDUAL@") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1098 and type_node.nodeName == C.INDIVIDUAL |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1099 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1100 for cat_node in type_node.getElementsByTagName("category"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1101 cat = cat_node.getAttribute("name") |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1102 params = cat_node.getElementsByTagName("param") |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1103 for param in params: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1104 if param.getAttribute("type") == attr_type: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1105 ret[(cat, param.getAttribute("name"))] = param |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
1106 return ret |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1107 |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1108 def checkSecurityLimit(self, node, security_limit): |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1109 """Check the given node against the given security limit. |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1110 The value NO_SECURITY_LIMIT (-1) means that everything is allowed. |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1111 @return: True if this node can be accessed with the given security limit. |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1112 """ |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1113 if security_limit < 0: |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1114 return True |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1115 if node.hasAttribute("security"): |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1116 if int(node.getAttribute("security")) <= security_limit: |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1117 return True |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1118 return False |
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
1119 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
1120 def checkApp(self, node, app): |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
1121 """Check the given node against the given app. |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1122 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
1123 @param node: parameter node |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
1124 @param app: name of the frontend requesting the parameters, or '' to get all parameters |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
1125 @return: True if this node concerns the given app. |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
1126 """ |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
1127 if not app or not node.hasAttribute("app"): |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
1128 return True |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
1129 return node.getAttribute("app") == app |
3105
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1130 |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1131 def checkExtra(self, node, extra): |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1132 """Check the given node against the extra filters. |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1133 |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1134 @param node: parameter node |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1135 @param app: name of the frontend requesting the parameters, or '' to get all parameters |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1136 @return: True if node doesn't match category/name of extra['ignore'] list |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1137 """ |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1138 ignore_list = extra.get('ignore') |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1139 if not ignore_list: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1140 return True |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1141 category = node.parentNode.getAttribute('name') |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1142 name = node.getAttribute('name') |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1143 ignore = [category, name] in ignore_list |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1144 if ignore: |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1145 log.debug(f"Ignoring parameter {category}/{name} as requested") |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1146 return False |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1147 return True |
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
1148 |
3105
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1149 |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1150 def makeOptions(options, selected=None): |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1151 """Create option XML form dictionary |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1152 |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1153 @param options(dict): option's name => option's label map |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1154 @param selected(None, str): value of selected option |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1155 None to use first value |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1156 @return (str): XML to use in parameters |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1157 """ |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1158 str_list = [] |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1159 if selected is None: |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1160 selected = next(iter(options.keys())) |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1161 selected_found = False |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1162 for value, label in options.items(): |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1163 if value == selected: |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1164 selected = 'selected="true"' |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1165 selected_found = True |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1166 else: |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1167 selected = '' |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1168 str_list.append( |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1169 f'<option value={quoteattr(value)} label={quoteattr(label)} {selected}/>' |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1170 ) |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1171 if not selected_found: |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1172 raise ValueError(f"selected value ({selected}) not found in options") |
eec0c25c796b
core (memory/params): new "makeOptions" method to easily create options XML from a dict
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1173 return '\n'.join(str_list) |