annotate src/memory/memory.py @ 634:ca2cae6b2c6d

core: security attribute added to the parameters - getParams, getParamsUI and getParamsForCategory have a security_limit parameter to filter - parameters with security = 0 can be retrieved/modified from Libervia
author souliane <souliane@mailoo.org>
date Thu, 05 Sep 2013 20:28:44 +0200
parents 5646ecd3e35e
children eff8772fd472
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
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
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
19
goffi@necton2
parents:
diff changeset
20 from __future__ import with_statement
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22 import os.path
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
23 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
24 from xml.dom import minidom
326
0f9925193586 core, plugin mblog: fixed some exceptions
Goffi <goffi@goffi.org>
parents: 318
diff changeset
25 from logging import debug, info, warning, error
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
26 from twisted.internet import defer
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
27 from twisted.words.protocols.jabber import jid
223
86d249b6d9b7 Files reorganisation
Goffi <goffi@goffi.org>
parents: 214
diff changeset
28 from sat.tools.xml_tools import paramsXml2xmlUI
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
29 from sat.core.default_config import default_config
432
31e8c48b5f5d core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents: 428
diff changeset
30 from sat.memory.sqlite import SqliteStorage
31e8c48b5f5d core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents: 428
diff changeset
31 from sat.memory.persistent import PersistentDict
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
32 from sat.core import exceptions
0
goffi@necton2
parents:
diff changeset
33
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
34 SAVEFILE_PARAM_XML = "/param" # xml parameters template
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
35 SAVEFILE_DATABASE = "/sat.db"
0
goffi@necton2
parents:
diff changeset
36
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
37
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
38 class Params(object):
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
39 """This class manage parameters with xml"""
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
40 ### TODO: add desciption in params
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
41
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
42 #TODO: move Watched in a plugin
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
43 #TODO: when priority is changed, a new presence stanza must be emitted
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
44 #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
45 default_xml = u"""
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
46 <params>
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
47 <general>
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
48 </general>
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
49 <individual>
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
50 <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
51 <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
52 <param name="Password" value="" type="password" />
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
53 <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
54 <param name="Server" value="example.org" type="string" />
556
14dcbcdb6222 core: added Port parameter
Goffi <goffi@goffi.org>
parents: 553
diff changeset
55 <param name="Port" value="5222" type="string" />
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
56 <param name="NewAccount" value="%(label_NewAccount)s" type="button" callback_id="registerNewAccount"/>
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
57 <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
58 <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
59 </category>
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
60 <category name="Misc" label="%(category_misc)s">
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
61 <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
62 </category>
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
63 </individual>
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
64 </params>
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
65 """ % {
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
66 'category_connection': _("Connection"),
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
67 'label_NewAccount': _("Register new account"),
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
68 'label_autoconnect': _('Connect on frontend startup'),
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
69 'label_autodisconnect': _('Disconnect on frontend closure'),
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
70 'category_misc': _("Misc")
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
71 }
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
72
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
73 def load_default_params(self):
458
094050fe461e core: fixed Params class name in load_default_params
Goffi <goffi@goffi.org>
parents: 443
diff changeset
74 self.dom = minidom.parseString(Params.default_xml.encode('utf-8'))
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
75
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
76 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
77 """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
78
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
79 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
80 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
81 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
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 to_add = source_set.difference(dest_set)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
90
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
91 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
92 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
93
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 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
95 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
96 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
97
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
98 def load_xml(self, xml_file):
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
99 """Load parameters template from 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
100 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
101 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
102 self._mergeParams(default_dom.documentElement, self.dom.documentElement)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
103
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
104 def loadGenParams(self):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
105 """Load general parameters data from storage
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
106 @return: deferred triggered once params are loaded"""
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
107 return self.storage.loadGenParams(self.params_gen)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
108
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
109 def loadIndParams(self, profile, cache=None):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
110 """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
111 set self.params cache or a temporary cache
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
112 @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
113 @param cache: if not None, will be used to store the value, as a short time cache
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
114 @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
115 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
116 self.params[profile] = {}
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
117 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
118
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
119 def purgeProfile(self, profile):
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
120 """Remove cache data of a profile
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
121 @param profile: %(doc_profile)s"""
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
122 try:
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
123 del self.params[profile]
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
124 except KeyError:
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
125 error(_("Trying to purge cache of a profile not in memory: [%s]") % profile)
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
126
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
127 def save_xml(self, filename):
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
128 """Save parameters template to xml file"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
129 with open(filename, 'wb') as xml_file:
214
e178e8f6d13a fixed some unicode issue
Goffi <goffi@goffi.org>
parents: 197
diff changeset
130 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
131
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
132 def __init__(self, host, storage):
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
133 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
134 self.host = host
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
135 self.storage = storage
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
136 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
137 self.params = {}
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
138 self.params_gen = {}
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
139 host.set_const('savefile_param_xml', SAVEFILE_PARAM_XML)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
140 host.registerGeneralCB("registerNewAccount", host.registerNewAccountCB)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
141
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
142 def createProfile(self, profile):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
143 """Create a new profile
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
144 @param profile: profile of the profile"""
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
145 #FIXME: must be asynchronous and call the callback once the profile actually exists
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
146 if self.storage.hasProfile(profile):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
147 info(_('The profile [%s] already exists') % (profile, ))
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
148 return True
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
149 if not self.host.trigger.point("ProfileCreation", profile):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
150 return False
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
151 self.storage.createProfile(profile)
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
152 return False
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
153
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
154 def asyncCreateProfile(self, profile):
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
155 """Create a new profile
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
156 @param profile: name of the profile
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
157 @param callback: called when the profile actually exists in database and memory
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
158 @param errback: called with a string constant as parameter:
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
159 - CONFLICT: the profile already exists
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
160 - CANCELED: profile creation canceled
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
161 """
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
162 if self.storage.hasProfile(profile):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
163 info(_('The profile name already exists'))
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
164 return defer.fail("CONFLICT")
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
165 if not self.host.trigger.point("ProfileCreation", 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
166 return defer.fail("CANCEL")
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
167 return self.storage.createProfile(profile)
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
168
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
169 def deleteProfile(self, profile):
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
170 """Delete an existing profile
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
171 @param profile: name of the profile"""
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
172 #TODO: async equivalent, like for createProfile
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
173 if not self.storage.hasProfile(profile):
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
174 error(_('Trying to delete an unknown profile'))
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
175 return True
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
176 if self.host.isConnected(profile):
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
177 error(_("Trying to delete a 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
178 raise exceptions.NotConnectedProfileError
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
179 self.storage.deleteProfile(profile)
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
180 return False
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
181
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
182 def getProfileName(self, profile_key):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
183 """return profile according to profile_key
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
184 @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
185 @ALL@ for all profiles
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
186 @DEFAULT@ for default profile
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
187 @return: requested profile name or None if it doesn't exist"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
188 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
189 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
190 if not default:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
191 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
192 try:
5646ecd3e35e core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents: 620
diff changeset
193 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
194 except IndexError:
5646ecd3e35e core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents: 620
diff changeset
195 info(_('No profile exist yet'))
5646ecd3e35e core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents: 620
diff changeset
196 return ""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
197 return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
198 if not self.storage.hasProfile(profile_key):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
199 info(_('Trying to access an unknown profile'))
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
200 return ""
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
201 return profile_key
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
202
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
203 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
204 """return node with given tag
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
205 @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
206 @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
207 @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
208 @return: node if it exist or None
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
209 """
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
210 for node in parent.childNodes:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
211 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
212 #the node already exists
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
213 return node
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
214 #the node is new
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
215 return None
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
216
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
217 def importParams(self, xml):
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
218 """import xml in parameters, do nothing if the param already exist
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
219 @param xml: parameters in xml form"""
34
a544b376b6f0 use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents: 22
diff changeset
220 src_dom = minidom.parseString(xml.encode('utf-8'))
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
221
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
222 def import_node(tgt_parent, src_parent):
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
223 for child in src_parent.childNodes:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
224 if child.nodeName == '#text':
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
225 continue
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
226 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
227 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
228 tgt_parent.appendChild(child)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
229 else:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
230 import_node(node, child)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
231
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
232 import_node(self.dom.documentElement, src_dom.documentElement)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
233
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
234 def __default_ok(self, value, name, category):
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
235 #FIXME: gof: will not work with individual parameters
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
236 self.setParam(name, value, category) # FIXME: better to set param xml value ???
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
237
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
238 def __default_ko(self, failure, name, category):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
239 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
240
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
241 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
242 """Set default value of parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
243 '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
244 @param name: name of the parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
245 @param category: category of the parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
246 @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
247 @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
248 """
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
249 #TODO: send signal param update if value changed
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
250 node = self.__getParamNode(name, category, '@ALL@')
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
251 if not node:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
252 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
253 return
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
254 if node[1].getAttribute('default_cb') == 'yes':
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
255 del node[1].attributes['default_cb']
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
256 d = defer.maybeDeferred(callback)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
257 d.addCallback(self.__default_ok, name, category)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
258 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
259
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
260 def __getAttr(self, node, attr, value):
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
261 """ get attribute value
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
262 @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
263 @param attr: name of the attribute to get (e.g.: 'value' or 'type')
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
264 @param value: user defined value"""
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
265 if attr == 'value':
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
266 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
267 if node.getAttribute('type') == 'bool':
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
268 return value_to_use.lower() not in ('false', '0')
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
269 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
270 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
271
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
272 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
273 """ 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
274 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
275 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
276 return result
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
277
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
278 def getStringParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
279 """ 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
280 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
281
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
282 def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
283 """Helper method to get a specific attribute
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
284 @param name: name of the parameter
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
285 @param category: category of the parameter
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
286 @param attr: name of the attribute (default: "value")
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
287 @param profile: owner of the param (@ALL@ for everyone)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
288
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
289 @return: attribute"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
290 #FIXME: looks really dirty and buggy, need to be reviewed/refactored
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
291 node = self.__getParamNode(name, category)
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
292 if not node:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
293 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
294 raise exceptions.NotFound
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
295
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
296 if node[0] == 'general':
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
297 value = self.__getParam(None, category, name, 'general')
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
298 return self.__getAttr(node[1], attr, value)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
299
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
300 assert node[0] == 'individual'
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
301
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
302 profile = self.getProfileName(profile_key)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
303 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
304 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
305 raise exceptions.ProfileUnknownError
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
306
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
307 if profile not in self.params:
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
308 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
309 raise exceptions.NotConnectedProfileError(profile)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
310
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
311 if attr == "value":
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
312 value = self.__getParam(profile, category, name)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
313 return self.__getAttr(node[1], attr, value)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
314
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
315 def asyncGetStringParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
316 d = self.asyncGetParamA(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
317 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
318 return d
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
319
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
320 def asyncGetParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
321 """Helper method to get a specific attribute
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
322 @param name: name of the parameter
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
323 @param category: category of the parameter
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
324 @param attr: name of the attribute (default: "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
325 @param profile: owner of the param (@ALL@ for everyone)"""
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
326 node = self.__getParamNode(name, category)
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
327 if not node:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
328 error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
329 return None
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
330
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
331 if node[0] == 'general':
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
332 value = self.__getParam(None, category, name, 'general')
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
333 return defer.succeed(self.__getAttr(node[1], attr, value))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
334
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
335 assert node[0] == 'individual'
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
336
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
337 profile = self.getProfileName(profile_key)
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
338 if not profile:
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
339 error(_('Requesting a param for a non-existant 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
340 return defer.fail()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
341
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
342 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
343 return defer.succeed(node[1].getAttribute(attr))
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
344 try:
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
345 value = self.__getParam(profile, category, name)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
346 return defer.succeed(self.__getAttr(node[1], attr, value))
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
347 except exceptions.ProfileNotInCacheError:
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
348 #We have to ask data to the storage manager
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
349 d = self.storage.getIndParam(category, name, profile)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
350 return d.addCallback(lambda value: self.__getAttr(node[1], attr, value))
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
351
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
352 def __getParam(self, profile, category, name, _type='individual', cache=None):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
353 """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
354 @param profile: the profile name (not profile key, i.e. name and not something like @DEFAULT@)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
355 @param category: param category
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
356 @param name: param name
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
357 @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
358 @param cache: temporary cache, to use when profile is not logged
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
359 @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
360 """
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
361 if _type == 'general':
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
362 if (category, name) in self.params_gen:
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
363 return self.params_gen[(category, name)]
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
364 return None # This general param has the default value
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
365 assert (_type == 'individual')
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
366 if profile in self.params:
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
367 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
368 # ignoring the temporary cache
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
369 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
370 raise exceptions.ProfileNotInCacheError
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
371 if (category, name) not in cache:
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
372 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
373 return cache[(category, name)]
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
374
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
375 def __constructProfileXml(self, security_limit, profile):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
376 """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
377 /!\ as noticed in doc, don't forget to unlink the minidom.Document
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
378 @security_limit: -1 to return all the params. Otherwise sole the
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
379 params which have a security level defined *and* lower or equal to
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
380 the specified value are returned.
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
381 @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
382 @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
383 """
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
384
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
385 def constructProfile(ignore, profile_cache):
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
386
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
387 def filterParam(node):
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
388 """Filter with security level.
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
389 @return: True is this param must be filtered"""
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
390 if security_limit < 0:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
391 return False
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
392 if not node.hasAttribute('security'):
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
393 debug("filtered param: %s (no security set)"
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
394 % node.getAttribute("name"))
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
395 return True
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
396 if int(node.getAttribute('security')) > security_limit:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
397 debug("filtered param: %s (security level > %i)"
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
398 % (node.getAttribute("name"), security_limit))
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
399 return True
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
400 return False
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
401
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
402 # 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
403 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
404 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
405
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
406 for type_node in self.dom.documentElement.childNodes:
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
407 if type_node.nodeName != 'general' and type_node.nodeName != 'individual':
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
408 continue
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
409 # we use all params, general and individual
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
410 for cat_node in type_node.childNodes:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
411 if cat_node.nodeName != 'category':
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
412 continue
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
413 category = cat_node.getAttribute('name')
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
414 dest_params = {} # result (merged) params for category
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
415 if category not in cache:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
416 # we make a copy for the new xml
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
417 cache[category] = dest_cat = cat_node.cloneNode(True)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
418 for node in dest_cat.childNodes:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
419 if node.nodeName != "param":
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
420 continue
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
421 if filterParam(node):
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
422 dest_cat.removeChild(node)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
423 continue
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
424 dest_params[node.getAttribute('name')] = node
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
425 new_node = True
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
426 else:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
427 # 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
428 dest_cat = cache[category]
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
429 new_node = False
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
430 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
431
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
432 for param_node in params:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
433 # 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
434 # to the previously parsed general ones)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
435 name = param_node.getAttribute('name')
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
436 if filterParam(param_node):
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
437 continue
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
438 if name not in dest_params:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
439 # this is reached when a previous category exists
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
440 dest_params[name] = param_node.cloneNode(True)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
441 dest_cat.appendChild(dest_params[name])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
442
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
443 profile_value = self.__getParam(profile, category,
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
444 name, type_node.nodeName,
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
445 cache=profile_cache)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
446 if profile_value is not None:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
447 # there is a value for this profile, we must change the default
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
448 dest_params[name].setAttribute('value', profile_value)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
449 if new_node:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
450 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
451
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
452 to_remove = []
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
453 for cat_node in prof_xml.documentElement.childNodes:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
454 # we remove empty categories
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
455 if cat_node.getElementsByTagName("param").length == 0:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
456 to_remove.append(cat_node)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
457 for node in to_remove:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
458 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
459 return prof_xml
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
460
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
461 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
462 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
463 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
464 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
465 #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
466 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
467 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
468
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
469 return d.addCallback(constructProfile, profile_cache)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
470
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
471 def getParamsUI(self, security_limit, profile_key):
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
472 """Return a SàT XMLUI for parameters, with given profile"""
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
473 profile = self.getProfileName(profile_key)
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
474 if not profile:
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
475 error(_("Asking params for inexistant profile"))
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
476 return ""
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
477 d = self.getParams(security_limit, profile)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
478 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
479
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
480 def getParams(self, security_limit, profile_key):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
481 """Construct xml for asked profile
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
482 Take params xml as skeleton"""
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
483 profile = self.getProfileName(profile_key)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
484 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
485 error(_("Asking params for inexistant profile"))
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
486 return ""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
487
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
488 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
489 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
490 prof_xml.unlink()
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
491 return '\n'.join([line for line in return_xml.split('\n')])
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
492
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
493 return self.__constructProfileXml(security_limit, profile).addCallback(returnXML)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
494
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
495 def getParamsForCategory(self, category, security_limit, profile_key):
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
496 """Return node's xml for selected category"""
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
497 #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
498 profile = self.getProfileName(profile_key)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
499 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
500 error(_("Asking params for inexistant profile"))
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
501 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
502
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
503 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
504 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
505 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
506 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
507 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
508 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
509
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
510 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
511 return "<category />"
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
512
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
513 d = self.__constructProfileXml(security_limit, 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
514 return d.addCallback(returnCategoryXml)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
515
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
516 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
517 """Return a node from the param_xml
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
518 @param name: name of the node
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
519 @param category: category of the node
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
520 @_type: keyword for search:
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
521 @ALL@ search everywhere
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
522 @GENERAL@ only search in general type
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
523 @INDIVIDUAL@ only search in individual type
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
524 @return: a tuple with the node type and the the node, or None if not found"""
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
525
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
526 for type_node in self.dom.documentElement.childNodes:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
527 if (((_type == "@ALL@" or _type == "@GENERAL@") and type_node.nodeName == 'general')
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
528 or ((_type == "@ALL@" or _type == "@INDIVIDUAL@") and type_node.nodeName == 'individual')):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
529 for node in type_node.getElementsByTagName('category'):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
530 if node.getAttribute("name") == category:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
531 params = node.getElementsByTagName("param")
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
532 for param in params:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
533 if param.getAttribute("name") == name:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
534 return (type_node.nodeName, param)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
535 return None
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
536
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
537 def getParamsCategories(self):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
538 """return the categories availables"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
539 categories = []
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
540 for cat in self.dom.getElementsByTagName("category"):
396
cecd22241d56 memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents: 395
diff changeset
541 name = cat.getAttribute("name")
cecd22241d56 memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents: 395
diff changeset
542 if name not in categories:
cecd22241d56 memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents: 395
diff changeset
543 categories.append(cat.getAttribute("name"))
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
544 return categories
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
545
392
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
546 def setParam(self, name, value, category, profile_key='@NONE@'):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
547 """Set a parameter, return None if the parameter is not in param xml"""
417
f1bf8b6143b7 core: removed former save_data method
Goffi <goffi@goffi.org>
parents: 416
diff changeset
548 #TODO: use different behaviour depending of the data type (e.g. password encrypted)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
549 if profile_key != "@NONE@":
392
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
550 profile = self.getProfileName(profile_key)
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
551 if not profile:
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
552 error(_('Trying to set parameter for an unknown profile'))
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
553 return # TODO: throw an error
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
554
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
555 node = self.__getParamNode(name, category, '@ALL@')
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
556 if not node:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
557 error(_('Requesting an unknown parameter (%(category)s/%(name)s)') % {'category': category, 'name': name})
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
558 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
559
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
560 if node[0] == 'general':
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
561 self.params_gen[(category, name)] = value
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
562 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
563 for profile in self.storage.getProfilesList():
392
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
564 if self.host.isConnected(profile):
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
565 self.host.bridge.paramUpdate(name, value, category, profile)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
566 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
567
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
568 assert (node[0] == 'individual')
392
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
569 assert (profile_key != "@NONE@")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
570
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
571 _type = node[1].getAttribute("type")
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
572 if _type == "button":
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
573 print "clique", node.toxml()
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
574 else:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
575 if self.host.isConnected(profile): # key can not exists if profile is not connected
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
576 self.params[profile][(category, name)] = value
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
577 self.host.bridge.paramUpdate(name, value, category, profile)
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
578 self.storage.setIndParam(category, name, value, profile)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
579
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
580
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
581 class Memory(object):
0
goffi@necton2
parents:
diff changeset
582 """This class manage all persistent informations"""
goffi@necton2
parents:
diff changeset
583
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
584 def __init__(self, host):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
585 info(_("Memory manager init"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
586 self.initialized = defer.Deferred()
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
587 self.host = host
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
588 self.entitiesCache = {} # XXX: keep presence/last resource/other data in cache
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
589 # /!\ an entity is not necessarily in roster
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
590 self.subscriptions = {}
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
591 self.server_features = {} # used to store discovery's informations
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
592 self.server_identities = {}
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
593 self.config = self.parseMainConf()
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
594 host.set_const('savefile_database', SAVEFILE_DATABASE)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
595 database_file = os.path.expanduser(self.getConfig('', 'local_dir') +
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
596 self.host.get_const('savefile_database'))
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
597 self.storage = SqliteStorage(database_file)
432
31e8c48b5f5d core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents: 428
diff changeset
598 PersistentDict.storage = self.storage
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
599 self.params = Params(host, self.storage)
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
600 self.loadFiles()
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
601 d = self.storage.initialized.addCallback(lambda ignore: self.load())
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
602 self.memory_data = PersistentDict("memory")
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
603 d.addCallback(lambda ignore: self.memory_data.load())
428
a4a9efadabfc core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents: 425
diff changeset
604 d.chainDeferred(self.initialized)
0
goffi@necton2
parents:
diff changeset
605
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
606 def parseMainConf(self):
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
607 """look for main .ini configuration file, and parse it"""
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
608 _config = SafeConfigParser(defaults=default_config)
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
609 try:
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 365
diff changeset
610 _config.read(map(os.path.expanduser, ['/etc/sat.conf', '~/sat.conf', '~/.sat.conf', 'sat.conf', '.sat.conf']))
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
611 except:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
612 error(_("Can't read main config !"))
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
613
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
614 return _config
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
615
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
616 def getConfig(self, section, name):
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
617 """Get the main configuration option
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
618 @param section: section of the config file (None or '' for DEFAULT)
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
619 @param name: name of the option
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
620 """
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
621 if not section:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
622 section = 'DEFAULT'
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
623 try:
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
624 _value = self.config.get(section, name)
483
655695f85e5b core: fixed bad try/except block in memory
Goffi <goffi@goffi.org>
parents: 480
diff changeset
625 except (NoOptionError, NoSectionError):
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
626 _value = ''
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
627
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
628 return os.path.expanduser(_value) if name.endswith('_path') or name.endswith('_dir') else _value
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
629
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
630 def loadFiles(self):
0
goffi@necton2
parents:
diff changeset
631 """Load parameters and all memory things from file/db"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
632 param_file_xml = os.path.expanduser(self.getConfig('', 'local_dir') +
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
633 self.host.get_const('savefile_param_xml'))
0
goffi@necton2
parents:
diff changeset
634
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
635 #parameters template
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
636 if os.path.exists(param_file_xml):
0
goffi@necton2
parents:
diff changeset
637 try:
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
638 self.params.load_xml(param_file_xml)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
639 debug(_("params template loaded"))
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
640 except Exception as e:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
641 error(_("Can't load params template: %s") % (e, ))
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
642 self.params.load_default_params()
0
goffi@necton2
parents:
diff changeset
643 else:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
644 info(_("No params template, using default template"))
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
645 self.params.load_default_params()
0
goffi@necton2
parents:
diff changeset
646
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
647 def load(self):
428
a4a9efadabfc core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents: 425
diff changeset
648 """Load parameters and all memory things from db"""
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
649 #parameters data
428
a4a9efadabfc core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents: 425
diff changeset
650 return self.params.loadGenParams()
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
651
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
652 def loadIndividualParams(self, profile):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
653 """Load individual parameters for a profile
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
654 @param profile: %(doc_profile)s"""
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
655 return self.params.loadIndParams(profile)
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
656
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
657 def startProfileSession(self, profile):
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
658 """"Iniatialise session for a profile
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
659 @param profile: %(doc_profile)s"""
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
660 info(_("[%s] Profile session started" % profile))
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
661 self.entitiesCache[profile] = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
662
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
663 def purgeProfileSession(self, profile):
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
664 """Delete cache of data of profile
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
665 @param profile: %(doc_profile)s"""
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
666 info(_("[%s] Profile session purge" % profile))
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
667 self.params.purgeProfile(profile)
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
668 try:
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
669 del self.entitiesCache[profile]
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
670 except KeyError:
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
671 error(_("Trying to purge roster status cache for a profile not in memory: [%s]") % profile)
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
672
0
goffi@necton2
parents:
diff changeset
673 def save(self):
goffi@necton2
parents:
diff changeset
674 """Save parameters and all memory things to file/db"""
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
675 #TODO: need to encrypt files (at least passwords !) and set permissions
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
676 param_file_xml = os.path.expanduser(self.getConfig('', 'local_dir') +
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
677 self.host.get_const('savefile_param_xml'))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
678
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
679 self.params.save_xml(param_file_xml)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
680 debug(_("params saved"))
0
goffi@necton2
parents:
diff changeset
681
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
682 def getProfilesList(self):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
683 return self.storage.getProfilesList()
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
684
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
685 def getProfileName(self, profile_key):
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
686 """Return name of profile from keyword
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
687 @param profile_key: can be the profile name or a keywork (like @DEFAULT@)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
688 @return: profile name or None if it doesn't exist"""
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
689 return self.params.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
690
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
691 def createProfile(self, name):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
692 """Create a new profile
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
693 @param name: Profile name
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
694 """
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
695 return self.params.createProfile(name)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
696
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
697 def asyncCreateProfile(self, name):
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
698 """Create a new profile
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
699 @param name: Profile name
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
700 """
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
701 return self.params.asyncCreateProfile(name)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
702
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
703 def deleteProfile(self, name):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
704 """Delete an existing profile
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
705 @param name: Name of the profile"""
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
706 return self.params.deleteProfile(name)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
707
512
862c0d6ab974 core, bridge, quick_frontend: MUC private messages history management:
Goffi <goffi@goffi.org>
parents: 507
diff changeset
708 def addToHistory(self, from_jid, to_jid, message, _type='chat', timestamp=None, profile="@NONE@"):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
709 assert profile != "@NONE@"
512
862c0d6ab974 core, bridge, quick_frontend: MUC private messages history management:
Goffi <goffi@goffi.org>
parents: 507
diff changeset
710 return self.storage.addToHistory(from_jid, to_jid, message, _type, timestamp, profile)
0
goffi@necton2
parents:
diff changeset
711
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
712 def getHistory(self, from_jid, to_jid, limit=0, between=True, profile="@NONE@"):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
713 assert profile != "@NONE@"
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
714 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
0
goffi@necton2
parents:
diff changeset
715
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
716 def addServerFeature(self, feature, profile):
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
717 """Add a feature discovered from server
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
718 @param feature: string of the feature
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
719 @param profile: which profile is using this server ?"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
720 if profile not in self.server_features:
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
721 self.server_features[profile] = []
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
722 self.server_features[profile].append(feature)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
723
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
724 def addServerIdentity(self, category, _type, entity, profile):
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
725 """Add an identity discovered from server
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
726 @param feature: string of the feature
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
727 @param profile: which profile is using this server ?"""
566
9faccd827657 core: sqlite storage constraint fix
Goffi <goffi@goffi.org>
parents: 557
diff changeset
728 if not profile in self.server_identities:
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
729 self.server_identities[profile] = {}
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
730 if (category, _type) not in self.server_identities[profile]:
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
731 self.server_identities[profile][(category, _type)] = set()
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
732 self.server_identities[profile][(category, _type)].add(entity)
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
733
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
734 def getServerServiceEntities(self, category, _type, profile):
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
735 """Return all available entities for a service"""
566
9faccd827657 core: sqlite storage constraint fix
Goffi <goffi@goffi.org>
parents: 557
diff changeset
736 if profile in self.server_identities:
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
737 return self.server_identities[profile].get((category, _type), set())
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
738 else:
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
739 return None
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
740
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
741 def getServerServiceEntity(self, category, _type, profile):
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
742 """Helper method to get first available entity for a service"""
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
743 entities = self.getServerServiceEntities(category, _type, profile)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
744 if entities is None:
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
745 warning(_("Entities (%(category)s/%(type)s) not available, maybe they haven't been asked to server yet ?") % {"category": category,
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
746 "type": _type})
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
747 return None
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
748 else:
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
749 return list(entities)[0] if entities else None
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
750
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 327
diff changeset
751 def hasServerFeature(self, feature, profile_key):
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
752 """Tell if the server of the profile has the required feature"""
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
753 profile = self.getProfileName(profile_key)
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
754 if not profile:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
755 error(_('Trying find server feature for a non-existant profile'))
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
756 return
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
757 assert profile in self.server_features
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
758 return feature in self.server_features[profile]
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
759
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
760 def getLastResource(self, contact, profile_key):
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
761 """Return the last resource used by a contact
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
762 @param contact: contact jid (unicode)
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
763 @param profile_key: %(doc_profile_key)s"""
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
764 profile = self.getProfileName(profile_key)
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
765 if not profile or not self.host.isConnected(profile):
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
766 error(_('Asking contacts for a non-existant or not connected profile'))
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
767 return ""
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
768 entity = jid.JID(contact).userhost()
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
769 if not entity in self.entitiesCache[profile]:
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
770 info(_("Entity not in cache"))
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
771 return ""
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
772 try:
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
773 return self.entitiesCache[profile][entity]["last_resource"]
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
774 except KeyError:
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
775 return ""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
776
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 327
diff changeset
777 def getPresenceStatus(self, profile_key):
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
778 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
779 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
780 error(_('Asking contacts for a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
781 return {}
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
782 entities_presence = {}
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
783 for entity in self.entitiesCache[profile]:
553
2b3e3349f6a4 core: fixed presence cache error
Goffi <goffi@goffi.org>
parents: 538
diff changeset
784 if "presence" in self.entitiesCache[profile][entity]:
2b3e3349f6a4 core: fixed presence cache error
Goffi <goffi@goffi.org>
parents: 538
diff changeset
785 entities_presence[entity] = self.entitiesCache[profile][entity]["presence"]
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
786
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
787 debug("Memory getPresenceStatus (%s)", entities_presence)
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
788 return entities_presence
0
goffi@necton2
parents:
diff changeset
789
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
790 def setPresenceStatus(self, entity_jid, show, priority, statuses, profile_key):
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
791 """Change the presence status of an entity"""
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
792 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
793 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
794 error(_('Trying to add presence status to a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
795 return
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
796 entity_data = self.entitiesCache[profile].setdefault(entity_jid.userhost(), {})
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
797 resource = jid.parse(entity_jid.full())[2] or ''
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
798 if resource:
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
799 entity_data["last_resource"] = resource
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
800 if not "last_resource" in entity_data:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
801 entity_data["last_resource"] = ''
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
802
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
803 entity_data.setdefault("presence", {})[resource] = (show, priority, statuses)
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
804
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
805 def updateEntityData(self, entity_jid, key, value, profile_key):
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
806 """Set a misc data for an entity
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
807 @param entity_jid: JID of the entity
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
808 @param key: key to set (eg: "type")
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
809 @param value: value for this key (eg: "chatroom")
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
810 @param profile_key: %(doc_profile_key)s
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
811 """
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
812 profile = self.getProfileName(profile_key)
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
813 if not profile:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
814 raise exceptions.UnknownProfileError(_('Trying to get entity data for a non-existant profile'))
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
815 if not profile in self.entitiesCache:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
816 raise exceptions.ProfileNotInCacheError
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
817 entity_data = self.entitiesCache[profile].setdefault(entity_jid.userhost(), {})
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
818 entity_data[key] = value
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
819 if isinstance(value, basestring):
504
65ecbb473cbb core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents: 494
diff changeset
820 self.host.bridge.entityDataUpdated(entity_jid.userhost(), key, value, profile)
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
821
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
822 def getEntityData(self, entity_jid, keys_list, profile_key):
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
823 """Get a list of cached values for entity
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
824 @param entity_jid: JID of the entity
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
825 @param keys_list: list of keys to get, empty list for everything
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
826 @param profile_key: %(doc_profile_key)s
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
827 @return: dict withs values for each key in keys_list.
504
65ecbb473cbb core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents: 494
diff changeset
828 if there is no value of a given key, resulting dict will
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
829 have nothing with that key nether
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
830 @raise: exceptions.UnknownEntityError if entity is not in cache
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
831 exceptions.ProfileNotInCacheError if profile is not in cache
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
832 """
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
833 profile = self.getProfileName(profile_key)
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
834 if not profile:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
835 raise exceptions.UnknownProfileError(_('Trying to get entity data for a non-existant profile'))
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
836 if not profile in self.entitiesCache:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
837 raise exceptions.ProfileNotInCacheError
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
838 if not entity_jid.userhost() in self.entitiesCache[profile]:
620
64db6758d223 core: more explicit UnknownEntityError
Goffi <goffi@goffi.org>
parents: 611
diff changeset
839 raise exceptions.UnknownEntityError(entity_jid.userhost())
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
840 entity_data = self.entitiesCache[profile][entity_jid.userhost()]
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
841 if not keys_list:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
842 return entity_data
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
843 ret = {}
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
844 for key in keys_list:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
845 if key in entity_data:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
846 ret[key] = entity_data[key]
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
847 return ret
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
848
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
849 def delEntityCache(self, entity_jid, profile_key):
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
850 """Remove cached data for entity
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
851 @param entity_jid: JID of the entity
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
852 """
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
853 profile = self.getProfileName(profile_key)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
854 try:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
855 del self.entitiesCache[profile][entity_jid.userhost()]
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
856 except KeyError:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
857 pass
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
858
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
859 def addWaitingSub(self, _type, entity_jid, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
860 """Called when a subcription request is received"""
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
861 profile = self.getProfileName(profile_key)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
862 assert profile
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
863 if profile not in self.subscriptions:
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
864 self.subscriptions[profile] = {}
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
865 self.subscriptions[profile][entity_jid] = _type
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
866
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
867 def delWaitingSub(self, entity_jid, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
868 """Called when a subcription request is finished"""
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
869 profile = self.getProfileName(profile_key)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
870 assert profile
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
871 if profile in self.subscriptions and entity_jid in self.subscriptions[profile]:
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
872 del self.subscriptions[profile][entity_jid]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
873
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 327
diff changeset
874 def getWaitingSub(self, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
875 """Called to get a list of currently waiting subscription requests"""
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
876 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
877 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
878 error(_('Asking waiting subscriptions for a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
879 return {}
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
880 if profile not in self.subscriptions:
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
881 return {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
882
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
883 return self.subscriptions[profile]
0
goffi@necton2
parents:
diff changeset
884
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
885 def getStringParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
886 return self.params.getStringParamA(name, category, attr, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
887
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 327
diff changeset
888 def getParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
889 return self.params.getParamA(name, category, attr, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
890
574
89f9a50ce7bf core, plugin imap, plugin smtp: fixed SMTP/IMAP integration. /!\ Profile need to be connected for IMAP server to work (will change in the future)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
891 def asyncGetParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
89f9a50ce7bf core, plugin imap, plugin smtp: fixed SMTP/IMAP integration. /!\ Profile need to be connected for IMAP server to work (will change in the future)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
892 return self.params.asyncGetParamA(name, category, attr, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
893
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
894 def asyncGetStringParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
895 return self.params.asyncGetStringParamA(name, category, attr, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
896
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
897 def getParamsUI(self, security_limit, profile_key):
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
898 return self.params.getParamsUI(security_limit, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
899
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
900 def getParams(self, security_limit, profile_key):
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
901 return self.params.getParams(security_limit, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
902
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
903 def getParamsForCategory(self, category, security_limit, profile_key):
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
904 return self.params.getParamsForCategory(category, security_limit, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
905
0
goffi@necton2
parents:
diff changeset
906 def getParamsCategories(self):
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
907 return self.params.getParamsCategories()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
908
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 327
diff changeset
909 def setParam(self, name, value, category, profile_key):
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
910 return self.params.setParam(name, value, category, profile_key)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
911
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
912 def importParams(self, xml):
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
913 return self.params.importParams(xml)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
914
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
915 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
916 return self.params.setDefault(name, category, callback, errback)