comparison src/core/sat_main.py @ 412:62b17854254e

database integration: first draft - using SQLite as backend /!\ Not finished yet, break execution. SàT CAN'T LAUNCH PROPERLY IN THE CURRENT STATE
author Goffi <goffi@goffi.org>
date Sun, 30 Oct 2011 23:13:40 +0100
parents 3ed53803b3b3
children dd4caab17008
comparison
equal deleted inserted replaced
411:b109a79ac72f 412:62b17854254e
110 if not os.path.exists(local_dir): 110 if not os.path.exists(local_dir):
111 os.makedirs(local_dir) 111 os.makedirs(local_dir)
112 112
113 self.trigger = TriggerManager() #trigger are used to change SàT behaviour 113 self.trigger = TriggerManager() #trigger are used to change SàT behaviour
114 114
115
116 self.bridge=DBusBridge() 115 self.bridge=DBusBridge()
117 self.bridge.register("getVersion", lambda: self.get_const('client_version')) 116 self.bridge.register("getVersion", lambda: self.get_const('client_version'))
118 self.bridge.register("getProfileName", self.memory.getProfileName) 117 self.bridge.register("getProfileName", self.memory.getProfileName)
119 self.bridge.register("getProfilesList", self.memory.getProfilesList) 118 self.bridge.register("getProfilesList", self.memory.getProfilesList)
120 self.bridge.register("createProfile", self.memory.createProfile) 119 self.bridge.register("createProfile", self.memory.createProfile)
146 self.bridge.register("confirmationAnswer", self.confirmationAnswer) 145 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
147 self.bridge.register("getProgress", self.getProgress) 146 self.bridge.register("getProgress", self.getProgress)
148 self.bridge.register("getMenus", self.getMenus) 147 self.bridge.register("getMenus", self.getMenus)
149 self.bridge.register("getMenuHelp", self.getMenuHelp) 148 self.bridge.register("getMenuHelp", self.getMenuHelp)
150 self.bridge.register("callMenu", self.callMenu) 149 self.bridge.register("callMenu", self.callMenu)
151 150
151 self.memory.initialized.addCallback(self._postMemoryInit)
152
153 def _postMemoryInit(self, ignore):
154 """Method called after memory initialization is done"""
155 info(_("Memory initialised"))
152 self._import_plugins() 156 self._import_plugins()
153 157
154 158
155 def _import_plugins(self): 159 def _import_plugins(self):
156 """Import all plugins found in plugins directory""" 160 """Import all plugins found in plugins directory"""
157 import sat.plugins 161 import sat.plugins
158 plugins_path = os.path.dirname(sat.plugins.__file__) 162 plugins_path = os.path.dirname(sat.plugins.__file__)
159 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob (os.path.join(plugins_path,"plugin*.py")))] 163 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob(os.path.join(plugins_path,"plugin*.py")))]
160 __plugins_to_import = {} #plugins will still have to import 164 __plugins_to_import = {} #plugins we still have to import
161 for plug in plug_lst: 165 for plug in plug_lst:
162 plugin_path = 'sat.plugins.'+plug 166 plugin_path = 'sat.plugins.'+plug
163 __import__(plugin_path) 167 __import__(plugin_path)
164 mod = sys.modules[plugin_path] 168 mod = sys.modules[plugin_path]
165 plugin_info = mod.PLUGIN_INFO 169 plugin_info = mod.PLUGIN_INFO
213 if (self.isConnected(profile)): 217 if (self.isConnected(profile)):
214 info(_("already connected !")) 218 info(_("already connected !"))
215 if callback: 219 if callback:
216 callback() 220 callback()
217 return 221 return
218 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile, 222
219 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile), 223 def afterMemoryInit(ignore):
220 self.memory.getParamA("Password", "Connection", profile_key = profile), 224 """This part must be called when we have loaded individual parameters from memory"""
221 self.memory.getParamA("Server", "Connection", profile_key = profile), 5222) 225 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
222 226 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile),
223 if callback and errback: 227 self.memory.getParamA("Password", "Connection", profile_key = profile),
224 current.getConnectionDeferred().addCallbacks(lambda x:callback(), errback) 228 self.memory.getParamA("Server", "Connection", profile_key = profile), 5222)
225 229
226 current.messageProt = xmpp.SatMessageProtocol(self) 230 if callback and errback:
227 current.messageProt.setHandlerParent(current) 231 current.getConnectionDeferred().addCallbacks(lambda x:callback(), errback)
228 232
229 current.roster = xmpp.SatRosterProtocol(self) 233 current.messageProt = xmpp.SatMessageProtocol(self)
230 current.roster.setHandlerParent(current) 234 current.messageProt.setHandlerParent(current)
231 235
232 current.presence = xmpp.SatPresenceProtocol(self) 236 current.roster = xmpp.SatRosterProtocol(self)
233 current.presence.setHandlerParent(current) 237 current.roster.setHandlerParent(current)
234 238
235 current.fallBack = xmpp.SatFallbackHandler(self) 239 current.presence = xmpp.SatPresenceProtocol(self)
236 current.fallBack.setHandlerParent(current) 240 current.presence.setHandlerParent(current)
237 241
238 current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'), 242 current.fallBack = xmpp.SatFallbackHandler(self)
239 self.get_const('client_version')) 243 current.fallBack.setHandlerParent(current)
240 current.versionHandler.setHandlerParent(current) 244
241 245 current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'),
242 debug (_("setting plugins parents")) 246 self.get_const('client_version'))
243 247 current.versionHandler.setHandlerParent(current)
244 for plugin in self.plugins.iteritems(): 248
245 if plugin[1].is_handler: 249 debug (_("setting plugins parents"))
246 plugin[1].getHandler(profile).setHandlerParent(current) 250
247 251 for plugin in self.plugins.iteritems():
248 current.startService() 252 if plugin[1].is_handler:
253 plugin[1].getHandler(profile).setHandlerParent(current)
254
255 current.startService()
256
257 params_defer = self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit)
258 if errback:
259 params_defer.addErrback(errback)
249 260
250 def disconnect(self, profile_key): 261 def disconnect(self, profile_key):
251 """disconnect from jabber server""" 262 """disconnect from jabber server"""
252 if (not self.isConnected(profile_key)): 263 if (not self.isConnected(profile_key)):
253 info(_("not connected !")) 264 info(_("not connected !"))