annotate tools/memory.py @ 47:9aa2d9dd4045

memory methods improvement - new method to save private data (mainly useful for plugins) - contacts/presence management refactored - new independant methods to manage subscription
author Goffi <goffi@goffi.org>
date Wed, 06 Jan 2010 23:49:55 +1100
parents d24629c631fc
children a5b5fb5fc9fd
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
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 SAT: a jabber client
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22 from __future__ import with_statement
goffi@necton2
parents:
diff changeset
23
goffi@necton2
parents:
diff changeset
24 import os.path
goffi@necton2
parents:
diff changeset
25 import time
goffi@necton2
parents:
diff changeset
26 import pickle
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
27 from xml.dom import minidom
0
goffi@necton2
parents:
diff changeset
28 from logging import debug, info, error
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
29 import pdb
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
30 from twisted.internet import defer
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
31 from twisted.words.protocols.jabber import jid
0
goffi@necton2
parents:
diff changeset
32
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
33 SAVEFILE_PARAM="/param"
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
34 SAVEFILE_HISTORY="/history"
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
35 SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins)
0
goffi@necton2
parents:
diff changeset
36
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
37 class Param():
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
38 """This class manage parameter with xml"""
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
39 ### TODO: add desciption in params
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
40
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
41 #TODO: mettre Watched dans un plugin
34
a544b376b6f0 use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents: 22
diff changeset
42 default_xml = u"""
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
43 <params>
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
44 <category name="Connection">
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
45 <param name="JabberID" value="goffi@necton2.int/TestScript" type="string" />
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
46 <param name="Password" value="toto" type="password" />
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
47 <param name="Server" value="necton2.int" type="string" />
21
633c5ed65701 parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents: 20
diff changeset
48 <param name="NewAccount" value="Register new account" type="button" callback="registerNewAccount"/>
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
49 </category>
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
50 <category name="Misc">
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
51 <param name="Watched" value="test@Jabber.goffi.int" type="string" />
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
52 </category>
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
53 </params>
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
54 """
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
55
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
56 def load_default_params(self):
34
a544b376b6f0 use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents: 22
diff changeset
57 self.dom = minidom.parseString(Param.default_xml.encode('utf-8'))
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
58
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
59 def load(self, file):
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
60 """Load parameters from file"""
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
61 self.dom = minidom.parse(file)
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
62
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
63 def save(self, file):
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
64 """Save parameters to xml file"""
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
65 with open(file, 'wb') as xml_file:
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
66 self.dom.writexml(xml_file)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
67
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
68 def __init__(self, host):
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
69 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
70 self.host = host
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
71 host.set_const('savefile_param', SAVEFILE_PARAM)
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
72 host.set_const('savefile_history', SAVEFILE_HISTORY)
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
73 host.set_const('savefile_private', SAVEFILE_PRIVATE)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
74 host.registerGeneralCB("registerNewAccount", host.registerNewAccountCB)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
75
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
76 def __get_unique_node(self, parent, tag, name):
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
77 """return node with given tag, create a new one if the node doesn't exist
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
78 @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
79 @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
80 @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
81 @return: node if it exist or None
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
82 """
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
83 for node in parent.childNodes:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
84 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
85 #the node already exists
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
86 return node
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
87 #the node is new
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
88 return None
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
89
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
90 def importParams(self, xml):
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
91 """import xml in parameters, do nothing if the param already exist
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
92 @param xml: parameters in xml form"""
34
a544b376b6f0 use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents: 22
diff changeset
93 src_dom = minidom.parseString(xml.encode('utf-8'))
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
94
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
95 def import_node(tgt_parent, src_parent):
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
96 for child in src_parent.childNodes:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
97 if child.nodeName == '#text':
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
98 continue
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
99 node = self.__get_unique_node(tgt_parent, child.nodeName, child.getAttribute("name"))
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
100 if not node: #The node is new
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
101 tgt_parent.appendChild(child)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
102 else:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
103 import_node(node, child)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
104
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
105 import_node(self.dom.documentElement, src_dom.documentElement)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
106
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
107 def __default_ok(self, value, name, category):
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
108 self.setParam(name, value, category)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
109
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
110 def __default_ko(self, failure, name, category):
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
111 error ("Can't determine default value for [%s/%s]: %s" % (category, name, str(failure.value)))
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
112
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
113 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
114 """Set default value of parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
115 '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
116 @param name: name of the parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
117 @param category: category of the parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
118 @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
119 @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
120 """
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
121 #TODO: send signal param update if value changed
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
122 node = self.__getParamNode(name, category)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
123 if not node:
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
124 error("Requested param [%s] in category [%s] doesn't exist !" , name, category)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
125 return
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
126 if node.getAttribute('default_cb') == 'yes':
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
127 del node.attributes['default_cb']
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
128 d = defer.maybeDeferred(callback)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
129 d.addCallback(self.__default_ok, name, category)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
130 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
131
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
132 def getParamA(self, name, category, attr="value"):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
133 """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
134 @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
135 @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
136 @param attr: name of the attribute (default: "value")
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
137
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
138 @return: attribute"""
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
139 node = self.__getParamNode(name, category)
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
140 if not node:
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
141 error("Requested param [%s] in category [%s] doesn't exist !" , name, category)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
142 return 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
143 return node.getAttribute(attr)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
144
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
145 def getParams(self):
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
146 """Return the whole params XML"""
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
147 return self.dom.toxml()
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
148
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
149 def getParamsForCategory(self, category):
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
150 """Return node's xml for selected category"""
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
151 for node in self.dom.documentElement.childNodes:
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
152 if node.nodeName == "category" and node.getAttribute("name") == category:
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
153 return node.toxml()
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
154 return "<category />"
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
155
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
156 def __getParamNode(self, name, category):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
157 for node in self.dom.documentElement.childNodes:
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
158 if node.nodeName == "category" and node.getAttribute("name") == category:
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
159 params = node.getElementsByTagName("param")
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
160 for param in params:
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
161 if param.getAttribute("name") == name:
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
162 return param
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
163 return None
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
164
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
165 def getParamsCategories(self):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
166 """return the categories availables"""
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
167 categories=[]
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
168 for cat in self.dom.getElementsByTagName("category"):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
169 categories.append(cat.getAttribute("name"))
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
170 return categories
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
171
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
172 def setParam(self, name, value, category):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
173 node = self.__getParamNode(name, category)
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
174 if not node:
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
175 return #TODO: throw an error
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
176 type = node.getAttribute("type")
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
177 if type=="button":
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
178 print "clique",node.toxml()
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
179 else:
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
180 node.setAttribute("value", value)
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
181 self.host.bridge.paramUpdate(name, value, category)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
182
0
goffi@necton2
parents:
diff changeset
183 class Memory:
goffi@necton2
parents:
diff changeset
184 """This class manage all persistent informations"""
goffi@necton2
parents:
diff changeset
185
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
186 def __init__(self, host):
0
goffi@necton2
parents:
diff changeset
187 info ("Memory manager init")
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
188 self.host = host
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
189 self.contacts={}
0
goffi@necton2
parents:
diff changeset
190 self.presenceStatus={}
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
191 self.subscriptions={}
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
192 self.params=Param(host)
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
193 self.history={} #used to store chat history (key: short jid)
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
194 self.private={} #used to store private value
0
goffi@necton2
parents:
diff changeset
195 self.disco={} #XXX: maybe best in a separate class
goffi@necton2
parents:
diff changeset
196 self.features={}
goffi@necton2
parents:
diff changeset
197 self.load()
goffi@necton2
parents:
diff changeset
198
goffi@necton2
parents:
diff changeset
199 def load(self):
goffi@necton2
parents:
diff changeset
200 """Load parameters and all memory things from file/db"""
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
201 param_file = os.path.expanduser(self.host.get_const('local_dir')+
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
202 self.host.get_const('savefile_param'))
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
203 history_file = os.path.expanduser(self.host.get_const('local_dir')+
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
204 self.host.get_const('savefile_history'))
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
205 private_file = os.path.expanduser(self.host.get_const('local_dir')+
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
206 self.host.get_const('savefile_private'))
0
goffi@necton2
parents:
diff changeset
207
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
208 #parameters
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
209 if os.path.exists(param_file):
0
goffi@necton2
parents:
diff changeset
210 try:
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
211 self.params.load(param_file)
0
goffi@necton2
parents:
diff changeset
212 debug("params loaded")
goffi@necton2
parents:
diff changeset
213 except:
goffi@necton2
parents:
diff changeset
214 error ("Can't load params !")
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
215 self.params.load_default_params()
0
goffi@necton2
parents:
diff changeset
216 else:
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
217 error ("No params, using default parameters")
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
218 self.params.load_default_params()
0
goffi@necton2
parents:
diff changeset
219
goffi@necton2
parents:
diff changeset
220 #history
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
221 if os.path.exists(history_file):
0
goffi@necton2
parents:
diff changeset
222 try:
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
223 with open(history_file, 'r') as history_pickle:
0
goffi@necton2
parents:
diff changeset
224 self.history=pickle.load(history_pickle)
goffi@necton2
parents:
diff changeset
225 debug("history loaded")
goffi@necton2
parents:
diff changeset
226 except:
goffi@necton2
parents:
diff changeset
227 error ("Can't load history !")
goffi@necton2
parents:
diff changeset
228
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
229 #private
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
230 if os.path.exists(private_file):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
231 try:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
232 with open(private_file, 'r') as private_pickle:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
233 self.private=pickle.load(private_pickle)
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
234 debug("private values loaded")
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
235 except:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
236 error ("Can't load private values !")
0
goffi@necton2
parents:
diff changeset
237
goffi@necton2
parents:
diff changeset
238 def save(self):
goffi@necton2
parents:
diff changeset
239 """Save parameters and all memory things to file/db"""
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
240 #TODO: need to encrypt files (at least passwords !) and set permissions
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
241 param_file = os.path.expanduser(self.host.get_const('local_dir')+
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
242 self.host.get_const('savefile_param'))
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
243 history_file = os.path.expanduser(self.host.get_const('local_dir')+
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
244 self.host.get_const('savefile_history'))
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
245 private_file = os.path.expanduser(self.host.get_const('local_dir')+
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
246 self.host.get_const('savefile_private'))
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
247
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
248 self.params.save(param_file)
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
249 debug("params saved")
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
250 with open(history_file, 'w') as history_pickle:
0
goffi@necton2
parents:
diff changeset
251 pickle.dump(self.history, history_pickle)
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
252 debug("history saved")
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
253 with open(private_file, 'w') as private_pickle:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
254 pickle.dump(self.private, private_pickle)
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
255 debug("private values saved")
0
goffi@necton2
parents:
diff changeset
256
goffi@necton2
parents:
diff changeset
257 def addToHistory(self, me_jid, from_jid, to_jid, type, message):
goffi@necton2
parents:
diff changeset
258 me_short=me_jid.userhost()
goffi@necton2
parents:
diff changeset
259 from_short=from_jid.userhost()
goffi@necton2
parents:
diff changeset
260 to_short=to_jid.userhost()
goffi@necton2
parents:
diff changeset
261
goffi@necton2
parents:
diff changeset
262 if from_jid==me_jid:
goffi@necton2
parents:
diff changeset
263 key=to_short
goffi@necton2
parents:
diff changeset
264 else:
goffi@necton2
parents:
diff changeset
265 key=from_short
goffi@necton2
parents:
diff changeset
266
goffi@necton2
parents:
diff changeset
267 if not self.history.has_key(me_short):
goffi@necton2
parents:
diff changeset
268 self.history[me_short]={}
goffi@necton2
parents:
diff changeset
269 if not self.history[me_short].has_key(key):
goffi@necton2
parents:
diff changeset
270 self.history[me_short][key]={}
goffi@necton2
parents:
diff changeset
271
goffi@necton2
parents:
diff changeset
272 self.history[me_short][key][int(time.time())] = (from_short, message)
goffi@necton2
parents:
diff changeset
273
goffi@necton2
parents:
diff changeset
274 def getHistory(self, from_jid, to_jid, size):
goffi@necton2
parents:
diff changeset
275 ret={}
goffi@necton2
parents:
diff changeset
276 if not self.history.has_key(from_jid):
goffi@necton2
parents:
diff changeset
277 error("source JID not found !")
goffi@necton2
parents:
diff changeset
278 #TODO: throw an error here
goffi@necton2
parents:
diff changeset
279 return {}
goffi@necton2
parents:
diff changeset
280 if not self.history[from_jid].has_key(to_jid):
goffi@necton2
parents:
diff changeset
281 error("dest JID not found !")
goffi@necton2
parents:
diff changeset
282 #TODO: throw an error here
goffi@necton2
parents:
diff changeset
283 return {}
goffi@necton2
parents:
diff changeset
284 stamps=self.history[from_jid][to_jid].keys()
goffi@necton2
parents:
diff changeset
285 stamps.sort()
goffi@necton2
parents:
diff changeset
286 for stamp in stamps[-size:]:
goffi@necton2
parents:
diff changeset
287 ret[stamp]=self.history[from_jid][to_jid][stamp]
goffi@necton2
parents:
diff changeset
288
goffi@necton2
parents:
diff changeset
289 return ret
goffi@necton2
parents:
diff changeset
290
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
291 def setPrivate(self, key, value):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
292 """Save a misc private value (mainly useful for plugins)"""
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
293 self.private[key] = value
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
294
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
295 def getPrivate(self, key):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
296 """return a private value
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
297 @param key: name of wanted value
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
298 @return: value or None if value don't exist"""
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
299 if self.private.has_key(key):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
300 return self.private[key]
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
301 return None
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
302
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
303
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
304 def addContact(self, contact_jid, attributes, groups):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
305 debug("Memory addContact: %s",contact_jid.userhost())
0
goffi@necton2
parents:
diff changeset
306 assert(isinstance(attributes,dict))
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 0
diff changeset
307 assert(isinstance(groups,set))
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
308 self.contacts[contact_jid.userhost()]=[attributes, groups]
0
goffi@necton2
parents:
diff changeset
309
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
310 def delContact(self, contact_jid):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
311 debug("Memory delContact: %s",contact_jid.userhost())
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
312 if self.contacts.has_key(contact_jid.userhost()):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
313 del self.contacts[contact_jid.userhost()]
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
314
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
315 def getContact(self, contact_jid):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
316 if self.contacts.has_key(contact_jid.userhost()):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
317 self.contacts[contact_jid.userhost()]
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
318 else:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
319 return None
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
320
0
goffi@necton2
parents:
diff changeset
321 def getContacts(self):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
322 debug ("Memory getContact OK (%s)", self.contacts)
0
goffi@necton2
parents:
diff changeset
323 ret=[]
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
324 for contact in self.contacts:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
325 attr, groups = self.contacts[contact]
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
326 ret.append([contact, attr, groups ])
0
goffi@necton2
parents:
diff changeset
327 return ret
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
328
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
329 def addPresenceStatus(self, contact_jid, show, priority, statuses):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
330 if not self.presenceStatus.has_key(contact_jid.userhost()):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
331 self.presenceStatus[contact_jid.userhost()] = {}
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
332 resource = jid.parse(contact_jid.full())[2] or ''
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
333 self.presenceStatus[contact_jid.userhost()][resource] = (show, priority, statuses)
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
334
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
335 def addWaitingSub(self, type, contact_jid):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
336 """Called when a subcription request is received"""
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
337 self.subscriptions[contact_jid] = type
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
338
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
339 def delWaitingSub(self, contact_jid):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
340 """Called when a subcription request is finished"""
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
341 if self.subscriptions.has_key(contact_jid):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
342 del self.subscriptions[contact_jid]
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
343
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
344 def getWaitingSub(self):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
345 """Called to get a list of currently waiting subscription requests"""
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
346 return self.subscriptions
0
goffi@necton2
parents:
diff changeset
347
goffi@necton2
parents:
diff changeset
348 def getPresenceStatus(self):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
349 debug ("Memory getPresenceStatus (%s)", self.presenceStatus)
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
350 return self.presenceStatus
0
goffi@necton2
parents:
diff changeset
351
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
352 def getParamA(self, name, category, attr="value"):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
353 return self.params.getParamA(name, category, attr)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
354
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
355 def getParams(self):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
356 return self.params.getParams()
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
357
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
358 def getParamsForCategory(self, category):
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
359 return self.params.getParamsForCategory(category)
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
360
0
goffi@necton2
parents:
diff changeset
361 def getParamsCategories(self):
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
362 return self.params.getParamsCategories()
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
363
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
364 def setParam(self, name, value, category):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
365 return self.params.setParam(name, value, category)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
366
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
367 def importParams(self, xml):
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
368 return self.params.importParams(xml)
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
369
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
370 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
371 return self.params.setDefault(name, category, callback, errback)