annotate src/memory/memory.py @ 896:0199a17f4d92

misc: added gobject dependency for primitivus in README4PACKAGERS
author Goffi <goffi@goffi.org>
date Tue, 04 Mar 2014 00:29:10 +0100
parents 57c32d8ec847
children fab49a1d5ea2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
4 # SAT: a jabber client
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 802
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
10 # (at your option) any later version.
0
goffi@necton2
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
15 # GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 592
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
goffi@necton2
parents:
diff changeset
19
goffi@necton2
parents:
diff changeset
20 from __future__ import with_statement
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
21 from sat.core.i18n import _
0
goffi@necton2
parents:
diff changeset
22
goffi@necton2
parents:
diff changeset
23 import os.path
729
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
24 import csv
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
25 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
26 from xml.dom import minidom
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
27 from uuid import uuid4
326
0f9925193586 core, plugin mblog: fixed some exceptions
Goffi <goffi@goffi.org>
parents: 318
diff changeset
28 from logging import debug, info, warning, error
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
29 from twisted.internet import defer, reactor
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
30 from twisted.words.protocols.jabber import jid
645
17bd09cd1001 core: misc bug fixes
Goffi <goffi@goffi.org>
parents: 643
diff changeset
31 from twisted.python.failure import Failure
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 784
diff changeset
32 from sat.tools.xml_tools import paramsXML2XMLUI
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
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
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
36 from sat.core import exceptions
0
goffi@necton2
parents:
diff changeset
37
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
38 SAVEFILE_DATABASE = "/sat.db"
642
e07a03d52321 core: fix for methods signature
souliane <souliane@mailoo.org>
parents: 641
diff changeset
39 NO_SECURITY_LIMIT = -1
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
40 INDIVIDUAL = "individual"
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
41 GENERAL = "general"
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
42
679
59c9a7ff903d wix, misc: use picture of dimension 32x32 for tray icon + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 677
diff changeset
43
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
44 class Sessions(object):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
45 DEFAULT_TIMEOUT = 600
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
46
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
47 def __init__(self, timeout = None):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
48 """
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
49 @param timeout: nb of seconds before session destruction
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
50 """
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
51 self._sessions = dict()
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
52 self.timeout = timeout or Sessions.DEFAULT_TIMEOUT
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
53
757
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
54 def newSession(self, session_data=None, profile=None):
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
55 """ Create a new session
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
56 @param session_data: mutable data to use, default to a dict
757
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
57 @param profile: if set, the session is owned by the profile,
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
58 and profileGet must be used instead of __getitem__
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
59 @return: session_id, session_data
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
60 """
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
61 session_id = str(uuid4())
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
62 timer = reactor.callLater(self.timeout, self._purgeSession, session_id)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
63 if session_data is None:
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
64 session_data = {}
757
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
65 self._sessions[session_id] = (timer, session_data) if profile is None else (timer, session_data, profile)
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
66 return session_id, session_data
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
67
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
68 def _purgeSession(self, session_id):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
69 del self._sessions[session_id]
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
70 debug("Session [%s] purged" % session_id)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
71
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
72 def __len__(self):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
73 return len(self._sessions)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
74
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
75 def __contains__(self, session_id):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
76 return session_id in self._sessions
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
77
757
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
78 def profileGet(self, session_id, profile):
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
79 try:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
80 timer, session_data, profile_set = self._sessions[session_id]
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
81 except ValueError:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
82 raise exceptions.InternalError("You need to use __getitem__ when profile is not set")
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
83 if profile_set != profile:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
84 raise exceptions.InternalError("current profile differ from set profile !")
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
85 timer.reset(self.timeout)
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
86 return session_data
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
87
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
88 def __getitem__(self, session_id):
757
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
89 try:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
90 timer, session_data = self._sessions[session_id]
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
91 except ValueError:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
92 raise exceptions.InternalError("You need to use profileGet instead of __getitem__ when profile is set")
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
93 timer.reset(self.timeout)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
94 return session_data
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
95
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
96 def __setitem__(self, key, value):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
97 raise NotImplementedError("You need do use newSession to create a session")
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
98
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
99 def __delitem__(self, session_id):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
100 """ Cancel the timer, then actually delete the session data """
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
101 try:
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
102 timer = self._sessions[session_id][0]
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
103 timer.cancel()
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
104 self._purgeSession(session_id)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
105 except KeyError:
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
106 debug ("Session [%s] doesn't exists, timeout expired ?" % session_id)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
107
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
108 def keys(self):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
109 return self._sessions.keys()
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
110
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
111 def iterkeys(self):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
112 return self._sessions.iterkeys()
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
113
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
114
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
115 class Params(object):
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
116 """This class manage parameters with xml"""
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
117 ### TODO: add desciption in params
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
118
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
119 #TODO: move Watched in a plugin
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
120 #TODO: when priority is changed, a new presence stanza must be emitted
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
121 #TODO: int type (Priority should be int instead of string)
34
a544b376b6f0 use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents: 22
diff changeset
122 default_xml = u"""
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
123 <params>
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
124 <general>
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
125 </general>
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
126 <individual>
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
127 <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
128 <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
129 <param name="Password" value="" type="password" />
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
130 <param name="Priority" value="50" type="string" />
256
f5181f6dd98f Test value replaced by example values for memory params
Goffi <goffi@goffi.org>
parents: 228
diff changeset
131 <param name="Server" value="example.org" type="string" />
556
14dcbcdb6222 core: added Port parameter
Goffi <goffi@goffi.org>
parents: 553
diff changeset
132 <param name="Port" value="5222" type="string" />
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 784
diff changeset
133 <param name="NewAccount" label="%(label_NewAccount)s" type="button" callback_id="registerNewAccount"/>
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
134 <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
135 <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
136 </category>
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
137 <category name="Misc" label="%(category_misc)s">
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
138 <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
139 </category>
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
140 </individual>
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
141 </params>
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
142 """ % {
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
143 'category_connection': _("Connection"),
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
144 'label_NewAccount': _("Register new account"),
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
145 'label_autoconnect': _('Connect on frontend startup'),
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
146 'label_autodisconnect': _('Disconnect on frontend closure'),
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
147 'category_misc': _("Misc")
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
148 }
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
149
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
150 def load_default_params(self):
458
094050fe461e core: fixed Params class name in load_default_params
Goffi <goffi@goffi.org>
parents: 443
diff changeset
151 self.dom = minidom.parseString(Params.default_xml.encode('utf-8'))
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
152
557
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
153 def _mergeParams(self, source_node, dest_node):
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
154 """Look for every node in source_node and recursively copy them to dest if they don't exists"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
155
557
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
156 def getNodesMap(children):
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
157 ret = {}
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
158 for child in children:
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
159 if child.nodeType == child.ELEMENT_NODE:
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
160 ret[(child.tagName, child.getAttribute('name'))] = child
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
161 return ret
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
162 source_map = getNodesMap(source_node.childNodes)
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
163 dest_map = getNodesMap(dest_node.childNodes)
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
164 source_set = set(source_map.keys())
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
165 dest_set = set(dest_map.keys())
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
166 to_add = source_set.difference(dest_set)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
167
557
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
168 for node_key in to_add:
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
169 dest_node.appendChild(source_map[node_key].cloneNode(True))
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
170
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
171 to_recurse = source_set - to_add
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
172 for node_key in to_recurse:
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
173 self._mergeParams(source_map[node_key], dest_map[node_key])
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
174
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
175 def load_xml(self, xml_file):
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
176 """Load parameters template from file"""
557
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
177 self.dom = minidom.parse(xml_file)
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
178 default_dom = minidom.parseString(Params.default_xml.encode('utf-8'))
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
179 self._mergeParams(default_dom.documentElement, self.dom.documentElement)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
180
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
181 def loadGenParams(self):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
182 """Load general parameters data from storage
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
183 @return: deferred triggered once params are loaded"""
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
184 return self.storage.loadGenParams(self.params_gen)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
185
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
186 def loadIndParams(self, profile, cache=None):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
187 """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
188 set self.params cache or a temporary cache
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
189 @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
190 @param cache: if not None, will be used to store the value, as a short time cache
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
191 @return: deferred triggered once params are loaded"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
192 if cache is None:
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
193 self.params[profile] = {}
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
194 return self.storage.loadIndParams(self.params[profile] if cache is None else cache, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
195
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
196 def purgeProfile(self, profile):
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
197 """Remove cache data of a profile
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
198 @param profile: %(doc_profile)s"""
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
199 try:
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
200 del self.params[profile]
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
201 except KeyError:
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
202 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
203
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
204 def save_xml(self, filename):
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
205 """Save parameters template to xml file"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
206 with open(filename, 'wb') as xml_file:
214
e178e8f6d13a fixed some unicode issue
Goffi <goffi@goffi.org>
parents: 197
diff changeset
207 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
208
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
209 def __init__(self, host, storage):
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
210 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
211 self.host = host
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
212 self.storage = storage
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
213 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
214 self.params = {}
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
215 self.params_gen = {}
813
1a1600491d9d core: registerNewAccount partial fix
Goffi <goffi@goffi.org>
parents: 811
diff changeset
216 host.registerCallback(host.registerNewAccountCB, with_data=True, force_id="registerNewAccount")
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
217
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
218 def asyncCreateProfile(self, profile):
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
219 """Create a new profile
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
220 @param profile: name of the profile
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
221 @param callback: called when the profile actually exists in database and memory
893
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 866
diff changeset
222 @return: a Deferred instance
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
223 """
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
224 if self.storage.hasProfile(profile):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
225 info(_('The profile name already exists'))
751
1def5b7edf9f core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents: 747
diff changeset
226 return defer.fail(Failure(exceptions.ConflictError))
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
227 if not self.host.trigger.point("ProfileCreation", profile):
751
1def5b7edf9f core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents: 747
diff changeset
228 return defer.fail(Failure(exceptions.CancelError))
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
229 return self.storage.createProfile(profile)
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
230
894
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
231 def asyncDeleteProfile(self, profile, force=False):
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
232 """Delete an existing profile
893
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 866
diff changeset
233 @param profile: name of the profile
894
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
234 @param force: force the deletion even if the profile is connected.
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
235 To be used for direct calls only (not through the bridge).
893
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 866
diff changeset
236 @return: a Deferred instance
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 866
diff changeset
237 """
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
238 if not self.storage.hasProfile(profile):
893
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 866
diff changeset
239 info(_('Trying to delete an unknown profile'))
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 866
diff changeset
240 return defer.fail(Failure(exceptions.ProfileUnknownError))
894
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
241 if not force and self.host.isConnected(profile):
893
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 866
diff changeset
242 info(_("Trying to delete a connected profile"))
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 866
diff changeset
243 return defer.fail(Failure(exceptions.ConnectedProfileError))
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 866
diff changeset
244 return self.storage.deleteProfile(profile)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
245
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 722
diff changeset
246 def getProfileName(self, profile_key, return_profile_keys = False):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
247 """return profile according to profile_key
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
248 @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
249 @ALL@ for all profiles
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
250 @DEFAULT@ for default profile
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 722
diff changeset
251 @param return_profile_keys: if True, return unmanaged profile keys (like "@ALL@"). This keys must be managed by the caller
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 722
diff changeset
252 @return: requested profile name or emptry string if it doesn't exist"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
253 if profile_key == '@DEFAULT@':
443
7099ea9c1b12 core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents: 432
diff changeset
254 default = self.host.memory.memory_data.get('Profile_default')
7099ea9c1b12 core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents: 432
diff changeset
255 if not default:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
256 info(_('No default profile, returning first one')) # TODO: manage real default profile
625
5646ecd3e35e core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents: 620
diff changeset
257 try:
5646ecd3e35e core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents: 620
diff changeset
258 default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0]
5646ecd3e35e core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents: 620
diff changeset
259 except IndexError:
5646ecd3e35e core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents: 620
diff changeset
260 info(_('No profile exist yet'))
5646ecd3e35e core: fixed crash on first run, when no profile exist yet
Goffi <goffi@goffi.org>
parents: 620
diff changeset
261 return ""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
262 return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists
639
99eee75ec1b7 core: better handling of profile_key and don't write the param file anymore
souliane <souliane@mailoo.org>
parents: 635
diff changeset
263 elif profile_key == '@NONE@':
99eee75ec1b7 core: better handling of profile_key and don't write the param file anymore
souliane <souliane@mailoo.org>
parents: 635
diff changeset
264 raise exceptions.ProfileNotSetError
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 722
diff changeset
265 elif return_profile_keys and profile_key in ["@ALL@"]:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 722
diff changeset
266 return profile_key # this value must be managed by the caller
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
267 if not self.storage.hasProfile(profile_key):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
268 info(_('Trying to access an unknown profile'))
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 722
diff changeset
269 return "" # FIXME: raise exceptions.ProfileUnknownError here (must be well checked, this method is used in lot of places)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
270 return profile_key
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
271
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
272 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
273 """return node with given tag
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
274 @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
275 @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
276 @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
277 @return: node if it exist or None
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
278 """
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
279 for node in parent.childNodes:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
280 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
281 #the node already exists
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
282 return node
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
283 #the node is new
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
284 return None
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
285
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
286 def updateParams(self, xml, security_limit=NO_SECURITY_LIMIT, app=''):
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 813
diff changeset
287 """import xml in parameters, update if the param already exists
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
288 If security_limit is specified and greater than -1, the parameters
778
bfafed251b40 memory: fixed wrong information in the docstrings for security_limit
souliane <souliane@mailoo.org>
parents: 777
diff changeset
289 that have a security level greater than security_limit are skipped.
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
290 @param xml: parameters in xml form
778
bfafed251b40 memory: fixed wrong information in the docstrings for security_limit
souliane <souliane@mailoo.org>
parents: 777
diff changeset
291 @param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
292 @param app: name of the frontend registering the parameters or empty value
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
293 """
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
294 src_parent = minidom.parseString(xml.encode('utf-8')).documentElement
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
295
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
296 def pre_process_app_node(src_parent, security_limit, app):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
297 """Parameters that are registered from a frontend must be checked"""
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
298 to_remove = []
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
299 for type_node in src_parent.childNodes:
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
300 if type_node.nodeName != INDIVIDUAL:
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
301 to_remove.append(type_node) # accept individual parameters only
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
302 continue
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
303 for cat_node in type_node.childNodes:
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
304 if cat_node.nodeName != 'category':
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
305 to_remove.append(cat_node)
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
306 continue
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
307 to_remove_count = 0 # count the params to be removed from current category
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
308 for node in cat_node.childNodes:
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
309 if node.nodeName != "param" or not self.checkSecurityLimit(node, security_limit):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
310 to_remove.append(node)
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
311 to_remove_count += 1
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
312 continue
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
313 node.setAttribute('app', app)
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
314 if len(cat_node.childNodes) == to_remove_count: # remove empty category
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
315 for dummy in xrange(0, to_remove_count):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
316 to_remove.pop()
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
317 to_remove.append(cat_node)
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
318 for node in to_remove:
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
319 node.parentNode.removeChild(node)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
320
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
321 def import_node(tgt_parent, src_parent):
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
322 for child in src_parent.childNodes:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
323 if child.nodeName == '#text':
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
324 continue
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
325 node = self.__get_unique_node(tgt_parent, child.nodeName, child.getAttribute("name"))
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
326 if not node: # The node is new
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
327 tgt_parent.appendChild(child)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
328 else:
662
4f747d7fde8c core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents: 656
diff changeset
329 if child.nodeName == "param":
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 813
diff changeset
330 # The child updates an existing parameter, we replace the node
662
4f747d7fde8c core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents: 656
diff changeset
331 tgt_parent.replaceChild(child, node)
4f747d7fde8c core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents: 656
diff changeset
332 else:
4f747d7fde8c core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents: 656
diff changeset
333 # the node already exists, we recurse 1 more level
4f747d7fde8c core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents: 656
diff changeset
334 import_node(node, child)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
335
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
336 if app:
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
337 pre_process_app_node(src_parent, security_limit, app)
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
338 import_node(self.dom.documentElement, src_parent)
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
339
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
340 def paramsRegisterApp(self, xml, security_limit, app):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
341 """Register frontend's specific parameters
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
342 If security_limit is specified and greater than -1, the parameters
778
bfafed251b40 memory: fixed wrong information in the docstrings for security_limit
souliane <souliane@mailoo.org>
parents: 777
diff changeset
343 that have a security level greater than security_limit are skipped.
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
344 @param xml: XML definition of the parameters to be added
778
bfafed251b40 memory: fixed wrong information in the docstrings for security_limit
souliane <souliane@mailoo.org>
parents: 777
diff changeset
345 @param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
346 @param app: name of the frontend registering the parameters
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
347 """
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
348 if not app:
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
349 warning(_("Trying to register frontends parameters with no specified app: aborted"))
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
350 return
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
351 if not hasattr(self, "frontends_cache"):
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 813
diff changeset
352 self.frontends_cache = []
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
353 if app in self.frontends_cache:
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 813
diff changeset
354 debug(_("Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app}))
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
355 return
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 813
diff changeset
356 self.frontends_cache.append(app)
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
357 self.updateParams(xml, security_limit, app)
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
358 debug("Frontends parameters registered for %(app)s" % {'app': app})
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
359
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
360 def __default_ok(self, value, name, category):
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
361 #FIXME: will not work with individual parameters
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
362 self.setParam(name, value, category)
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
363
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
364 def __default_ko(self, failure, name, category):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
365 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
366
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
367 def setDefault(self, name, category, callback, errback=None):
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
368 """Set default value of parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
369 '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
370 @param name: name of the parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
371 @param category: category of the parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
372 @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
373 @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
374 """
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
375 #TODO: send signal param update if value changed
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
376 #TODO: manage individual paramaters
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
377 debug ("setDefault called for %(category)s/%(name)s" % {"category": category, "name": name})
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
378 node = self._getParamNode(name, category, '@ALL@')
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
379 if not node:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
380 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
381 return
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
382 if node[1].getAttribute('default_cb') == 'yes':
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
383 # del node[1].attributes['default_cb'] # default_cb is not used anymore as a flag to know if we have to set the default value,
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
384 # and we can still use it later e.g. to call a generic setDefault method
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
385 value = self._getParam(category, name, GENERAL)
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
386 if value is None: # no value set by the user: we have the default value
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
387 debug ("Default value to set, using callback")
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
388 d = defer.maybeDeferred(callback)
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
389 d.addCallback(self.__default_ok, name, category)
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
390 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
391
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
392 def _getAttr(self, node, attr, value):
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
393 """ get attribute value
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
394 @param node: XML param node
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
395 @param attr: name of the attribute to get (e.g.: 'value' or 'type')
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
396 @param value: user defined value"""
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
397 if attr == 'value':
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
398 value_to_use = value if value is not None else node.getAttribute(attr) # we use value (user defined) if it exist, else we use node's default value
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
399 if node.getAttribute('type') == 'bool':
866
f27d736428f1 core (memory): added 'no' value management in configuration's booleans
Goffi <goffi@goffi.org>
parents: 853
diff changeset
400 return value_to_use.lower() not in ('false', '0', 'no')
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
401 return value_to_use
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
402 return node.getAttribute(attr)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
403
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
404 def __type_to_string(self, result):
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
405 """ convert result to string, according to its type """
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
406 if isinstance(result, bool):
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
407 return "true" if result else "false"
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
408 return result
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
409
639
99eee75ec1b7 core: better handling of profile_key and don't write the param file anymore
souliane <souliane@mailoo.org>
parents: 635
diff changeset
410 def getStringParamA(self, name, category, attr="value", profile_key="@NONE@"):
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
411 """ Same as getParamA but for bridge: convert non string value to string """
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
412 return self.__type_to_string(self.getParamA(name, category, attr, profile_key))
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
413
639
99eee75ec1b7 core: better handling of profile_key and don't write the param file anymore
souliane <souliane@mailoo.org>
parents: 635
diff changeset
414 def getParamA(self, name, category, attr="value", profile_key="@NONE@"):
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
415 """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
416 @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
417 @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
418 @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
419 @param profile: owner of the param (@ALL@ for everyone)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
420
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
421 @return: attribute"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
422 #FIXME: looks really dirty and buggy, need to be reviewed/refactored
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
423 node = self._getParamNode(name, category)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
424 if not node:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
425 error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
426 raise exceptions.NotFound
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
427
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
428 if node[0] == GENERAL:
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
429 value = self._getParam(category, name, GENERAL)
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
430 return self._getAttr(node[1], attr, value)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
431
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
432 assert node[0] == INDIVIDUAL
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
433
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
434 profile = self.getProfileName(profile_key)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
435 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
436 error(_('Requesting a param for an non-existant profile'))
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
437 raise exceptions.ProfileUnknownError
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
438
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
439 if profile not in self.params:
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
440 error(_('Requesting synchronous param for not connected profile'))
557
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
441 raise exceptions.NotConnectedProfileError(profile)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
442
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
443 if attr == "value":
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
444 value = self._getParam(category, name, profile=profile)
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
445 return self._getAttr(node[1], attr, value)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
446
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
447 def asyncGetStringParamA(self, name, category, attr="value", security_limit=NO_SECURITY_LIMIT, profile_key="@NONE@"):
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
448 d = self.asyncGetParamA(name, category, attr, security_limit, profile_key)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
449 d.addCallback(self.__type_to_string)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
450 return d
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
451
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
452 def asyncGetParamA(self, name, category, attr="value", security_limit=NO_SECURITY_LIMIT, profile_key="@NONE@"):
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
453 """Helper method to get a specific attribute
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
454 @param name: name of the parameter
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
455 @param category: category of the parameter
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
456 @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
457 @param profile: owner of the param (@ALL@ for everyone)"""
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
458 node = self._getParamNode(name, category)
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
459 if not node:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
460 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
461 return None
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
462
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
463 if not self.checkSecurityLimit(node[1], security_limit):
844
f3513c8cc2e6 misc: fix unnamed arguments in format strings
souliane <souliane@mailoo.org>
parents: 833
diff changeset
464 warning(_("Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!"
f3513c8cc2e6 misc: fix unnamed arguments in format strings
souliane <souliane@mailoo.org>
parents: 833
diff changeset
465 % {'param': name, 'cat': category}))
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
466 return None
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
467
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
468 if node[0] == GENERAL:
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
469 value = self._getParam(category, name, GENERAL)
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
470 return defer.succeed(self._getAttr(node[1], attr, value))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
471
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
472 assert node[0] == INDIVIDUAL
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
473
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
474 profile = self.getProfileName(profile_key)
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
475 if not profile:
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
476 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
477 return defer.fail()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
478
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
479 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
480 return defer.succeed(node[1].getAttribute(attr))
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
481 try:
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
482 value = self._getParam(category, name, profile=profile)
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
483 return defer.succeed(self._getAttr(node[1], attr, value))
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
484 except exceptions.ProfileNotInCacheError:
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
485 #We have to ask data to the storage manager
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 412
diff changeset
486 d = self.storage.getIndParam(category, name, profile)
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
487 return d.addCallback(lambda value: self._getAttr(node[1], attr, value))
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
488
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
489 def _getParam(self, category, name, type_=INDIVIDUAL, cache=None, profile="@NONE@"):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
490 """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
491 @param category: param category
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
492 @param name: param name
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
493 @param type_: GENERAL or INDIVIDUAL
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
494 @param cache: temporary cache, to use when profile is not logged
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
495 @param profile: the profile name (not profile key, i.e. name and not something like @DEFAULT@)
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
496 @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
497 """
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
498 if type_ == GENERAL:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
499 if (category, name) in self.params_gen:
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
500 return self.params_gen[(category, name)]
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
501 return None # This general param has the default value
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
502 assert (type_ == INDIVIDUAL)
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
503 if profile == "@NONE@":
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
504 raise exceptions.ProfileNotSetError
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
505 if profile in self.params:
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
506 cache = self.params[profile] # if profile is in main cache, we use it,
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
507 # ignoring the temporary cache
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
508 elif cache is None: # else we use the temporary cache if it exists, or raise an exception
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
509 raise exceptions.ProfileNotInCacheError
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
510 if (category, name) not in cache:
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
511 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
512 return cache[(category, name)]
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
513
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
514 def __constructProfileXml(self, security_limit, app, profile):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
515 """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
516 /!\ as noticed in doc, don't forget to unlink the minidom.Document
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
517 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params.
642
e07a03d52321 core: fix for methods signature
souliane <souliane@mailoo.org>
parents: 641
diff changeset
518 Otherwise sole the params which have a security level defined *and*
e07a03d52321 core: fix for methods signature
souliane <souliane@mailoo.org>
parents: 641
diff changeset
519 lower or equal to the specified value are returned.
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
520 @param app: name of the frontend requesting the parameters, or '' to get all parameters
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
521 @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
522 @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
523 """
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
524
784
900987e1c0c4 memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents: 779
diff changeset
525 def checkNode(node):
900987e1c0c4 memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents: 779
diff changeset
526 """Check the node against security_limit and app"""
900987e1c0c4 memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents: 779
diff changeset
527 return self.checkSecurityLimit(node, security_limit) and self.checkApp(node, app)
900987e1c0c4 memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents: 779
diff changeset
528
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
529 def constructProfile(ignore, profile_cache):
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
530 # init the result document
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
531 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
532 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
533
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
534 for type_node in self.dom.documentElement.childNodes:
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
535 if type_node.nodeName != GENERAL and type_node.nodeName != INDIVIDUAL:
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
536 continue
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
537 # we use all params, general and individual
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
538 for cat_node in type_node.childNodes:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
539 if cat_node.nodeName != 'category':
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
540 continue
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
541 category = cat_node.getAttribute('name')
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
542 dest_params = {} # result (merged) params for category
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
543 if category not in cache:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
544 # we make a copy for the new xml
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
545 cache[category] = dest_cat = cat_node.cloneNode(True)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
546 for node in dest_cat.childNodes:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
547 if node.nodeName != "param":
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
548 continue
784
900987e1c0c4 memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents: 779
diff changeset
549 if not checkNode(node):
779
a978c703bf57 memory: bug fix related to method paramsRegisterApp + getParams was not always returning a Deferred
souliane <souliane@mailoo.org>
parents: 778
diff changeset
550 dest_cat.removeChild(node)
a978c703bf57 memory: bug fix related to method paramsRegisterApp + getParams was not always returning a Deferred
souliane <souliane@mailoo.org>
parents: 778
diff changeset
551 continue
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
552 dest_params[node.getAttribute('name')] = node
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
553 new_node = True
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
554 else:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
555 # It's not a new node, we use the previously cloned one
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
556 dest_cat = cache[category]
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
557 new_node = False
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
558 params = cat_node.getElementsByTagName("param")
395
79fe50fc8edc memory: multiples params of the same category are now merged
Goffi <goffi@goffi.org>
parents: 392
diff changeset
559
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
560 for param_node in params:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
561 # we have to merge new params (we are parsing individual parameters, we have to add them
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
562 # to the previously parsed general ones)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
563 name = param_node.getAttribute('name')
784
900987e1c0c4 memory: factorize the node checks in Params.__constructProfileXml
souliane <souliane@mailoo.org>
parents: 779
diff changeset
564 if not checkNode(param_node):
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
565 continue
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
566 if name not in dest_params:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
567 # this is reached when a previous category exists
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
568 dest_params[name] = param_node.cloneNode(True)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
569 dest_cat.appendChild(dest_params[name])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
570
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
571 profile_value = self._getParam(category,
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
572 name, type_node.nodeName,
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
573 cache=profile_cache, profile=profile)
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
574 if profile_value is not None:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
575 # there is a value for this profile, we must change the default
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
576 dest_params[name].setAttribute('value', profile_value)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
577 if new_node:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
578 prof_xml.documentElement.appendChild(dest_cat)
395
79fe50fc8edc memory: multiples params of the same category are now merged
Goffi <goffi@goffi.org>
parents: 392
diff changeset
579
634
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
580 to_remove = []
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
581 for cat_node in prof_xml.documentElement.childNodes:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
582 # we remove empty categories
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
583 if cat_node.getElementsByTagName("param").length == 0:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
584 to_remove.append(cat_node)
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
585 for node in to_remove:
ca2cae6b2c6d core: security attribute added to the parameters
souliane <souliane@mailoo.org>
parents: 625
diff changeset
586 prof_xml.documentElement.removeChild(node)
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
587 return prof_xml
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
588
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
589 if profile in self.params:
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
590 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
591 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
592 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
593 #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
594 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
595 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
596
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
597 return d.addCallback(constructProfile, profile_cache)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
598
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
599 def getParamsUI(self, security_limit, app, profile_key):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
600 """
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
601 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
602 Otherwise sole the params which have a security level defined *and*
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
603 lower or equal to the specified value are returned.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
604 @param app: name of the frontend requesting the parameters, or '' to get all parameters
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
605 @param profile_key: Profile key which can be either a magic (eg: @DEFAULT@) or the name of an existing profile.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
606 @return: a SàT XMLUI for parameters
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
607 """
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
608 profile = self.getProfileName(profile_key)
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
609 if not profile:
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
610 error(_("Asking params for inexistant profile"))
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
611 return ""
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
612 d = self.getParams(security_limit, app, profile)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 784
diff changeset
613 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
614
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
615 def getParams(self, security_limit, app, profile_key):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
616 """Construct xml for asked profile, take params xml as skeleton
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
617 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
618 Otherwise sole the params which have a security level defined *and*
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
619 lower or equal to the specified value are returned.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
620 @param app: name of the frontend requesting the parameters, or '' to get all parameters
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
621 @param profile_key: Profile key which can be either a magic (eg: @DEFAULT@) or the name of an existing profile.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
622 @return: XML of parameters
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
623 """
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
624 profile = self.getProfileName(profile_key)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
625 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
626 error(_("Asking params for inexistant profile"))
779
a978c703bf57 memory: bug fix related to method paramsRegisterApp + getParams was not always returning a Deferred
souliane <souliane@mailoo.org>
parents: 778
diff changeset
627 return defer.succeed("")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
628
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
629 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
630 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
631 prof_xml.unlink()
643
262d9d9ad27a plugin XEP-0085: renamed category and parameter
souliane <souliane@mailoo.org>
parents: 642
diff changeset
632 return '\n'.join((line for line in return_xml.split('\n') if line))
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
633
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
634 return self.__constructProfileXml(security_limit, app, profile).addCallback(returnXML)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
635
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
636 def getParamsForCategory(self, category, security_limit, app, profile_key):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
637 """
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
638 @param category: the desired category
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
639 @param security_limit: NO_SECURITY_LIMIT (-1) to return all the params.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
640 Otherwise sole the params which have a security level defined *and*
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
641 lower or equal to the specified value are returned.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
642 @param app: name of the frontend requesting the parameters, or '' to get all parameters
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
643 @param profile_key: Profile key which can be either a magic (eg: @DEFAULT@) or the name of an existing profile.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
644 @return: node's xml for selected category
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
645 """
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
646 #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
647 profile = self.getProfileName(profile_key)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
648 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
649 error(_("Asking params for inexistant profile"))
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
650 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
651
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
652 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
653 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
654 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
655 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
656 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
657 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
658
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
659 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
660 return "<category />"
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
661
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
662 d = self.__constructProfileXml(security_limit, app, profile)
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
663 return d.addCallback(returnCategoryXml)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
664
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
665 def _getParamNode(self, name, category, type_="@ALL@"): # FIXME: is type_ useful ?
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
666 """Return a node from the param_xml
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
667 @param name: name of the node
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
668 @param category: category of the node
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
669 @type_: keyword for search:
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
670 @ALL@ search everywhere
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
671 @GENERAL@ only search in general type
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
672 @INDIVIDUAL@ only search in individual type
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
673 @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
674
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
675 for type_node in self.dom.documentElement.childNodes:
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
676 if (((type_ == "@ALL@" or type_ == "@GENERAL@") and type_node.nodeName == GENERAL)
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
677 or ((type_ == "@ALL@" or type_ == "@INDIVIDUAL@") and type_node.nodeName == INDIVIDUAL)):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
678 for node in type_node.getElementsByTagName('category'):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
679 if node.getAttribute("name") == category:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
680 params = node.getElementsByTagName("param")
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
681 for param in params:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
682 if param.getAttribute("name") == name:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
683 return (type_node.nodeName, param)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
684 return None
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
685
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
686 def getParamsCategories(self):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
687 """return the categories availables"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
688 categories = []
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
689 for cat in self.dom.getElementsByTagName("category"):
396
cecd22241d56 memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents: 395
diff changeset
690 name = cat.getAttribute("name")
cecd22241d56 memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents: 395
diff changeset
691 if name not in categories:
cecd22241d56 memory: avoid duplicate in getParamsCategories
Goffi <goffi@goffi.org>
parents: 395
diff changeset
692 categories.append(cat.getAttribute("name"))
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
693 return categories
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
694
642
e07a03d52321 core: fix for methods signature
souliane <souliane@mailoo.org>
parents: 641
diff changeset
695 def setParam(self, name, value, category, security_limit=NO_SECURITY_LIMIT, profile_key='@NONE@'):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
696 """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
697 #TODO: use different behaviour depending of the data type (e.g. password encrypted)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
698 if profile_key != "@NONE@":
392
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
699 profile = self.getProfileName(profile_key)
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
700 if not profile:
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
701 error(_('Trying to set parameter for an unknown profile'))
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
702 return # TODO: throw an error
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
703
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
704 node = self._getParamNode(name, category, '@ALL@')
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
705 if not node:
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 639
diff changeset
706 error(_('Requesting an unknown parameter (%(category)s/%(name)s)')
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 639
diff changeset
707 % {'category': category, 'name': name})
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
708 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
709
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
710 if not self.checkSecurityLimit(node[1], security_limit):
844
f3513c8cc2e6 misc: fix unnamed arguments in format strings
souliane <souliane@mailoo.org>
parents: 833
diff changeset
711 warning(_("Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!"
f3513c8cc2e6 misc: fix unnamed arguments in format strings
souliane <souliane@mailoo.org>
parents: 833
diff changeset
712 % {'param': name, 'cat': category}))
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
713 return
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 639
diff changeset
714
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
715 if node[0] == GENERAL:
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
716 self.params_gen[(category, name)] = value
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
717 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
718 for profile in self.storage.getProfilesList():
392
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
719 if self.host.isConnected(profile):
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
720 self.host.bridge.paramUpdate(name, value, category, profile)
635
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
721 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
722 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
723
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
724 assert (node[0] == INDIVIDUAL)
392
20f11097d99b memory: general param default value fix
Goffi <goffi@goffi.org>
parents: 369
diff changeset
725 assert (profile_key != "@NONE@")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
726
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
727 type_ = node[1].getAttribute("type")
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
728 if type_ == "button":
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
729 print "clique", node.toxml()
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
730 else:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
731 if self.host.isConnected(profile): # key can not exists if profile is not connected
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
732 self.params[profile][(category, name)] = value
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
733 self.host.bridge.paramUpdate(name, value, category, profile)
635
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
734 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile)
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
735 self.storage.setIndParam(category, name, value, profile)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
736
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
737 def checkSecurityLimit(self, node, security_limit):
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
738 """Check the given node against the given security limit.
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
739 The value NO_SECURITY_LIMIT (-1) means that everything is allowed.
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
740 @return: True if this node can be accessed with the given security limit.
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
741 """
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
742 if security_limit < 0:
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
743 return True
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
744 if node.hasAttribute("security"):
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
745 if int(node.getAttribute("security")) <= security_limit:
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
746 return True
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
747 return False
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
748
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
749 def checkApp(self, node, app):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
750 """Check the given node against the given app.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
751 @param node: parameter node
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
752 @param app: name of the frontend requesting the parameters, or '' to get all parameters
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
753 @return: True if this node concerns the given app.
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
754 """
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
755 if not app or not node.hasAttribute("app"):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
756 return True
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
757 return node.getAttribute("app") == app
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
758
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
759
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
760 class Memory(object):
0
goffi@necton2
parents:
diff changeset
761 """This class manage all persistent informations"""
goffi@necton2
parents:
diff changeset
762
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
763 def __init__(self, host):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
764 info(_("Memory manager init"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
765 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
766 self.host = host
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
767 self.entitiesCache = {} # XXX: keep presence/last resource/other data in cache
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
768 # /!\ an entity is not necessarily in roster
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
769 self.subscriptions = {}
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
770 self.server_features = {} # used to store discovery's informations
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
771 self.server_identities = {}
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
772 self.config = self.parseMainConf()
853
c2f6ada7858f core (sqlite): automatic database update:
Goffi <goffi@goffi.org>
parents: 844
diff changeset
773 host.setConst('savefile_database', SAVEFILE_DATABASE)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
774 database_file = os.path.expanduser(self.getConfig('', 'local_dir') +
853
c2f6ada7858f core (sqlite): automatic database update:
Goffi <goffi@goffi.org>
parents: 844
diff changeset
775 self.host.getConst('savefile_database'))
c2f6ada7858f core (sqlite): automatic database update:
Goffi <goffi@goffi.org>
parents: 844
diff changeset
776 self.storage = SqliteStorage(database_file, host.__version__)
432
31e8c48b5f5d core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents: 428
diff changeset
777 PersistentDict.storage = self.storage
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
778 self.params = Params(host, self.storage)
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
779 info(_("Loading default params template"))
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
780 self.params.load_default_params()
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
781 d = self.storage.initialized.addCallback(lambda ignore: self.load())
443
7099ea9c1b12 core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents: 432
diff changeset
782 self.memory_data = PersistentDict("memory")
7099ea9c1b12 core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents: 432
diff changeset
783 d.addCallback(lambda ignore: self.memory_data.load())
428
a4a9efadabfc core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents: 425
diff changeset
784 d.chainDeferred(self.initialized)
0
goffi@necton2
parents:
diff changeset
785
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
786 def parseMainConf(self):
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
787 """look for main .ini configuration file, and parse it"""
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
788 _config = SafeConfigParser(defaults=default_config)
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
789 try:
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 365
diff changeset
790 _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
791 except:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
792 error(_("Can't read main config !"))
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
793
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
794 return _config
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
795
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
796 def getConfig(self, section, name):
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
797 """Get the main configuration option
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
798 @param section: section of the config file (None or '' for DEFAULT)
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
799 @param name: name of the option
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
800 """
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
801 if not section:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
802 section = 'DEFAULT'
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
803 try:
729
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
804 value = self.config.get(section, name)
483
655695f85e5b core: fixed bad try/except block in memory
Goffi <goffi@goffi.org>
parents: 480
diff changeset
805 except (NoOptionError, NoSectionError):
729
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
806 value = ''
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
807
729
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
808 if name.endswith('_path') or name.endswith('_dir'):
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
809 value = os.path.expanduser(value)
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
810 # thx to Brian (http://stackoverflow.com/questions/186857/splitting-a-semicolon-separated-string-to-a-dictionary-in-python/186873#186873)
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
811 elif name.endswith('_list'):
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
812 value = csv.reader([value], delimiter=',', quotechar='"').next()
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
813 elif name.endswith('_dict'):
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
814 value = dict(csv.reader([item], delimiter=':', quotechar='"').next()
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
815 for item in csv.reader([value], delimiter=',', quotechar='"').next())
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
816 return value
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
817
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
818 def load_xml(self, filename):
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
819 """Load parameters template from xml file"""
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
820 if filename is None:
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
821 return False
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
822 filename = os.path.expanduser(filename)
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
823 if os.path.exists(filename):
0
goffi@necton2
parents:
diff changeset
824 try:
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
825 self.params.load_xml(filename)
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
826 debug(_("Parameters loaded from file: %s") % filename)
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
827 return True
557
4f856dd4c0d0 core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents: 556
diff changeset
828 except Exception as e:
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
829 error(_("Can't load parameters from file: %s") % e)
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
830 return False
0
goffi@necton2
parents:
diff changeset
831
443
7099ea9c1b12 core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents: 432
diff changeset
832 def load(self):
428
a4a9efadabfc core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents: 425
diff changeset
833 """Load parameters and all memory things from db"""
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
834 #parameters data
428
a4a9efadabfc core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents: 425
diff changeset
835 return self.params.loadGenParams()
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
836
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
837 def loadIndividualParams(self, profile):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
838 """Load individual parameters for a profile
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
839 @param profile: %(doc_profile)s"""
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
840 return self.params.loadIndParams(profile)
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
841
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
842 def startProfileSession(self, profile):
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
843 """"Iniatialise session for a profile
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
844 @param profile: %(doc_profile)s"""
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
845 info(_("[%s] Profile session started" % profile))
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
846 self.entitiesCache[profile] = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
847
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
848 def purgeProfileSession(self, profile):
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
849 """Delete cache of data of profile
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
850 @param profile: %(doc_profile)s"""
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
851 info(_("[%s] Profile session purge" % profile))
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
852 self.params.purgeProfile(profile)
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
853 try:
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
854 del self.entitiesCache[profile]
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
855 except KeyError:
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
856 error(_("Trying to purge roster status cache for a profile not in memory: [%s]") % profile)
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
857
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
858 def save_xml(self, filename=None):
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
859 """Save parameters template to xml file"""
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
860 if filename is None:
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
861 return False
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
862 #TODO: need to encrypt files (at least passwords !) and set permissions
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
863 filename = os.path.expanduser(filename)
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
864 try:
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
865 self.params.save_xml(filename)
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
866 debug(_("Parameters saved to file: %s") % filename)
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
867 return True
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
868 except Exception as e:
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
869 error(_("Can't save parameters to file: %s") % e)
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
870 return False
0
goffi@necton2
parents:
diff changeset
871
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
872 def getProfilesList(self):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
873 return self.storage.getProfilesList()
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
874
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 722
diff changeset
875 def getProfileName(self, profile_key, return_profile_keys = False):
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
876 """Return name of profile from keyword
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
877 @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
878 @return: profile name or None if it doesn't exist"""
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 722
diff changeset
879 return self.params.getProfileName(profile_key, return_profile_keys)
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
880
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
881 def asyncCreateProfile(self, name):
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
882 """Create a new profile
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
883 @param name: Profile name
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
884 """
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
885 return self.params.asyncCreateProfile(name)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
886
894
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
887 def asyncDeleteProfile(self, name, force=False):
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
888 """Delete an existing profile
894
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
889 @param name: Name of the profile
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
890 @param force: force the deletion even if the profile is connected.
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
891 To be used for direct calls only (not through the bridge).
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
892 @return: a Deferred instance
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
893 """
57c32d8ec847 core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents: 893
diff changeset
894 return self.params.asyncDeleteProfile(name, force)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
895
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
896 def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile="@NONE@"):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
897 assert profile != "@NONE@"
669
ffb716804580 core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents: 662
diff changeset
898 if extra is None:
ffb716804580 core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents: 662
diff changeset
899 extra = {}
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
900 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
0
goffi@necton2
parents:
diff changeset
901
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
902 def getHistory(self, from_jid, to_jid, limit=0, between=True, profile="@NONE@"):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
903 assert profile != "@NONE@"
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
904 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
0
goffi@necton2
parents:
diff changeset
905
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
906 def addServerFeature(self, feature, jid_, profile):
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
907 """Add a feature discovered from server
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
908 @param feature: string of the feature
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
909 @param jid_: the jid of the target server
747
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
910 @param profile: which profile asked this server?"""
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
911 if profile not in self.server_features:
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
912 self.server_features[profile] = {}
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
913 features = self.server_features[profile].setdefault(jid_, [])
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
914 features.append(feature)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
915
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
916 def addServerIdentity(self, category, type_, entity, jid_, profile):
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
917 """Add an identity discovered from server
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
918 @param feature: string of the feature
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
919 @param jid_: the jid of the target server
747
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
920 @param profile: which profile asked this server?"""
566
9faccd827657 core: sqlite storage constraint fix
Goffi <goffi@goffi.org>
parents: 557
diff changeset
921 if not profile in self.server_identities:
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
922 self.server_identities[profile] = {}
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
923 identities = self.server_identities[profile].setdefault(jid_, {})
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
924 if (category, type_) not in identities:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
925 identities[(category, type_)] = set()
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
926 identities[(category, type_)].add(entity)
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
927
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
928 def getServerServiceEntities(self, category, type_, jid_=None, profile=None):
747
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
929 """Return all available entities of a server for the service (category, type_)
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
930 @param category: identity's category
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
931 @param type_: identitiy's type
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
932 @param jid_: the jid of the target server (None for profile's server)
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
933 @param profile: which profile is asking this server?
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
934 @return: a set of entities or None if no cached data were found
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
935 """
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
936 if jid_ is None:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
937 jid_ = self.host.getClientHostJid(profile)
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
938 if profile in self.server_identities and jid_ in self.server_identities[profile]:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
939 return self.server_identities[profile][jid_].get((category, type_), set())
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
940 else:
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
941 return None
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
942
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
943 def getServerServiceEntity(self, category, type_, jid_=None, profile=None):
747
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
944 """Helper method to get first available entity of a server for the service (category, type_)
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
945 @param category: identity's category
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
946 @param type_: identitiy's type
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
947 @param jid_: the jid of the target server (None for profile's server)
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
948 @param profile: which profile is asking this server?
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
949 @return: the first found entity or None if no cached data were found
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
950 """
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
951 entities = self.getServerServiceEntities(category, type_, jid_, profile)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
952 if entities is None:
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
953 warning(_("Entities (%(category)s/%(type)s) of %(server)s not available, maybe they haven't been asked yet?")
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
954 % {"category": category, "type": type_, "server": jid_})
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
955 return None
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
956 else:
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
957 return list(entities)[0] if entities else None
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
958
747
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
959 def getAllServerIdentities(self, jid_, profile):
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
960 """Helper method to get all identities of a server
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
961 @param jid_: the jid of the target server (None for profile's server)
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
962 @param profile: which profile is asking this server?
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
963 @return: a set of entities or None if no cached data were found
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
964 """
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
965 if jid_ is None:
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
966 jid_ = self.host.getClientHostJid(profile)
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
967 if jid_ not in self.server_identities[profile]:
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
968 return None
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
969 entities = set()
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
970 for set_ in self.server_identities[profile][jid_].values():
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
971 entities.update(set_)
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
972 return entities
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
973
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
974 def hasServerFeature(self, feature, jid_=None, profile_key="@NONE@"):
747
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
975 """Tell if the specified server has the required feature
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
976 @param feature: requested feature
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
977 @param jid_: the jid of the target server (None for profile's server)
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
978 @param profile: which profile is asking this server?
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
979 """
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
980 profile = self.getProfileName(profile_key)
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
981 if not profile:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
982 error(_('Trying find server feature for a non-existant profile'))
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
983 return None
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
984 assert profile in self.server_features
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
985 if jid_ is None:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
986 jid_ = self.host.getClientHostJid(profile)
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
987 if jid_ in self.server_features[profile]:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
988 return feature in self.server_features[profile][jid_]
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
989 else:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
990 warning(_("Features of %s not available, maybe they haven't been asked yet?") % jid_)
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
991 return None
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
992
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
993 def getLastResource(self, contact, profile_key):
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
994 """Return the last resource used by a contact
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
995 @param contact: contact jid (unicode)
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
996 @param profile_key: %(doc_profile_key)s"""
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
997 profile = self.getProfileName(profile_key)
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
998 if not profile or not self.host.isConnected(profile):
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
999 error(_('Asking contacts for a non-existant or not connected profile'))
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1000 return ""
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1001 entity = jid.JID(contact).userhost()
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1002 if not entity in self.entitiesCache[profile]:
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1003 info(_("Entity not in cache"))
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
1004 return ""
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
1005 try:
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1006 return self.entitiesCache[profile][entity]["last_resource"]
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1007 except KeyError:
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
1008 return ""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1009
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
1010 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
1011 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
1012 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
1013 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
1014 return {}
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1015 entities_presence = {}
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1016 for entity in self.entitiesCache[profile]:
553
2b3e3349f6a4 core: fixed presence cache error
Goffi <goffi@goffi.org>
parents: 538
diff changeset
1017 if "presence" in self.entitiesCache[profile][entity]:
2b3e3349f6a4 core: fixed presence cache error
Goffi <goffi@goffi.org>
parents: 538
diff changeset
1018 entities_presence[entity] = self.entitiesCache[profile][entity]["presence"]
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1019
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1020 debug("Memory getPresenceStatus (%s)", entities_presence)
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1021 return entities_presence
0
goffi@necton2
parents:
diff changeset
1022
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1023 def setPresenceStatus(self, entity_jid, show, priority, statuses, profile_key):
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1024 """Change the presence status of an entity"""
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
1025 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
1026 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
1027 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
1028 return
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1029 entity_data = self.entitiesCache[profile].setdefault(entity_jid.userhost(), {})
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1030 resource = jid.parse(entity_jid.full())[2] or ''
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
1031 if resource:
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1032 entity_data["last_resource"] = resource
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1033 if not "last_resource" in entity_data:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1034 entity_data["last_resource"] = ''
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1035
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1036 entity_data.setdefault("presence", {})[resource] = (show, priority, statuses)
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1037
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1038 def updateEntityData(self, entity_jid, key, value, profile_key):
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1039 """Set a misc data for an entity
635
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1040 @param entity_jid: JID of the entity, or '@ALL@' to update all entities)
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1041 @param key: key to set (eg: "type")
635
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1042 @param value: value for this key (eg: "chatroom"), or '@NONE@' to delete
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1043 @param profile_key: %(doc_profile_key)s
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1044 """
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1045 profile = self.getProfileName(profile_key)
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1046 if not profile:
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
1047 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile'))
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1048 if not profile in self.entitiesCache:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1049 raise exceptions.ProfileNotInCacheError
635
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1050 if entity_jid == "@ALL@":
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1051 entities_map = self.entitiesCache[profile]
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1052 else:
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1053 entity = entity_jid.userhost()
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1054 self.entitiesCache[profile].setdefault(entity, {})
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1055 entities_map = {entity: self.entitiesCache[profile][entity]}
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1056 for entity in entities_map:
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1057 entity_map = entities_map[entity]
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1058 if value == "@NONE@" and key in entity_map:
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1059 del entity_map[key]
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1060 else:
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1061 entity_map[key] = value
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1062 if isinstance(value, basestring):
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
1063 self.host.bridge.entityDataUpdated(entity, key, value, profile)
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
1064
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1065 def getEntityData(self, entity_jid, keys_list, profile_key):
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1066 """Get a list of cached values for entity
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1067 @param entity_jid: JID of the entity
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1068 @param keys_list: list of keys to get, empty list for everything
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1069 @param profile_key: %(doc_profile_key)s
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1070 @return: dict withs values for each key in keys_list.
504
65ecbb473cbb core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents: 494
diff changeset
1071 if there is no value of a given key, resulting dict will
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1072 have nothing with that key nether
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1073 @raise: exceptions.UnknownEntityError if entity is not in cache
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1074 exceptions.ProfileNotInCacheError if profile is not in cache
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1075 """
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1076 profile = self.getProfileName(profile_key)
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1077 if not profile:
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
1078 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile'))
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1079 if not profile in self.entitiesCache:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1080 raise exceptions.ProfileNotInCacheError
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1081 if not entity_jid.userhost() in self.entitiesCache[profile]:
620
64db6758d223 core: more explicit UnknownEntityError
Goffi <goffi@goffi.org>
parents: 611
diff changeset
1082 raise exceptions.UnknownEntityError(entity_jid.userhost())
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1083 entity_data = self.entitiesCache[profile][entity_jid.userhost()]
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1084 if not keys_list:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1085 return entity_data
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1086 ret = {}
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1087 for key in keys_list:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1088 if key in entity_data:
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1089 ret[key] = entity_data[key]
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1090 return ret
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
1091
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1092 def delEntityCache(self, entity_jid, profile_key):
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1093 """Remove cached data for entity
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1094 @param entity_jid: JID of the entity
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1095 """
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1096 profile = self.getProfileName(profile_key)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1097 try:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1098 del self.entitiesCache[profile][entity_jid.userhost()]
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1099 except KeyError:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1100 pass
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
1101
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1102 def addWaitingSub(self, type_, entity_jid, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
1103 """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
1104 profile = self.getProfileName(profile_key)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1105 assert profile
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1106 if profile not in self.subscriptions:
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
1107 self.subscriptions[profile] = {}
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1108 self.subscriptions[profile][entity_jid] = type_
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1109
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1110 def delWaitingSub(self, entity_jid, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
1111 """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
1112 profile = self.getProfileName(profile_key)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1113 assert profile
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1114 if profile in self.subscriptions and entity_jid in self.subscriptions[profile]:
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1115 del self.subscriptions[profile][entity_jid]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1116
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
1117 def getWaitingSub(self, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
1118 """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
1119 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
1120 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
1121 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
1122 return {}
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1123 if profile not in self.subscriptions:
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
1124 return {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1125
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
1126 return self.subscriptions[profile]
0
goffi@necton2
parents:
diff changeset
1127
639
99eee75ec1b7 core: better handling of profile_key and don't write the param file anymore
souliane <souliane@mailoo.org>
parents: 635
diff changeset
1128 def getStringParamA(self, name, category, attr="value", profile_key='@NONE@'):
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
1129 return self.params.getStringParamA(name, category, attr, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1130
639
99eee75ec1b7 core: better handling of profile_key and don't write the param file anymore
souliane <souliane@mailoo.org>
parents: 635
diff changeset
1131 def getParamA(self, name, category, attr="value", profile_key='@NONE@'):
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
1132 return self.params.getParamA(name, category, attr, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1133
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
1134 def asyncGetParamA(self, name, category, attr="value", security_limit=NO_SECURITY_LIMIT, profile_key='@NONE@'):
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
1135 return self.params.asyncGetParamA(name, category, attr, security_limit, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1136
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
1137 def asyncGetStringParamA(self, name, category, attr="value", security_limit=NO_SECURITY_LIMIT, profile_key='@NONE@'):
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
1138 return self.params.asyncGetStringParamA(name, category, attr, security_limit, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1139
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
1140 def getParamsUI(self, security_limit=NO_SECURITY_LIMIT, app='', profile_key='@NONE@'):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
1141 return self.params.getParamsUI(security_limit, app, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1142
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
1143 def getParams(self, security_limit=NO_SECURITY_LIMIT, app='', profile_key='@NONE@'):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
1144 return self.params.getParams(security_limit, app, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1145
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
1146 def getParamsForCategory(self, category, security_limit=NO_SECURITY_LIMIT, app='', profile_key='@NONE@'):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
1147 return self.params.getParamsForCategory(category, security_limit, app, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1148
0
goffi@necton2
parents:
diff changeset
1149 def getParamsCategories(self):
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
1150 return self.params.getParamsCategories()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1151
642
e07a03d52321 core: fix for methods signature
souliane <souliane@mailoo.org>
parents: 641
diff changeset
1152 def setParam(self, name, value, category, security_limit=NO_SECURITY_LIMIT, profile_key='@NONE@'):
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 639
diff changeset
1153 return self.params.setParam(name, value, category, security_limit, profile_key)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1154
662
4f747d7fde8c core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents: 656
diff changeset
1155 def updateParams(self, xml):
4f747d7fde8c core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents: 656
diff changeset
1156 return self.params.updateParams(xml)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
1157
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
1158 def paramsRegisterApp(self, xml, security_limit=NO_SECURITY_LIMIT, app=''):
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
1159 return self.params.paramsRegisterApp(xml, security_limit, app)
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
1160
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
1161 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
1162 return self.params.setDefault(name, category, callback, errback)