Mercurial > libervia-backend
annotate src/memory/memory.py @ 432:31e8c48b5f5d
core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
- private values are now stored in storage (currently sqlite database) and splitted in normal/binary storage. Normal storage is for string key/values, binary storage is for string key and any python data for value
- PersistentDict and PersistentBinaryDict are sugar classes to manage the data in storage thought a python dictionary like class.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 20 Nov 2011 15:34:37 +0100 |
parents | src/tools/memory.py@a4a9efadabfc |
children | 7099ea9c1b12 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
228 | 6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from __future__ import with_statement | |
23 | |
24 import os.path | |
25 import time | |
106 | 26 import cPickle as pickle |
364 | 27 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
28 from xml.dom import minidom |
326
0f9925193586
core, plugin mblog: fixed some exceptions
Goffi <goffi@goffi.org>
parents:
318
diff
changeset
|
29 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
|
30 from twisted.internet import defer |
47 | 31 from twisted.words.protocols.jabber import jid |
223 | 32 from sat.tools.xml_tools import paramsXml2xmlUI |
364 | 33 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
|
34 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
|
35 from sat.memory.persistent import PersistentDict |
0 | 36 |
61 | 37 SAVEFILE_PARAM_XML="/param" #xml parameters template |
47 | 38 SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins) |
412 | 39 SAVEFILE_DATABASE="/sat.db" |
0 | 40 |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
41 class ProfileNotInCacheError(Exception): |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
42 pass |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
43 |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
44 class ConnectedProfileError(Exception): |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
45 pass |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
46 |
432
31e8c48b5f5d
core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents:
428
diff
changeset
|
47 class Params(): |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
48 """This class manage parameters with xml""" |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
49 ### TODO: add desciption in params |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
50 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
51 #TODO: move Watched in a plugin |
34
a544b376b6f0
use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
52 default_xml = u""" |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
53 <params> |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
54 <general> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
55 </general> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
56 <individual> |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
57 <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
|
58 <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
|
59 <param name="Password" value="" type="password" /> |
f5181f6dd98f
Test value replaced by example values for memory params
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
60 <param name="Server" value="example.org" type="string" /> |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
61 <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
|
62 <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
|
63 <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
|
64 </category> |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
65 <category name="Misc" label="%(category_misc)s"> |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
66 <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
|
67 </category> |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
68 </individual> |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
69 </params> |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
70 """ % {'category_connection': _("Connection"), |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
71 'label_NewAccount': _("Register new account"), |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
72 'label_autoconnect': _('Connect on frontend startup'), |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
73 'label_autodisconnect': _('Disconnect on frontend closure'), |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
74 'category_misc': _("Misc") |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
75 } |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
76 |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
77 def load_default_params(self): |
34
a544b376b6f0
use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
78 self.dom = minidom.parseString(Param.default_xml.encode('utf-8')) |
38 | 79 |
61 | 80 def load_xml(self, file): |
81 """Load parameters template from file""" | |
38 | 82 self.dom = minidom.parse(file) |
83 | |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
84 def loadGenParams(self): |
412 | 85 """Load general parameters data from storage |
86 @return: deferred triggered once params are loaded""" | |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
87 return self.storage.loadGenParams(self.params_gen) |
61 | 88 |
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
|
89 def loadIndParams(self, profile, cache=None): |
412 | 90 """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
|
91 set self.params cache or a temporary cache |
412 | 92 @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
|
93 @param cache: if not None, will be used to store the value, as a short time cache |
412 | 94 @return: deferred triggered once params are loaded""" |
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
|
95 if cache == 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
|
96 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
|
97 return self.storage.loadIndParams(self.params[profile] if cache==None else cache, profile) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
98 |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
99 def purgeProfile(self, profile): |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
100 """Remove cache data of a profile |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
101 @param profile: %(doc_profile)s""" |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
102 try: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
103 del self.params[profile] |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
104 except KeyError: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
105 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
|
106 |
61 | 107 def save_xml(self, file): |
108 """Save parameters template to xml file""" | |
38 | 109 with open(file, 'wb') as xml_file: |
214 | 110 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
|
111 |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
112 def __init__(self, host, storage): |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
113 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
|
114 self.host = host |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
115 self.storage = storage |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
116 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
|
117 self.params = {} |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
118 self.params_gen = {} |
61 | 119 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
|
120 host.registerGeneralCB("registerNewAccount", host.registerNewAccountCB) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
121 |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
122 def createProfile(self, profile): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
123 """Create a new profile |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
124 @param profile: profile of the profile""" |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
125 #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
|
126 if self.storage.hasProfile(profile): |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
127 info (_('The profile profile already exists')) |
412 | 128 return True |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
129 if not self.host.trigger.point("ProfileCreation", profile): |
412 | 130 return False |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
131 self.storage.createProfile(profile) |
412 | 132 return False |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
133 |
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
|
134 def asyncCreateProfile(self, profile): |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
135 """Create a new profile |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
136 @param profile: name of the profile |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
137 @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
|
138 @param errback: called with a string constant as parameter: |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
139 - CONFLICT: the profile already exists |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
140 - 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
|
141 """ |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
142 if self.storage.hasProfile(profile): |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
143 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
|
144 return defer.fail("CONFLICT") |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
145 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
|
146 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
|
147 return self.storage.createProfile(profile) |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
148 |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
149 |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
150 def deleteProfile(self, profile): |
68 | 151 """Delete an existing profile |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
152 @param profile: name of the profile""" |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
153 #TODO: async equivalent, like for createProfile |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
154 if not self.storage.hasProfile(profile): |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
155 error(_('Trying to delete an unknown profile')) |
412 | 156 return True |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
157 if self.host.isConnected(profile): |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
158 error(_("Trying to delete a connected profile")) |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
159 raise ConnectedProfileError |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
160 self.storage.deleteProfile(profile) |
412 | 161 return False |
68 | 162 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
163 def getProfileName(self, profile_key): |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
164 """return profile according to profile_key |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
165 @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
|
166 @ALL@ for all profiles |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
167 @DEFAULT@ for default profile |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
168 @return: requested profile name or None if it doesn't exist""" |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
169 if profile_key=='@DEFAULT@': |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
170 if not self.params: |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
171 return "" |
68 | 172 default = self.host.memory.getPrivate('Profile_default') |
173 if not default or not default in self.params: | |
69 | 174 info(_('No default profile, returning first one')) #TODO: manage real default 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
|
175 default = self.storage.getProfilesList()[0] |
68 | 176 self.host.memory.setPrivate('Profile_default', default) |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
177 return default #FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists |
412 | 178 if not self.storage.hasProfile(profile_key): |
69 | 179 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
|
180 return "" |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
181 return profile_key |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
182 |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
183 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
|
184 """return node with given tag |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
185 @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
|
186 @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
|
187 @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
|
188 @return: node if it exist or None |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
189 """ |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
190 for node in parent.childNodes: |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
191 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
|
192 #the node already exists |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
193 return node |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
194 #the node is new |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
195 return None |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
196 |
38 | 197 def importParams(self, xml): |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
198 """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
|
199 @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
|
200 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
|
201 |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
202 def import_node(tgt_parent, src_parent): |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
203 for child in src_parent.childNodes: |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
204 if child.nodeName == '#text': |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
205 continue |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
206 node = self.__get_unique_node(tgt_parent, child.nodeName, child.getAttribute("name")) |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
207 if not node: #The node is new |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
208 tgt_parent.appendChild(child) |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
209 else: |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
210 import_node(node, child) |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
211 |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
212 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
|
213 |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
214 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
|
215 #FIXME: gof: will not work with individual parameters |
61 | 216 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
|
217 |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
218 def __default_ko(self, failure, name, category): |
69 | 219 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
|
220 |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
221 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
|
222 """Set default value of parameter |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
223 '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
|
224 @param name: name of the parameter |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
225 @param category: category of the parameter |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
226 @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
|
227 @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
|
228 """ |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
229 #TODO: send signal param update if value changed |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
230 node = self.__getParamNode(name, category, '@ALL@') |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
231 if not node: |
69 | 232 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
|
233 return |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
234 if node[1].getAttribute('default_cb') == 'yes': |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
235 del node[1].attributes['default_cb'] |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
236 d = defer.maybeDeferred(callback) |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
237 d.addCallback(self.__default_ok, name, category) |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
238 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
|
239 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
240 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
|
241 """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
|
242 @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
|
243 @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
|
244 @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
|
245 @param profile: owner of the param (@ALL@ for everyone) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
246 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
247 @return: attribute""" |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
248 node = self.__getParamNode(name, category) |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
249 if not node: |
69 | 250 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
|
251 return "" |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
252 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
253 if node[0] == 'general': |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
254 value = self.__getParam(None, category, name, 'general') |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
255 return value if value!=None else node[1].getAttribute(attr) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
256 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
257 assert(node[0] == 'individual') |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
258 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
259 profile = self.getProfileName(profile_key) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
260 if not profile: |
69 | 261 error(_('Requesting a param for an non-existant profile')) |
276
a00e87d48213
bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
262 return "" |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
263 |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
264 if profile not in self.params: |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
265 error(_('Requesting synchronous param for not connected profile')) |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
266 return "" |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
267 |
64 | 268 if attr == "value": |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
269 value = self.__getParam(profile, category, name) |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
270 return value if value!=None else node[1].getAttribute(attr) |
64 | 271 else: |
272 return node[1].getAttribute(attr) | |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
273 |
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
|
274 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
|
275 """Helper method to get a specific attribute |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
276 @param name: name of the parameter |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
277 @param category: category of the parameter |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
278 @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
|
279 @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
|
280 node = self.__getParamNode(name, category) |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
281 if not node: |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
282 error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name':name, 'category':category}) |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
283 return None |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
284 |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
285 if node[0] == 'general': |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
286 value = self.__getParam(None, category, name, 'general') |
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
|
287 return defer.succeed(value if value!=None else node[1].getAttribute(attr)) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
288 |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
289 assert(node[0] == 'individual') |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
290 |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
291 profile = self.getProfileName(profile_key) |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
292 if not profile: |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
293 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
|
294 return defer.fail() |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
295 |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
296 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
|
297 return defer.succeed(node[1].getAttribute(attr)) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
298 default = node[1].getAttribute(attr) |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
299 try: |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
300 value = self.__getParam(profile, category, name) |
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
|
301 return defer.succeed(value if value!=None else default) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
302 except ProfileNotInCacheError: |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
303 #We have to ask data to the storage manager |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
304 d = self.storage.getIndParam(category, name, 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
|
305 return d.addCallback(lambda value: value if value!=None else default) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
306 |
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
|
307 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
|
308 """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
|
309 @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
|
310 @param category: param category |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
311 @param name: param name |
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
|
312 @param type: "general" or "individual" |
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
|
313 @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
|
314 @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
|
315 """ |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
316 if type == 'general': |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
317 if self.params_gen.has_key((category, name)): |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
318 return self.params_gen[(category, name)] |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
319 return None #This general param has the default value |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
320 assert (type == '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
|
321 if self.params.has_key(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
|
322 cache = self.params[profile] # if profile is in main cache, we use it, |
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
|
323 # ignoring the temporary 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
|
324 elif cache == None: #else we use the temporary cache if it exists, or raise an exception |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
325 raise ProfileNotInCacheError |
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
|
326 if not cache.has_key((category, name)): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
327 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
|
328 return cache[(category, name)] |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
329 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
330 def __constructProfileXml(self, profile): |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
331 """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
|
332 /!\ as noticed in doc, don't forget to unlink the minidom.Document |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
333 @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
|
334 @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
|
335 """ |
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
|
336 def constructProfile(ignore,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
|
337 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
|
338 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
|
339 |
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 for type_node in self.dom.documentElement.childNodes: |
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
|
341 if type_node.nodeName == 'general' or type_node.nodeName == 'individual': #we use all params, general and individual |
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
|
342 for cat_node in type_node.childNodes: |
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 if cat_node.nodeName == '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
|
344 category = cat_node.getAttribute('name') |
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
|
345 if not cache.has_key(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
|
346 cache[category] = dest_cat = cat_node.cloneNode(True) #we make a copy for the new 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
|
347 new_node = True |
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
|
348 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
|
349 dest_cat = cache[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
|
350 new_node = False #It's not a new node, we will merge information |
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
|
351 params = cat_node.getElementsByTagName("param") |
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
|
352 dest_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
|
353 for node in dest_cat.childNodes: |
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
|
354 if node.nodeName != "param": |
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
|
355 continue |
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
|
356 dest_params[node.getAttribute('name')] = node |
395
79fe50fc8edc
memory: multiples params of the same category are now merged
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
357 |
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 for param_node in 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
|
359 name = param_node.getAttribute('name') |
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
|
360 |
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
|
361 if name not in dest_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
|
362 dest_params[name] = param_node.cloneNode(True) |
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
|
363 dest_cat.appendChild(dest_params[name]) |
395
79fe50fc8edc
memory: multiples params of the same category are now merged
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
364 |
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
|
365 profile_value = self.__getParam(profile, category, name, type_node.nodeName, cache=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
|
366 if profile_value!=None: #there is a value for this profile, we must change the default |
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
|
367 dest_params[name].setAttribute('value', profile_value) |
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
|
368 if new_node: |
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
|
369 prof_xml.documentElement.appendChild(dest_cat) |
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
|
370 return 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
|
371 |
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
|
372 |
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 if self.params.has_key(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
|
374 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
|
375 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
|
376 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
|
377 #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
|
378 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
|
379 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
|
380 |
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
|
381 return d.addCallback(constructProfile, profile_cache) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
382 |
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
|
383 def getParamsUI(self, profile_key): |
105 | 384 """Return a SàT XMLUI for parameters, with given profile""" |
385 profile = self.getProfileName(profile_key) | |
386 if not profile: | |
387 error(_("Asking params for inexistant profile")) | |
388 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
|
389 d = self.getParams(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
|
390 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
|
391 |
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
|
392 def getParams(self, profile_key): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
393 """Construct xml for asked profile |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
394 Take params xml as skeleton""" |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
395 profile = self.getProfileName(profile_key) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
396 if not profile: |
69 | 397 error(_("Asking params for inexistant profile")) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
398 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
|
399 |
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
|
400 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
|
401 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
|
402 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
|
403 return return_xml |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
404 |
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
|
405 return self.__constructProfileXml(profile).addCallback(returnXML) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
406 |
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
|
407 def getParamsForCategory(self, category, profile_key): |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
408 """Return node's xml for selected category""" |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
409 #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
|
410 profile = self.getProfileName(profile_key) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
411 if not profile: |
69 | 412 error(_("Asking params for inexistant profile")) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
413 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
|
414 |
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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 |
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
|
422 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
|
423 return "<category />" |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
424 |
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
|
425 d = self.__constructProfileXml(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
|
426 return d.addCallback(returnCategoryXml) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
427 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
428 def __getParamNode(self, name, category, type="@ALL@"): #FIXME: is type useful ? |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
429 """Return a node from the param_xml |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
430 @param name: name of the node |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
431 @param category: category of the node |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
432 @type: keyword for search: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
433 @ALL@ search everywhere |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
434 @GENERAL@ only search in general type |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
435 @INDIVIDUAL@ only search in individual type |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
436 @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
|
437 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
438 for type_node in self.dom.documentElement.childNodes: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
439 if ( ((type == "@ALL@" or type == "@GENERAL@") and type_node.nodeName == 'general') |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
440 or ( (type == "@ALL@" or type == "@INDIVIDUAL@") and type_node.nodeName == 'individual') ): |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
441 for node in type_node.getElementsByTagName('category'): |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
442 if node.getAttribute("name") == category: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
443 params = node.getElementsByTagName("param") |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
444 for param in params: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
445 if param.getAttribute("name") == name: |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
446 return (type_node.nodeName, param) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
447 return None |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
448 |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
449 def getParamsCategories(self): |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
450 """return the categories availables""" |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
451 categories=[] |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
452 for cat in self.dom.getElementsByTagName("category"): |
396
cecd22241d56
memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
453 name = cat.getAttribute("name") |
cecd22241d56
memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
454 if name not in categories: |
cecd22241d56
memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
455 categories.append(cat.getAttribute("name")) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
456 return categories |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
457 |
392
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
458 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
|
459 """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
|
460 #TODO: use different behaviour depending of the data type (e.g. password encrypted) |
392
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
461 if profile_key!="@NONE@": |
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
462 profile = self.getProfileName(profile_key) |
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
463 if not profile: |
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
464 error(_('Trying to set parameter for an unknown profile')) |
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
465 return #TODO: throw an error |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
466 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
467 node = self.__getParamNode(name, category, '@ALL@') |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
468 if not node: |
69 | 469 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
|
470 return |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
471 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
472 if node[0] == 'general': |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
473 self.params_gen[(category, name)] = value |
412 | 474 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
|
475 for profile in self.storage.getProfilesList(): |
392
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
476 if self.host.isConnected(profile): |
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
477 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
|
478 return |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
479 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
480 assert (node[0] == 'individual') |
392
20f11097d99b
memory: general param default value fix
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
481 assert (profile_key != "@NONE@") |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
482 |
61 | 483 type = node[1].getAttribute("type") |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
484 if type=="button": |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
485 print "clique",node.toxml() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
486 else: |
412 | 487 if self.host.isConnected(profile): #key can not exists if profile is not connected |
488 self.params[profile][(category, name)] = value | |
489 self.host.bridge.paramUpdate(name, value, category, profile) | |
490 self.storage.setIndParam(category, name, value, profile) | |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
491 |
0 | 492 class Memory: |
493 """This class manage all persistent informations""" | |
494 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
495 def __init__(self, host): |
69 | 496 info (_("Memory manager init")) |
412 | 497 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
|
498 self.host = host |
47 | 499 self.contacts={} |
0 | 500 self.presenceStatus={} |
399 | 501 self.lastResource={} #tmp, will be refactored with bdd integration |
47 | 502 self.subscriptions={} |
503 self.private={} #used to store private value | |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
504 self.server_features={} #used to store discovery's informations |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
505 self.server_identities={} |
364 | 506 self.config = self.parseMainConf() |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
507 host.set_const('savefile_private', SAVEFILE_PRIVATE) |
412 | 508 host.set_const('savefile_database', SAVEFILE_DATABASE) |
509 database_file = os.path.expanduser(self.getConfig('','local_dir')+ | |
510 self.host.get_const('savefile_database')) | |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
511 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
|
512 PersistentDict.storage = self.storage |
31e8c48b5f5d
core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents:
428
diff
changeset
|
513 self.params=Params(host, self.storage) |
412 | 514 self.loadFiles() |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
515 d = self.storage.initialized.addCallback(self.load) |
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
516 d.chainDeferred(self.initialized) |
0 | 517 |
364 | 518 def parseMainConf(self): |
519 """look for main .ini configuration file, and parse it""" | |
520 _config = SafeConfigParser(defaults=default_config) | |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
521 try: |
369
e83d0c21d64d
launching script now read config files
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
522 _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
|
523 except: |
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
524 error (_("Can't read main config !")) |
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
525 |
364 | 526 return _config |
527 | |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
528 def getConfig(self, section, name): |
364 | 529 """Get the main configuration option |
530 @param section: section of the config file (None or '' for DEFAULT) | |
531 @param name: name of the option | |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
532 """ |
364 | 533 if not section: |
534 section='DEFAULT' | |
535 try: | |
536 _value = self.config.get(section, name) | |
537 except NoOptionError, NoSectionError: | |
538 _value = '' | |
539 | |
540 return os.path.expanduser(_value) if name.endswith('_path') or name.endswith('_dir') else _value | |
541 | |
412 | 542 |
543 def loadFiles(self): | |
0 | 544 """Load parameters and all memory things from file/db""" |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
545 param_file_xml = os.path.expanduser(self.getConfig('','local_dir')+ |
61 | 546 self.host.get_const('savefile_param_xml')) |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
547 private_file = os.path.expanduser(self.getConfig('','local_dir')+ |
47 | 548 self.host.get_const('savefile_private')) |
0 | 549 |
412 | 550 #parameters template |
61 | 551 if os.path.exists(param_file_xml): |
0 | 552 try: |
61 | 553 self.params.load_xml(param_file_xml) |
69 | 554 debug(_("params template loaded")) |
0 | 555 except: |
69 | 556 error (_("Can't load params template !")) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
557 self.params.load_default_params() |
0 | 558 else: |
69 | 559 info (_("No params template, using default template")) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
560 self.params.load_default_params() |
0 | 561 |
47 | 562 #private |
563 if os.path.exists(private_file): | |
564 try: | |
565 with open(private_file, 'r') as private_pickle: | |
566 self.private=pickle.load(private_pickle) | |
69 | 567 debug(_("private values loaded")) |
47 | 568 except: |
69 | 569 error (_("Can't load private values !")) |
0 | 570 |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
571 def load(self, ignore): |
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
572 """Load parameters and all memory things from db""" |
412 | 573 #parameters data |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
574 return self.params.loadGenParams() |
412 | 575 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
576 def loadIndividualParams(self, profile): |
412 | 577 """Load individual parameters for a profile |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
578 @param profile: %(doc_profile)s""" |
412 | 579 return self.params.loadIndParams(profile) |
580 | |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
581 def purgeProfile(self, profile): |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
582 """Delete cache of data of profile |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
583 @param profile: %(doc_profile)s""" |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
584 self.params.purgeProfile(profile) |
412 | 585 |
0 | 586 def save(self): |
587 """Save parameters and all memory things to file/db""" | |
38 | 588 #TODO: need to encrypt files (at least passwords !) and set permissions |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
589 param_file_xml = os.path.expanduser(self.getConfig('','local_dir')+ |
61 | 590 self.host.get_const('savefile_param_xml')) |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
591 private_file = os.path.expanduser(self.getConfig('','local_dir')+ |
47 | 592 self.host.get_const('savefile_private')) |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
593 |
61 | 594 self.params.save_xml(param_file_xml) |
69 | 595 debug(_("params saved")) |
47 | 596 with open(private_file, 'w') as private_pickle: |
597 pickle.dump(self.private, private_pickle) | |
69 | 598 debug(_("private values saved")) |
0 | 599 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
600 def getProfilesList(self): |
412 | 601 return self.storage.getProfilesList() |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
602 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
603 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
604 def getProfileName(self, profile_key): |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
605 """Return name of profile from keyword |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
606 @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
|
607 @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
|
608 return self.params.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
609 |
68 | 610 def createProfile(self, name): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
611 """Create a new profile |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
612 @param name: Profile name |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
613 """ |
68 | 614 return self.params.createProfile(name) |
615 | |
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
|
616 def asyncCreateProfile(self, name): |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
617 """Create a new profile |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
618 @param name: Profile name |
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
619 """ |
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
|
620 return self.params.asyncCreateProfile(name) |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
621 |
68 | 622 def deleteProfile(self, name): |
623 """Delete an existing profile | |
624 @param name: Name of the profile""" | |
625 return self.params.deleteProfile(name) | |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
626 |
425
e4e9187e3b5b
backend, bridge: asynchronous history
Goffi <goffi@goffi.org>
parents:
423
diff
changeset
|
627 def addToHistory(self, from_jid, to_jid, message, timestamp=None, profile="@NONE@"): |
e4e9187e3b5b
backend, bridge: asynchronous history
Goffi <goffi@goffi.org>
parents:
423
diff
changeset
|
628 assert(profile!="@NONE@") |
e4e9187e3b5b
backend, bridge: asynchronous history
Goffi <goffi@goffi.org>
parents:
423
diff
changeset
|
629 return self.storage.addToHistory(from_jid, to_jid, message, timestamp, profile) |
0 | 630 |
425
e4e9187e3b5b
backend, bridge: asynchronous history
Goffi <goffi@goffi.org>
parents:
423
diff
changeset
|
631 def getHistory(self, from_jid, to_jid, limit=0, between=True): |
e4e9187e3b5b
backend, bridge: asynchronous history
Goffi <goffi@goffi.org>
parents:
423
diff
changeset
|
632 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between) |
0 | 633 |
47 | 634 def setPrivate(self, key, value): |
635 """Save a misc private value (mainly useful for plugins)""" | |
636 self.private[key] = value | |
637 | |
638 def getPrivate(self, key): | |
639 """return a private value | |
640 @param key: name of wanted value | |
641 @return: value or None if value don't exist""" | |
642 if self.private.has_key(key): | |
643 return self.private[key] | |
644 return None | |
645 | |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
646 def addServerFeature(self, feature, profile): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
647 """Add a feature discovered from server |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
648 @param feature: string of the feature |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
649 @param profile: which profile is using this server ?""" |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
650 if not self.server_features.has_key(profile): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
651 self.server_features[profile] = [] |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
652 self.server_features[profile].append(feature) |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
653 |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
654 def addServerIdentity(self, category, type, entity, profile): |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
655 """Add an identity discovered from server |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
656 @param feature: string of the feature |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
657 @param profile: which profile is using this server ?""" |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
658 if not self.server_identities.has_key(profile): |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
659 self.server_identities[profile] = {} |
318
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
660 if not self.server_identities[profile].has_key((category, type)): |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
661 self.server_identities[profile][(category, type)]=set() |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
662 self.server_identities[profile][(category, type)].add(entity) |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
663 |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
664 def getServerServiceEntities(self, category, type, profile): |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
665 """Return all available entities for a service""" |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
666 if self.server_identities.has_key(profile): |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
667 return self.server_identities[profile].get((category, type), set()) |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
668 else: |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
669 return None |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
670 |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
671 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
|
672 """Helper method to get first available entity for a service""" |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
673 entities = self.getServerServiceEntities(category, type, profile) |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
674 if entities == None: |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
675 warning(_("Entities not available, maybe they haven't been asked to server yet ?")) |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
676 return None |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
677 else: |
b544bec477dd
core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
678 return list(entities)[0] if entities else None |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
679 |
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
|
680 def hasServerFeature(self, feature, profile_key): |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
681 """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
|
682 profile = self.getProfileName(profile_key) |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
683 if not profile: |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
684 error (_('Trying find server feature for a non-existant profile')) |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
685 return |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
686 assert(self.server_features.has_key(profile)) |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
687 return feature in self.server_features[profile] |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
688 |
47 | 689 |
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
|
690 def addContact(self, contact_jid, attributes, groups, profile_key): |
47 | 691 debug("Memory addContact: %s",contact_jid.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
692 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
|
693 if not profile: |
69 | 694 error (_('Trying to add a contact 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
|
695 return |
0 | 696 assert(isinstance(attributes,dict)) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
697 assert(isinstance(groups,set)) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
698 if not self.contacts.has_key(profile): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
699 self.contacts[profile] = {} |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
700 self.contacts[profile][contact_jid.userhost()]=[attributes, groups] |
0 | 701 |
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
|
702 def delContact(self, contact_jid, profile_key): |
47 | 703 debug("Memory delContact: %s",contact_jid.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
704 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
|
705 if not profile: |
69 | 706 error (_('Trying to delete a contact 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
|
707 return |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
708 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
709 del self.contacts[profile][contact_jid.userhost()] |
47 | 710 |
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
|
711 def getContact(self, contact_jid, profile_key): |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
712 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
|
713 if not profile: |
69 | 714 error(_('Asking a contact 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
|
715 return None |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
716 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): |
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
|
717 return self.contacts[profile][contact_jid.userhost()] |
47 | 718 |
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
|
719 def getContacts(self, profile_key): |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
720 """Return list of contacts for given profile |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
721 @param profile_key: profile key |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
722 @return list of [contact, attr, groups]""" |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
723 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
|
724 if not profile: |
69 | 725 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
|
726 return [] |
0 | 727 ret=[] |
327
7c9784658163
core: fixed crash when roster list is empty
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
728 if self.contacts.has_key(profile): |
7c9784658163
core: fixed crash when roster list is empty
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
729 for contact in self.contacts[profile]: |
7c9784658163
core: fixed crash when roster list is empty
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
730 attr, groups = self.contacts[profile][contact] |
7c9784658163
core: fixed crash when roster list is empty
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
731 ret.append([contact, attr, groups ]) |
0 | 732 return ret |
399 | 733 |
734 def getLastResource(self, contact, profile_key): | |
735 """Return the last resource used by a contact | |
736 @param contact: contact jid (unicode) | |
737 @param profile_key: %(doc_profile_key)s""" | |
738 profile = self.getProfileName(profile_key) | |
739 if not profile: | |
740 error(_('Asking contacts for a non-existant profile')) | |
741 return "" | |
742 try: | |
743 return self.lastResource[profile][jid.JID(contact).userhost()] | |
744 except: | |
745 return "" | |
47 | 746 |
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
|
747 def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key): |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
748 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
|
749 if not profile: |
69 | 750 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
|
751 return |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
752 if not self.presenceStatus.has_key(profile): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
753 self.presenceStatus[profile] = {} |
399 | 754 if not self.lastResource.has_key(profile): |
755 self.lastResource[profile] = {} | |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
756 if not self.presenceStatus[profile].has_key(contact_jid.userhost()): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
757 self.presenceStatus[profile][contact_jid.userhost()] = {} |
47 | 758 resource = jid.parse(contact_jid.full())[2] or '' |
399 | 759 if resource: |
760 self.lastResource[profile][contact_jid.userhost()] = resource | |
761 | |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
762 self.presenceStatus[profile][contact_jid.userhost()][resource] = (show, priority, statuses) |
47 | 763 |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
764 def addWaitingSub(self, type, contact_jid, profile_key): |
47 | 765 """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
|
766 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
|
767 assert(profile) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
768 if not self.subscriptions.has_key(profile): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
769 self.subscriptions[profile] = {} |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
770 self.subscriptions[profile][contact_jid] = type |
47 | 771 |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
772 def delWaitingSub(self, contact_jid, profile_key): |
47 | 773 """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
|
774 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
|
775 assert(profile) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
776 if self.subscriptions.has_key(profile) and self.subscriptions[profile].has_key(contact_jid): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
777 del self.subscriptions[profile][contact_jid] |
47 | 778 |
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
|
779 def getWaitingSub(self, profile_key): |
47 | 780 """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
|
781 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
|
782 if not profile: |
69 | 783 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
|
784 return {} |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
785 if not self.subscriptions.has_key(profile): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
786 return {} |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
787 |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
788 return self.subscriptions[profile] |
0 | 789 |
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
|
790 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
|
791 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
|
792 if not profile: |
69 | 793 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
|
794 return {} |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
795 if not self.presenceStatus.has_key(profile): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
796 self.presenceStatus[profile] = {} |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
797 debug ("Memory getPresenceStatus (%s)", self.presenceStatus[profile]) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
798 return self.presenceStatus[profile] |
0 | 799 |
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
|
800 def getParamA(self, name, category, attr="value", profile_key='@DEFAULT@'): |
64 | 801 return self.params.getParamA(name, category, attr, profile_key) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
802 |
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
|
803 def asyncGetParamA(self, name, category, attr="value", profile_key='@DEFAULT@'): |
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
|
804 return self.params.asyncGetParamA(name, category, attr, profile_key) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
805 |
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
|
806 def getParamsUI(self, profile_key): |
105 | 807 return self.params.getParamsUI(profile_key) |
808 | |
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
|
809 def getParams(self, profile_key): |
105 | 810 return self.params.getParams(profile_key) |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
811 |
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
|
812 def getParamsForCategory(self, category, profile_key): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
813 return self.params.getParamsForCategory(category, profile_key) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
814 |
0 | 815 def getParamsCategories(self): |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
816 return self.params.getParamsCategories() |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
817 |
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
|
818 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
|
819 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
|
820 |
38 | 821 def importParams(self, xml): |
822 return self.params.importParams(xml) | |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
823 |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
824 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
|
825 return self.params.setDefault(name, category, callback, errback) |