annotate src/memory/memory.py @ 923:e77948faaef3

core: removed default_config: - constants in core.default_config moved to core.constants - removed unused host.getConst and host.setConst - APP_NAME* used where it make sense
author Goffi <goffi@goffi.org>
date Sat, 22 Mar 2014 17:48:10 +0100
parents ed9841e6d84a
children cbf4122baae7
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
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
20 from sat.core.i18n import _
0
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22 import os.path
729
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
23 import csv
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
24 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
25 from uuid import uuid4
326
0f9925193586 core, plugin mblog: fixed some exceptions
Goffi <goffi@goffi.org>
parents: 318
diff changeset
26 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
27 from twisted.internet import defer, reactor
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
28 from twisted.words.protocols.jabber import jid
914
1a3ba959f0ab core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents: 909
diff changeset
29 from sat.core import exceptions
1a3ba959f0ab core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents: 909
diff changeset
30 from sat.core.constants import Const as C
432
31e8c48b5f5d core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents: 428
diff changeset
31 from sat.memory.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
32 from sat.memory.persistent import PersistentDict
914
1a3ba959f0ab core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents: 909
diff changeset
33 from sat.memory.params import Params
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
34
679
59c9a7ff903d wix, misc: use picture of dimension 32x32 for tray icon + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 677
diff changeset
35
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
36 class Sessions(object):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
37 DEFAULT_TIMEOUT = 600
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
38
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
39 def __init__(self, timeout = None):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
40 """
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
41 @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
42 """
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
43 self._sessions = dict()
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
44 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
45
757
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
46 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
47 """ Create a new session
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
48 @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
49 @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
50 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
51 @return: session_id, session_data
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
52 """
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
53 session_id = str(uuid4())
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
54 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
55 if session_data is None:
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
56 session_data = {}
757
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
57 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
58 return session_id, session_data
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
59
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
60 def _purgeSession(self, session_id):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
61 del self._sessions[session_id]
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
62 debug("Session [%s] purged" % session_id)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
63
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
64 def __len__(self):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
65 return len(self._sessions)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
66
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
67 def __contains__(self, session_id):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
68 return session_id in self._sessions
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
69
757
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
70 def profileGet(self, session_id, profile):
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
71 try:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
72 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
73 except ValueError:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
74 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
75 if profile_set != profile:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
76 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
77 timer.reset(self.timeout)
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
78 return session_data
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
79
756
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
80 def __getitem__(self, session_id):
757
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
81 try:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
82 timer, session_data = self._sessions[session_id]
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
83 except ValueError:
bbe55c7bee43 core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents: 756
diff changeset
84 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
85 timer.reset(self.timeout)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
86 return session_data
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
87
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
88 def __setitem__(self, key, value):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
89 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
90
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
91 def __delitem__(self, session_id):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
92 """ 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
93 try:
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
94 timer = self._sessions[session_id][0]
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
95 timer.cancel()
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
96 self._purgeSession(session_id)
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
97 except KeyError:
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
98 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
99
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
100 def keys(self):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
101 return self._sessions.keys()
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
102
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
103 def iterkeys(self):
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
104 return self._sessions.iterkeys()
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
105
efa0e0f57950 core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents: 751
diff changeset
106
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
107 class Memory(object):
0
goffi@necton2
parents:
diff changeset
108 """This class manage all persistent informations"""
goffi@necton2
parents:
diff changeset
109
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
110 def __init__(self, host):
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
111 info(_("Memory manager init"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
112 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
113 self.host = host
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
114 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
115 # /!\ 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
116 self.subscriptions = {}
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
117 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
118 self.server_identities = {}
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
119 self.config = self.parseMainConf()
923
e77948faaef3 core: removed default_config:
Goffi <goffi@goffi.org>
parents: 919
diff changeset
120 database_file = os.path.expanduser(os.path.join(self.getConfig('', 'local_dir'), C.SAVEFILE_DATABASE))
853
c2f6ada7858f core (sqlite): automatic database update:
Goffi <goffi@goffi.org>
parents: 844
diff changeset
121 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
122 PersistentDict.storage = self.storage
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
123 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
124 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
125 self.params.load_default_params()
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
126 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
127 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
128 d.addCallback(lambda ignore: self.memory_data.load())
428
a4a9efadabfc core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents: 425
diff changeset
129 d.chainDeferred(self.initialized)
0
goffi@necton2
parents:
diff changeset
130
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
131 def parseMainConf(self):
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
132 """look for main .ini configuration file, and parse it"""
923
e77948faaef3 core: removed default_config:
Goffi <goffi@goffi.org>
parents: 919
diff changeset
133 _config = SafeConfigParser(defaults=C.DEFAULT_CONFIG)
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
134 try:
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 365
diff changeset
135 _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
136 except:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
137 error(_("Can't read main config !"))
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
138
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
139 return _config
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
140
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
141 def getConfig(self, section, name):
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
142 """Get the main configuration option
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
143 @param section: section of the config file (None or '' for DEFAULT)
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
144 @param name: name of the option
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
145 """
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
146 if not section:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
147 section = 'DEFAULT'
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
148 try:
729
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
149 value = self.config.get(section, name)
483
655695f85e5b core: fixed bad try/except block in memory
Goffi <goffi@goffi.org>
parents: 480
diff changeset
150 except (NoOptionError, NoSectionError):
729
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
151 value = ''
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
152
729
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
153 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
154 value = os.path.expanduser(value)
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
155 # 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
156 elif name.endswith('_list'):
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
157 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
158 elif name.endswith('_dict'):
8f50a0079769 core: management of _list and _dict in sat.conf
Goffi <goffi@goffi.org>
parents: 728
diff changeset
159 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
160 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
161 return value
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 346
diff changeset
162
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
163 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
164 """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
165 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
166 return False
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
167 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
168 if os.path.exists(filename):
0
goffi@necton2
parents:
diff changeset
169 try:
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
170 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
171 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
172 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
173 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
174 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
175 return False
0
goffi@necton2
parents:
diff changeset
176
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
177 def load(self):
428
a4a9efadabfc core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents: 425
diff changeset
178 """Load parameters and all memory things from db"""
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
179 #parameters data
428
a4a9efadabfc core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents: 425
diff changeset
180 return self.params.loadGenParams()
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
181
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
182 def loadIndividualParams(self, profile):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
183 """Load individual parameters for a profile
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
184 @param profile: %(doc_profile)s"""
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
185 return self.params.loadIndParams(profile)
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
186
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
187 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
188 """"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
189 @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
190 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
191 self.entitiesCache[profile] = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
192
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
193 def purgeProfileSession(self, profile):
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
194 """Delete cache of data of profile
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
195 @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
196 info(_("[%s] Profile session purge" % profile))
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
197 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
198 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
199 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
200 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
201 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
202
677
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
203 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
204 """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
205 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
206 return False
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
207 #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
208 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
209 try:
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
210 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
211 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
212 return True
9a50aa7feefb core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents: 669
diff changeset
213 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
214 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
215 return False
0
goffi@necton2
parents:
diff changeset
216
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
217 def getProfilesList(self):
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
218 return self.storage.getProfilesList()
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
219
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 722
diff changeset
220 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
221 """Return name of profile from keyword
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
222 @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
223 @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
224 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
225
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
226 def asyncCreateProfile(self, name):
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
227 """Create a new profile
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
228 @param name: Profile name
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 418
diff changeset
229 """
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
230 return self.params.asyncCreateProfile(name)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
231
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
232 def asyncDeleteProfile(self, name, force=False):
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
233 """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
234 @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
235 @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
236 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
237 @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
238 """
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
239 return self.params.asyncDeleteProfile(name, force)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
240
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
241 def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile=C.PROF_KEY_NONE):
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
242 assert profile != C.PROF_KEY_NONE
669
ffb716804580 core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents: 662
diff changeset
243 if extra is None:
ffb716804580 core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents: 662
diff changeset
244 extra = {}
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
245 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
0
goffi@necton2
parents:
diff changeset
246
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
247 def getHistory(self, from_jid, to_jid, limit=0, between=True, profile=C.PROF_KEY_NONE):
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
248 assert profile != C.PROF_KEY_NONE
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
249 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
0
goffi@necton2
parents:
diff changeset
250
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
251 def addServerFeature(self, feature, jid_, profile):
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
252 """Add a feature discovered from server
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
253 @param feature: string of the feature
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
254 @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
255 @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
256 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
257 self.server_features[profile] = {}
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
258 features = self.server_features[profile].setdefault(jid_, [])
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
259 features.append(feature)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
260
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
261 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
262 """Add an identity discovered from server
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
263 @param feature: string of the feature
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
264 @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
265 @param profile: which profile asked this server?"""
566
9faccd827657 core: sqlite storage constraint fix
Goffi <goffi@goffi.org>
parents: 557
diff changeset
266 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
267 self.server_identities[profile] = {}
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
268 identities = self.server_identities[profile].setdefault(jid_, {})
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
269 if (category, type_) not in identities:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
270 identities[(category, type_)] = set()
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
271 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
272
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
273 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
274 """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
275 @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
276 @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
277 @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
278 @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
279 @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
280 """
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
281 if jid_ is None:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
282 jid_ = self.host.getClientHostJid(profile)
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
283 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
284 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
285 else:
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
286 return None
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
287
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
288 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
289 """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
290 @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
291 @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
292 @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
293 @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
294 @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
295 """
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
296 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
297 if entities is None:
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
298 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
299 % {"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
300 return None
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
301 else:
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
302 return list(entities)[0] if entities else None
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
303
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
304 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
305 """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
306 @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
307 @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
308 @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
309 """
5aff0beddb28 core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents: 742
diff changeset
310 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
311 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
312 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
313 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
314 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
315 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
316 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
317 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
318
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
319 def hasServerFeature(self, feature, jid_=None, profile_key=C.PROF_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
320 """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
321 @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
322 @param jid_: the jid of the target server (None for profile's server)
909
fab49a1d5ea2 core: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 894
diff changeset
323 @param profile_key: %(doc_profile_key)s
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
324 """
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
325 profile = self.getProfileName(profile_key)
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
326 if not profile:
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
327 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
328 return None
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
329 assert profile in self.server_features
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
330 if jid_ is None:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
331 jid_ = self.host.getClientHostJid(profile)
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
332 if jid_ in self.server_features[profile]:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
333 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
334 else:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 729
diff changeset
335 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
336 return None
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
337
919
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
338 def _getLastResource(self, jid_s, profile_key):
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
339 jid_ = jid.JID(jid_s)
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
340 return self.getLastResource(jid_, profile_key)
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
341
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
342
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
343 def getLastResource(self, jid_, profile_key):
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
344 """Return the last resource used by a jid_
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
345 @param jid_: bare jid
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
346 @param profile_key: %(doc_profile_key)s"""
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
347 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
348 if not profile or not self.host.isConnected(profile):
919
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
349 error(_('Asking jid_s for a non-existant or not connected 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
350 return ""
919
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 916
diff changeset
351 entity = jid_.userhost()
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
352 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
353 info(_("Entity not in cache"))
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
354 return ""
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
355 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
356 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
357 except KeyError:
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
358 return ""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
359
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
360 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
361 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
362 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
363 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
364 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
365 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
366 for entity in self.entitiesCache[profile]:
553
2b3e3349f6a4 core: fixed presence cache error
Goffi <goffi@goffi.org>
parents: 538
diff changeset
367 if "presence" in self.entitiesCache[profile][entity]:
2b3e3349f6a4 core: fixed presence cache error
Goffi <goffi@goffi.org>
parents: 538
diff changeset
368 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
369
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
370 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
371 return entities_presence
0
goffi@necton2
parents:
diff changeset
372
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
373 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
374 """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
375 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
376 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
377 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
378 return
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
379 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
380 resource = jid.parse(entity_jid.full())[2] or ''
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
381 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
382 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
383 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
384 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
385
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
386 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
387
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
388 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
389 """Set a misc data for an entity
635
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
390 @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
391 @param key: key to set (eg: "type")
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
392 @param value: value for this key (eg: "chatroom"), or C.PROF_KEY_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
393 @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
394 """
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
395 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
396 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
397 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
398 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
399 raise exceptions.ProfileNotInCacheError
635
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
400 if entity_jid == "@ALL@":
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
401 entities_map = self.entitiesCache[profile]
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
402 else:
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
403 entity = entity_jid.userhost()
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
404 self.entitiesCache[profile].setdefault(entity, {})
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
405 entities_map = {entity: self.entitiesCache[profile][entity]}
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
406 for entity in entities_map:
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
407 entity_map = entities_map[entity]
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
408 if value == C.PROF_KEY_NONE and key in entity_map:
635
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
409 del entity_map[key]
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
410 else:
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
411 entity_map[key] = value
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
412 if isinstance(value, basestring):
eff8772fd472 core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents: 634
diff changeset
413 self.host.bridge.entityDataUpdated(entity, key, value, profile)
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 398
diff changeset
414
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
415 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
416 """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
417 @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
418 @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
419 @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
420 @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
421 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
422 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
423 @raise: exceptions.UnknownEntityError if entity is not in cache
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
424 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
425 """
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
426 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
427 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
428 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
429 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
430 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
431 if not entity_jid.userhost() in self.entitiesCache[profile]:
620
64db6758d223 core: more explicit UnknownEntityError
Goffi <goffi@goffi.org>
parents: 611
diff changeset
432 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
433 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
434 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
435 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
436 ret = {}
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
437 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
438 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
439 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
440 return ret
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
441
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
442 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
443 """Remove cached data for entity
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
444 @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
445 """
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
446 profile = self.getProfileName(profile_key)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
447 try:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
448 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
449 except KeyError:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
450 pass
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
451
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
452 def addWaitingSub(self, type_, entity_jid, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
453 """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
454 profile = self.getProfileName(profile_key)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
455 assert profile
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
456 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
457 self.subscriptions[profile] = {}
722
04aabc3f2684 core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents: 679
diff changeset
458 self.subscriptions[profile][entity_jid] = type_
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
459
486
0d9908ac775e core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents: 484
diff changeset
460 def delWaitingSub(self, entity_jid, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
461 """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
462 profile = self.getProfileName(profile_key)
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
463 assert profile
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
464 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
465 del self.subscriptions[profile][entity_jid]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
466
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
467 def getWaitingSub(self, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
468 """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
469 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
470 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
471 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
472 return {}
592
e5a875a3311b Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
473 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
474 return {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
475
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
476 return self.subscriptions[profile]
0
goffi@necton2
parents:
diff changeset
477
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
478 def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE):
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 512
diff changeset
479 return self.params.getStringParamA(name, category, attr, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
480
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
481 def getParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE):
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
482 return self.params.getParamA(name, category, attr, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
483
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
484 def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
485 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
486
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
487 def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
656
7d6e5807504a bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents: 645
diff changeset
488 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
489
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
490 def getParamsUI(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE):
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
491 return self.params.getParamsUI(security_limit, app, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
492
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
493 def getParams(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE):
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
494 return self.params.getParams(security_limit, app, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
495
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
496 def getParamsForCategory(self, category, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE):
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
497 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
498
0
goffi@necton2
parents:
diff changeset
499 def getParamsCategories(self):
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
500 return self.params.getParamsCategories()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
501
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
502 def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 639
diff changeset
503 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
504
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
505 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
506 return self.params.updateParams(xml)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
507
914
1a3ba959f0ab core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents: 909
diff changeset
508 def paramsRegisterApp(self, xml, security_limit=C.NO_SECURITY_LIMIT, app=''):
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 771
diff changeset
509 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
510
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
511 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
512 return self.params.setDefault(name, category, callback, errback)