Mercurial > libervia-backend
annotate src/memory/params.py @ 1039:902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 20 May 2014 09:34:02 +0200 |
parents | 6e975c6b0faf |
children | 59de0c7a28ec |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
4 # SAT: a jabber client |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
7 # 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
|
8 # 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
|
9 # 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
|
10 # (at your option) any later version. |
0 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
12 # 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
|
13 # 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
|
14 # 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
|
15 # GNU Affero General Public License for more details. |
0 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
17 # 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
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
771 | 20 from sat.core.i18n import _ |
0 | 21 |
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
|
22 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
|
23 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
|
24 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
|
25 from xml.dom import minidom, NotFoundErr |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
26 from sat.core.log import getLogger |
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 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
784
diff
changeset
|
30 from sat.tools.xml_tools import paramsXML2XMLUI |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
31 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
32 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
33 class Params(object): |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
34 """This class manage parameters with xml""" |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
35 ### TODO: add desciption in params |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
36 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
37 #TODO: move Watched in a plugin |
611 | 38 #TODO: when priority is changed, a new presence stanza must be emitted |
39 #TODO: int type (Priority should be int instead of string) | |
34
a544b376b6f0
use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
40 default_xml = u""" |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
41 <params> |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
42 <general> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
43 </general> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
44 <individual> |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
45 <category name="General" label="%(category_general)s"> |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
46 <param name="Password" value="" type="password" /> |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
47 </category> |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
48 <category name="Connection" label="%(category_connection)s"> |
256
f5181f6dd98f
Test value replaced by example values for memory params
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
49 <param name="JabberID" value="name@example.org/SàT" type="string" /> |
f5181f6dd98f
Test value replaced by example values for memory params
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
50 <param name="Password" value="" type="password" /> |
611 | 51 <param name="Priority" value="50" type="string" /> |
256
f5181f6dd98f
Test value replaced by example values for memory params
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
52 <param name="Server" value="example.org" type="string" /> |
556 | 53 <param name="Port" value="5222" type="string" /> |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
784
diff
changeset
|
54 <param name="NewAccount" label="%(label_NewAccount)s" type="button" callback_id="registerNewAccount"/> |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
55 <param name="autoconnect" label="%(label_autoconnect)s" value="true" type="bool" /> |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
56 <param name="autodisconnect" label="%(label_autodisconnect)s" value="false" type="bool" /> |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
57 </category> |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
58 <category name="Misc" label="%(category_misc)s"> |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
59 <param name="Watched" value="test@Jabber.goffi.int" type="string" /> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
60 </category> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
61 </individual> |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
62 </params> |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
63 """ % { |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
64 'category_general': _("General"), |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
65 'category_connection': _("Connection"), |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
66 'label_NewAccount': _("Register new account"), |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
67 'label_autoconnect': _('Connect on frontend startup'), |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
68 'label_autodisconnect': _('Disconnect on frontend closure'), |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
69 'category_misc': _("Misc") |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
70 } |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
71 |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
72 def load_default_params(self): |
458
094050fe461e
core: fixed Params class name in load_default_params
Goffi <goffi@goffi.org>
parents:
443
diff
changeset
|
73 self.dom = minidom.parseString(Params.default_xml.encode('utf-8')) |
38 | 74 |
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
|
75 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
|
76 """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
|
77 |
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
|
78 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
|
79 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
|
80 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
|
81 if child.nodeType == child.ELEMENT_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
|
82 ret[(child.tagName, child.getAttribute('name'))] = child |
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
|
83 return 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 to_add = source_set.difference(dest_set) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
89 |
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
|
90 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
|
91 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
|
92 |
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
|
93 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
|
94 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
|
95 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
|
96 |
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
|
97 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
|
98 """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
|
99 self.dom = minidom.parse(xml_file) |
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
|
100 default_dom = minidom.parseString(Params.default_xml.encode('utf-8')) |
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
|
101 self._mergeParams(default_dom.documentElement, self.dom.documentElement) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
102 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
103 def loadGenParams(self): |
412 | 104 """Load general parameters data from storage |
105 @return: deferred triggered once params are loaded""" | |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
106 return self.storage.loadGenParams(self.params_gen) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
107 |
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
|
108 def loadIndParams(self, profile, cache=None): |
412 | 109 """Load individual parameters |
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
|
110 set self.params cache or a temporary cache |
412 | 111 @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
|
112 @param cache: if not None, will be used to store the value, as a short time cache |
412 | 113 @return: deferred triggered once params are loaded""" |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
114 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
|
115 self.params[profile] = {} |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
116 return self.storage.loadIndParams(self.params[profile] if cache is None else cache, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
117 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
118 def purgeProfile(self, profile): |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
119 """Remove cache data of a profile |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
120 @param profile: %(doc_profile)s""" |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
121 try: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
122 del self.params[profile] |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
123 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
124 log.error(_("Trying to purge cache of a profile not in memory: [%s]") % profile) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
125 |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
126 def save_xml(self, filename): |
61 | 127 """Save parameters template to xml file""" |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
128 with open(filename, 'wb') as xml_file: |
214 | 129 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
|
130 |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
131 def __init__(self, host, storage): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
132 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
|
133 self.host = host |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
134 self.storage = storage |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
135 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
|
136 self.params = {} |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
137 self.params_gen = {} |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
138 |
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
|
139 def asyncCreateProfile(self, profile): |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
140 """Create a new profile |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
141 @param profile: name of the profile |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
142 @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
|
143 @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
|
144 """ |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
145 if self.storage.hasProfile(profile): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
146 log.info(_('The profile name already exists')) |
751
1def5b7edf9f
core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents:
747
diff
changeset
|
147 return defer.fail(Failure(exceptions.ConflictError)) |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
148 if not self.host.trigger.point("ProfileCreation", profile): |
751
1def5b7edf9f
core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents:
747
diff
changeset
|
149 return defer.fail(Failure(exceptions.CancelError)) |
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
|
150 return self.storage.createProfile(profile) |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
151 |
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
|
152 def asyncDeleteProfile(self, profile, force=False): |
68 | 153 """Delete an existing profile |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
938
diff
changeset
|
154 |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
866
diff
changeset
|
155 @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
|
156 @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
|
157 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
|
158 @return: a Deferred instance |
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
866
diff
changeset
|
159 """ |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
160 if not self.storage.hasProfile(profile): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
161 log.info(_('Trying to delete an unknown profile')) |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
866
diff
changeset
|
162 return defer.fail(Failure(exceptions.ProfileUnknownError)) |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
163 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
|
164 if force: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
165 self.host.disconnect(profile) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
166 else: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
167 log.info(_("Trying to delete a connected profile")) |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
168 return defer.fail(Failure(exceptions.ConnectedProfileError)) |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
866
diff
changeset
|
169 return self.storage.deleteProfile(profile) |
68 | 170 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
171 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
|
172 """return profile according to profile_key |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
938
diff
changeset
|
173 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
174 @param profile_key: profile name or key which can be |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
175 @ALL@ for all profiles |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
176 @DEFAULT@ for default profile |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
177 @param return_profile_keys: if True, return unmanaged profile keys (like "@ALL@"). This keys must be managed by the caller |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
178 @return: requested profile name or emptry string if it doesn't exist""" |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
179 if profile_key == '@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
|
180 default = self.host.memory.memory_data.get('Profile_default') |
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
|
181 if not default: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
182 log.info(_('No default profile, returning first one')) # TODO: manage real default profile |
625
5646ecd3e35e
core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents:
620
diff
changeset
|
183 try: |
5646ecd3e35e
core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents:
620
diff
changeset
|
184 default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0] |
5646ecd3e35e
core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents:
620
diff
changeset
|
185 except IndexError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
186 log.info(_('No profile exist yet')) |
625
5646ecd3e35e
core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents:
620
diff
changeset
|
187 return "" |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
188 return default # 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
|
189 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
|
190 raise exceptions.ProfileNotSetError |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
191 elif return_profile_keys and profile_key in ["@ALL@"]: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
192 return profile_key # this value must be managed by the caller |
412 | 193 if not self.storage.hasProfile(profile_key): |
1023
8bae81e254a2
core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents:
1019
diff
changeset
|
194 log.error(_('Trying to access an unknown profile')) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
195 return "" # FIXME: raise exceptions.ProfileUnknownError here (must be well checked, this method is used in lot of places) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
196 return profile_key |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
197 |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
198 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
|
199 """return node with given tag |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
200 @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
|
201 @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
|
202 @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
|
203 @return: node if it exist or None |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
204 """ |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
205 for node in parent.childNodes: |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
206 if node.nodeName == tag and node.getAttribute("name") == name: |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
207 #the node already exists |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
208 return node |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
209 #the node is new |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
210 return None |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
211 |
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
|
212 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
|
213 """import xml in parameters, update if the param already exists |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
214 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
|
215 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
|
216 @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
|
217 @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
|
218 @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
|
219 """ |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
220 src_parent = minidom.parseString(xml.encode('utf-8')).documentElement |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
221 |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
222 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
|
223 """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
|
224 to_remove = [] |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 continue |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
229 for cat_node in type_node.childNodes: |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
230 if cat_node.nodeName != 'category': |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
231 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
|
232 continue |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
233 to_remove_count = 0 # count the params to be removed from current category |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
234 for node in cat_node.childNodes: |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
235 if node.nodeName != "param" or not self.checkSecurityLimit(node, security_limit): |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
236 to_remove.append(node) |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
237 to_remove_count += 1 |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
238 continue |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
239 node.setAttribute('app', app) |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
240 if len(cat_node.childNodes) == to_remove_count: # remove empty category |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
241 for dummy in xrange(0, to_remove_count): |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
242 to_remove.pop() |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
243 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
|
244 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
|
245 node.parentNode.removeChild(node) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
246 |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
247 def import_node(tgt_parent, src_parent): |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
248 for child in src_parent.childNodes: |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
249 if child.nodeName == '#text': |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
250 continue |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
251 node = self.__get_unique_node(tgt_parent, child.nodeName, child.getAttribute("name")) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
252 if not node: # The node is new |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
253 tgt_parent.appendChild(child) |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
254 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
|
255 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
|
256 # 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
|
257 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
|
258 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
|
259 # 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
|
260 import_node(node, child) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
261 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
262 if app: |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
263 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
|
264 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
|
265 |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
266 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
|
267 """Register frontend's specific parameters |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
268 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
|
269 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
|
270 @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
|
271 @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
|
272 @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
|
273 """ |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
274 if not app: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
275 log.warning(_("Trying to register frontends parameters with no specified app: aborted")) |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
276 return |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
277 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
|
278 self.frontends_cache = [] |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
279 if app in self.frontends_cache: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
280 log.debug(_("Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app})) |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
281 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
|
282 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
|
283 self.updateParams(xml, security_limit, app) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
284 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
|
285 |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
286 def __default_ok(self, value, name, category): |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
287 #FIXME: will not work with individual parameters |
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
288 self.setParam(name, value, category) |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
289 |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
290 def __default_ko(self, failure, name, category): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
291 log.error(_("Can't determine default value for [%(category)s/%(name)s]: %(reason)s") % {'category': category, 'name': name, 'reason': str(failure.value)}) |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
292 |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
293 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
|
294 """Set default value of parameter |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
295 '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
|
296 @param name: name of the parameter |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
297 @param category: category of the parameter |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
298 @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
|
299 @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
|
300 """ |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
301 #TODO: send signal param update if value changed |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
302 #TODO: manage individual paramaters |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
303 log.debug ("setDefault called for %(category)s/%(name)s" % {"category": category, "name": name}) |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
304 node = self._getParamNode(name, category, '@ALL@') |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
305 if not node: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
306 log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category}) |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
307 return |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
308 if node[1].getAttribute('default_cb') == 'yes': |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
309 # 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, |
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
310 # 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
|
311 value = self._getParam(category, name, C.GENERAL) |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
312 if value is None: # no value set by the user: we have the default value |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
313 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
|
314 d = defer.maybeDeferred(callback) |
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
315 d.addCallback(self.__default_ok, name, category) |
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
316 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
|
317 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
318 def _getAttr_internal(self, node, attr, value): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
319 """Get attribute value. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
320 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
321 /!\ This method would return encrypted password values. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
322 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
323 @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
|
324 @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
|
325 @param value: user defined value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
326 @return: str |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
327 """ |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
328 if attr == 'value': |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
329 value_to_use = value if value is not None else node.getAttribute(attr) # we use value (user defined) if it exist, else we use node's default value |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
330 if node.getAttribute('type') == 'bool': |
866
f27d736428f1
core (memory): added 'no' value management in configuration's booleans
Goffi <goffi@goffi.org>
parents:
853
diff
changeset
|
331 return value_to_use.lower() not in ('false', '0', 'no') |
1039
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
332 elif node.getAttribute('type') == 'list': |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
333 options = [option for option in node.childNodes if option.nodeName == 'option'] |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
334 values = [option.getAttribute('value') for option in options] |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
335 if value_to_use not in values: # value_to_use is probably empty |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
336 selected = [option for option in options if option.getAttribute('selected') == 'true'] |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
337 cat, param = node.parentNode.getAttribute('name'), node.getAttribute('name') |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
338 if len(selected) == 1: |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
339 value_to_use = selected[0].getAttribute('value') |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
340 log.info(_("Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'") % |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
341 {'cat': cat, 'param': param, 'value': value_to_use}) |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
342 return value_to_use |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
343 if len(selected) == 0: |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
344 log.error(_('Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param}) |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
345 else: |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
346 log.error(_('Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param}) |
902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
347 raise exceptions.DataError |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
348 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
|
349 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
|
350 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
351 def _getAttr(self, node, attr, value): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
352 """Get attribute value (synchronous). |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
353 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
354 /!\ 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
|
355 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
356 @param node: XML param node |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
357 @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
|
358 @param value: user defined value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
359 @return: str |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
360 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
361 if attr == 'value' and node.getAttribute('type') == 'password': |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
362 raise exceptions.InternalError('To retrieve password values, use _asyncGetAttr instead of _getAttr') |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
363 return self._getAttr_internal(node, attr, value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
364 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
365 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
|
366 """Get attribute value. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
367 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
368 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
|
369 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
|
370 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
371 @param node: XML param node |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
372 @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
|
373 @param value: user defined value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
374 @param profile: %(doc_profile)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
375 @return: a deferred str |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
376 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
377 value = self._getAttr_internal(node, attr, value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
378 if attr != 'value' or node.getAttribute('type') != 'password': |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
379 return defer.succeed(value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
380 param_cat = node.parentNode.getAttribute('name') |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
381 param_name = node.getAttribute('name') |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
382 if ((param_cat, param_name) == C.PROFILE_PASS_PATH) or not value: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
383 return defer.succeed(value) # profile password and empty passwords are returned "as is" |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
384 if not profile: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
385 raise exceptions.ProfileUnknownError('The profile is needed to decrypt a password') |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
386 try: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
387 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
388 except TypeError: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
389 raise exceptions.InternalError(_('Trying to decrypt a password while the personal key is undefined!')) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
390 d = BlockCipher.decrypt(personal_key, value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
391 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
392 def gotPlainPassword(password): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
393 if password is None: # empty value means empty password, None means decryption failure |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
394 raise exceptions.InternalError(_('The stored password could not be decrypted!')) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
395 return password |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
396 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
397 return d.addCallback(gotPlainPassword) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
398 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
399 def __type_to_string(self, result): |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
400 """ 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
|
401 if isinstance(result, bool): |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
402 return "true" if result else "false" |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
403 return result |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
404 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
405 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
|
406 """ Same as getParamA but for bridge: convert non string value to string """ |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
407 return self.__type_to_string(self.getParamA(name, category, attr, profile_key)) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
408 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
409 def getParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
410 """Helper method to get a specific attribute. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
411 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
412 /!\ This method would return encrypted password values, |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
413 to get the plain values you have to use _asyncGetParamA. |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
414 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
415 @param name: name of the parameter |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
416 @param category: category of the parameter |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
417 @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
|
418 @param profile: owner of the param (@ALL@ for everyone) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
419 @return: attribute |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
420 """ |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
421 #FIXME: looks really dirty and buggy, need to be reviewed/refactored |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
422 node = self._getParamNode(name, category) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
423 if not node: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
424 log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category}) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
425 raise exceptions.NotFound |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
426 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
427 if attr == 'value' and node[1].getAttribute('type') == 'password': |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
428 raise exceptions.InternalError('To retrieve password values, use asyncGetParamA instead of getParamA') |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
429 |
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
|
430 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
|
431 value = self._getParam(category, name, C.GENERAL) |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
432 return self._getAttr(node[1], attr, value) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
433 |
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
|
434 assert node[0] == C.INDIVIDUAL |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
435 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
436 profile = self.getProfileName(profile_key) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
437 if not profile: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
438 log.error(_('Requesting a param for an non-existant profile')) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
439 raise exceptions.ProfileUnknownError |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
440 |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
441 if profile not in self.params: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
442 log.error(_('Requesting synchronous param for not connected profile')) |
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
|
443 raise exceptions.NotConnectedProfileError(profile) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
444 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
445 if attr == "value": |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
446 value = self._getParam(category, name, profile=profile) |
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
447 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
|
448 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
449 def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
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
|
450 d = self.asyncGetParamA(name, category, attr, security_limit, profile_key) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
451 d.addCallback(self.__type_to_string) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
452 return d |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
453 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
454 def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
455 """Helper method to get a specific attribute. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
456 @param name: name of the parameter |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
457 @param category: category of the parameter |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
458 @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
|
459 @param profile: owner of the param (@ALL@ for everyone) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
460 @return: Deferred |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
461 """ |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
462 node = self._getParamNode(name, category) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
463 if not node: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
464 log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category}) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
465 return defer.succeed(None) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
466 |
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
|
467 if not self.checkSecurityLimit(node[1], security_limit): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
468 log.warning(_("Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!" |
844
f3513c8cc2e6
misc: fix unnamed arguments in format strings
souliane <souliane@mailoo.org>
parents:
833
diff
changeset
|
469 % {'param': name, 'cat': category})) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
470 return defer.succeed(None) |
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
|
471 |
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
|
472 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
|
473 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
|
474 return self._asyncGetAttr(node[1], attr, value) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
475 |
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
|
476 assert node[0] == C.INDIVIDUAL |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
477 |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
478 profile = self.getProfileName(profile_key) |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
479 if not profile: |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
480 raise exceptions.InternalError(_('Requesting a param for a non-existant profile')) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
481 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
482 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
|
483 return defer.succeed(node[1].getAttribute(attr)) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
484 try: |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
485 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
|
486 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
|
487 except exceptions.ProfileNotInCacheError: |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
488 #We have to ask data to the storage manager |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
489 d = self.storage.getIndParam(category, name, profile) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
490 return d.addCallback(lambda value: self._asyncGetAttr(node[1], attr, value, profile)) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
491 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
492 def _getParam(self, category, name, type_=C.INDIVIDUAL, cache=None, profile=C.PROF_KEY_NONE): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
493 """Return the param, or None if it doesn't exist |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
494 @param category: param category |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
495 @param name: param name |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
496 @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
|
497 @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
|
498 @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
|
499 @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
|
500 """ |
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
|
501 if type_ == C.GENERAL: |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
502 if (category, name) in self.params_gen: |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
503 return self.params_gen[(category, name)] |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
504 return None # This general param has the default value |
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
|
505 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
|
506 if profile == C.PROF_KEY_NONE: |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
507 raise exceptions.ProfileNotSetError |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
508 if profile in self.params: |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
509 cache = self.params[profile] # if profile is in main cache, we use it, |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
510 # ignoring the temporary cache |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
511 elif cache is None: # 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
|
512 raise exceptions.ProfileNotInCacheError |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
513 if (category, name) not in cache: |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
514 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
|
515 return cache[(category, name)] |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
516 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
517 def __constructProfileXml(self, security_limit, app, profile): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
518 """Construct xml for asked profile, filling values when needed |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
519 /!\ 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
|
520 @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
|
521 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
|
522 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
|
523 @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
|
524 @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
|
525 @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
|
526 """ |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
527 |
784
900987e1c0c4
memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents:
779
diff
changeset
|
528 def checkNode(node): |
900987e1c0c4
memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents:
779
diff
changeset
|
529 """Check the node against security_limit and app""" |
900987e1c0c4
memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents:
779
diff
changeset
|
530 return self.checkSecurityLimit(node, security_limit) and self.checkApp(node, app) |
900987e1c0c4
memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents:
779
diff
changeset
|
531 |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
532 def constructProfile(ignore, profile_cache): |
634
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
533 # init the result document |
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
|
534 prof_xml = minidom.parseString('<params/>') |
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
|
535 cache = {} |
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
|
536 |
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
|
537 for type_node in self.dom.documentElement.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
|
538 if type_node.nodeName != C.GENERAL and type_node.nodeName != C.INDIVIDUAL: |
634
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
539 continue |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
540 # we use all params, general and individual |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
541 for cat_node in type_node.childNodes: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
542 if cat_node.nodeName != 'category': |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
543 continue |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
544 category = cat_node.getAttribute('name') |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
545 dest_params = {} # result (merged) params for category |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
546 if category not in cache: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
547 # we make a copy for the new xml |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
548 cache[category] = dest_cat = cat_node.cloneNode(True) |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
549 for node in dest_cat.childNodes: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
550 if node.nodeName != "param": |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
551 continue |
784
900987e1c0c4
memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents:
779
diff
changeset
|
552 if not checkNode(node): |
779
a978c703bf57
memory: bug fix related to method paramsRegisterApp + getParams was not always returning a Deferred
souliane <souliane@mailoo.org>
parents:
778
diff
changeset
|
553 dest_cat.removeChild(node) |
a978c703bf57
memory: bug fix related to method paramsRegisterApp + getParams was not always returning a Deferred
souliane <souliane@mailoo.org>
parents:
778
diff
changeset
|
554 continue |
634
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
555 dest_params[node.getAttribute('name')] = node |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
556 new_node = True |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
557 else: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
558 # It's not a new node, we use the previously cloned one |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
559 dest_cat = cache[category] |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
560 new_node = False |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
561 params = cat_node.getElementsByTagName("param") |
395
79fe50fc8edc
memory: multiples params of the same category are now merged
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
562 |
634
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
563 for param_node in params: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
564 # we have to merge new params (we are parsing individual parameters, we have to add them |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
565 # to the previously parsed general ones) |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
566 name = param_node.getAttribute('name') |
784
900987e1c0c4
memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents:
779
diff
changeset
|
567 if not checkNode(param_node): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
568 continue |
634
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
569 if name not in dest_params: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
570 # this is reached when a previous category exists |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
571 dest_params[name] = param_node.cloneNode(True) |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
572 dest_cat.appendChild(dest_params[name]) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
573 |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
574 profile_value = self._getParam(category, |
634
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
575 name, type_node.nodeName, |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
576 cache=profile_cache, profile=profile) |
634
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
577 if profile_value is not None: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
578 # there is a value for this profile, we must change the default |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
579 if dest_params[name].getAttribute('type') == 'list': |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
580 for option in dest_params[name].getElementsByTagName("option"): |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
581 if option.getAttribute('value') == profile_value: |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
582 option.setAttribute('selected', 'true') |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
583 else: |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
584 try: |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
585 option.removeAttribute('selected') |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
586 except NotFoundErr: |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
587 pass |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
588 else: |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
589 dest_params[name].setAttribute('value', profile_value) |
634
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
590 if new_node: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
591 prof_xml.documentElement.appendChild(dest_cat) |
395
79fe50fc8edc
memory: multiples params of the same category are now merged
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
592 |
634
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
593 to_remove = [] |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
594 for cat_node in prof_xml.documentElement.childNodes: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
595 # we remove empty categories |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
596 if cat_node.getElementsByTagName("param").length == 0: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
597 to_remove.append(cat_node) |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
598 for node in to_remove: |
ca2cae6b2c6d
core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
599 prof_xml.documentElement.removeChild(node) |
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
|
600 return prof_xml |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
601 |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
602 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
|
603 d = defer.succeed(None) |
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
|
604 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
|
605 else: |
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
|
606 #profile is not in cache, we load values in a short time cache |
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
|
607 profile_cache = {} |
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
|
608 d = self.loadIndParams(profile, profile_cache) |
395
79fe50fc8edc
memory: multiples params of the same category are now merged
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
609 |
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
|
610 return d.addCallback(constructProfile, profile_cache) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
611 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
612 def getParamsUI(self, security_limit, app, profile_key): |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
613 """ |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
614 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params. |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
615 Otherwise sole the params which have a security level defined *and* |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
616 lower or equal to the specified value are returned. |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
617 @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
|
618 @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
|
619 @return: a SàT XMLUI for parameters |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
620 """ |
105 | 621 profile = self.getProfileName(profile_key) |
622 if not profile: | |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
623 log.error(_("Asking params for inexistant profile")) |
105 | 624 return "" |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
625 d = self.getParams(security_limit, app, profile) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
784
diff
changeset
|
626 return d.addCallback(lambda param_xml: paramsXML2XMLUI(param_xml)) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
627 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
628 def getParams(self, security_limit, app, profile_key): |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
629 """Construct xml for asked profile, take params xml as skeleton |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
630 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params. |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
631 Otherwise sole the params which have a security level defined *and* |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
632 lower or equal to the specified value are returned. |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
633 @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
|
634 @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
|
635 @return: XML of parameters |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
636 """ |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
637 profile = self.getProfileName(profile_key) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
638 if not profile: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
639 log.error(_("Asking params for inexistant profile")) |
779
a978c703bf57
memory: bug fix related to method paramsRegisterApp + getParams was not always returning a Deferred
souliane <souliane@mailoo.org>
parents:
778
diff
changeset
|
640 return defer.succeed("") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
641 |
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
|
642 def returnXML(prof_xml): |
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
|
643 return_xml = prof_xml.toxml() |
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
|
644 prof_xml.unlink() |
643
262d9d9ad27a
plugin XEP-0085: renamed category and parameter
souliane <souliane@mailoo.org>
parents:
642
diff
changeset
|
645 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
|
646 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
647 return self.__constructProfileXml(security_limit, app, profile).addCallback(returnXML) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
648 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
649 def getParamsForCategory(self, category, security_limit, app, profile_key): |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
650 """ |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
651 @param category: the desired category |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
652 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params. |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
653 Otherwise sole the params which have a security level defined *and* |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
654 lower or equal to the specified value are returned. |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
655 @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
|
656 @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
|
657 @return: node's xml for selected category |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
658 """ |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
659 #TODO: manage category of general type (without existant profile) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
660 profile = self.getProfileName(profile_key) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
661 if not profile: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
662 log.error(_("Asking params for inexistant profile")) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
663 return "" |
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
|
664 |
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
|
665 def returnCategoryXml(prof_xml): |
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
|
666 for node in prof_xml.getElementsByTagName("category"): |
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
|
667 if node.nodeName == "category" and node.getAttribute("name") == category: |
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
|
668 result = node.toxml() |
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
|
669 prof_xml.unlink() |
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
|
670 return result |
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
|
671 |
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
|
672 prof_xml.unlink() |
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
|
673 return "<category />" |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
674 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
675 d = self.__constructProfileXml(security_limit, app, profile) |
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
|
676 return d.addCallback(returnCategoryXml) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
677 |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
678 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
|
679 """Return a node from the param_xml |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
680 @param name: name of the node |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
681 @param category: category of the node |
1019 | 682 @param type_: keyword for search: |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
683 @ALL@ search everywhere |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
684 @GENERAL@ only search in general type |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
685 @INDIVIDUAL@ only search in individual type |
1019 | 686 @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
|
687 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
688 for type_node in self.dom.documentElement.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
|
689 if (((type_ == "@ALL@" or type_ == "@GENERAL@") and type_node.nodeName == 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
|
690 or ((type_ == "@ALL@" or type_ == "@INDIVIDUAL@") and type_node.nodeName == C.INDIVIDUAL)): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
691 for node in type_node.getElementsByTagName('category'): |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
692 if node.getAttribute("name") == category: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
693 params = node.getElementsByTagName("param") |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
694 for param in params: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
695 if param.getAttribute("name") == name: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
696 return (type_node.nodeName, param) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
697 return None |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
698 |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
699 def getParamsCategories(self): |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
700 """return the categories availables""" |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
701 categories = [] |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
702 for cat in self.dom.getElementsByTagName("category"): |
396
cecd22241d56
memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
703 name = cat.getAttribute("name") |
cecd22241d56
memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
704 if name not in categories: |
cecd22241d56
memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
705 categories.append(cat.getAttribute("name")) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
706 return categories |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
707 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
708 def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
709 """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
|
710 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
711 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
|
712 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
|
713 (if not empty). |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
714 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
715 @param name (str): the parameter name |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
716 @param value (str): the new value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
717 @param category (str): the parameter category |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
718 @param security_limit (int) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
719 @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
|
720 @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
|
721 """ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
722 if profile_key != C.PROF_KEY_NONE: |
392
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
723 profile = self.getProfileName(profile_key) |
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
724 if not profile: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
725 log.error(_('Trying to set parameter for an unknown profile')) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
726 raise exceptions.ProfileUnknownError |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
727 |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
728 node = self._getParamNode(name, category, '@ALL@') |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
729 if not node: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
730 log.error(_('Requesting an unknown parameter (%(category)s/%(name)s)') |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
639
diff
changeset
|
731 % {'category': category, 'name': name}) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
732 return defer.succeed(None) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
733 |
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
|
734 if not self.checkSecurityLimit(node[1], security_limit): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
735 log.warning(_("Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!" |
844
f3513c8cc2e6
misc: fix unnamed arguments in format strings
souliane <souliane@mailoo.org>
parents:
833
diff
changeset
|
736 % {'param': name, 'cat': category})) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
737 return defer.succeed(None) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
738 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
739 type_ = node[1].getAttribute("type") |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
740 log.info(_("Setting parameter (%(category)s, %(name)s) = %(value)s") % |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
741 {'category': category, 'name': name, 'value': value if type_ != 'password' else '********'}) |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
639
diff
changeset
|
742 |
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
|
743 if node[0] == C.GENERAL: |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
744 self.params_gen[(category, name)] = value |
412 | 745 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
|
746 for profile in self.storage.getProfilesList(): |
392
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
747 if self.host.isConnected(profile): |
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
748 self.host.bridge.paramUpdate(name, value, category, profile) |
635
eff8772fd472
core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents:
634
diff
changeset
|
749 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
750 return defer.succeed(None) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
751 |
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
|
752 assert (node[0] == 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
|
753 assert (profile_key != C.PROF_KEY_NONE) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
754 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
755 d_list = [] |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
756 if type_ == "button": |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
757 log.debug("Clicked param button %s" % node.toxml()) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
758 return defer.succeed(None) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
759 elif type_ == "password": |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
760 try: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
761 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
762 except TypeError: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
763 raise exceptions.InternalError(_('Trying to encrypt a password while the personal key is undefined!')) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
764 if (category, name) == C.PROFILE_PASS_PATH: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
765 # using 'value' as the encryption key to encrypt another encryption key... could be confusing! |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
766 d_list.append(self.host.memory.encryptPersonalData(data_key=C.MEMORY_CRYPTO_KEY, |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
767 data_value=personal_key, |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
768 crypto_key=value, |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
769 profile=profile)) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
770 d = PasswordHasher.hash(value) # profile password is hashed (empty value stays empty) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
771 elif value: # other non empty passwords are encrypted with the personal key |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
772 d = BlockCipher.encrypt(personal_key, value) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
773 else: |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
774 d = defer.succeed(value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
775 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
776 def gotFinalValue(value): |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
777 if self.host.isConnected(profile): # key can not exists if profile is not connected |
412 | 778 self.params[profile][(category, name)] = value |
779 self.host.bridge.paramUpdate(name, value, category, profile) | |
635
eff8772fd472
core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents:
634
diff
changeset
|
780 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
781 d_list.append(self.storage.setIndParam(category, name, value, profile)) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
782 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
783 d.addCallback(gotFinalValue) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
784 return defer.DeferredList(d_list).addCallback(lambda dummy: None) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
785 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
786 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
|
787 """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
|
788 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
789 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
|
790 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
791 @param attr_type (str): the attribute type (string, text, password, bool, button, list) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
792 @param node_type (str): keyword for filtering: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
793 @ALL@ search everywhere |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
794 @GENERAL@ only search in general type |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
795 @INDIVIDUAL@ only search in individual type |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
796 @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
|
797 - 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
|
798 - value is a node |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
799 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
800 ret = {} |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
801 for type_node in self.dom.documentElement.childNodes: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
802 if (((node_type == "@ALL@" or node_type == "@GENERAL@") and type_node.nodeName == C.GENERAL) or |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
803 ((node_type == "@ALL@" or node_type == "@INDIVIDUAL@") and type_node.nodeName == C.INDIVIDUAL)): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
804 for cat_node in type_node.getElementsByTagName('category'): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
805 cat = cat_node.getAttribute('name') |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
806 params = cat_node.getElementsByTagName("param") |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
807 for param in params: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
808 if param.getAttribute("type") == attr_type: |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
809 ret[(cat, param.getAttribute("name"))] = param |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1023
diff
changeset
|
810 return ret |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
811 |
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
|
812 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
|
813 """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
|
814 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
|
815 @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
|
816 """ |
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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
824 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
|
825 """Check the given node against the given app. |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
826 @param node: parameter node |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
827 @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
|
828 @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
|
829 """ |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
830 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
|
831 return True |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
832 return node.getAttribute("app") == app |