Mercurial > libervia-backend
comparison src/core/sat_main.py @ 1409:3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 16 Apr 2015 14:57:57 +0200 |
parents | 069ad98b360d |
children | 176de79c8c39 |
comparison
equal
deleted
inserted
replaced
1408:8a7145138330 | 1409:3265a2639182 |
---|---|
160 for plug in plug_lst: | 160 for plug in plug_lst: |
161 plugin_path = 'sat.plugins.' + plug | 161 plugin_path = 'sat.plugins.' + plug |
162 try: | 162 try: |
163 __import__(plugin_path) | 163 __import__(plugin_path) |
164 except ImportError as e: | 164 except ImportError as e: |
165 log.error(_("Can't import plugin [%(path)s]: %(error)s") % {'path': plugin_path, 'error':e}) | 165 log.error(_(u"Can't import plugin [%(path)s]: %(error)s") % {'path': plugin_path, 'error':e}) |
166 continue | 166 continue |
167 mod = sys.modules[plugin_path] | 167 mod = sys.modules[plugin_path] |
168 plugin_info = mod.PLUGIN_INFO | 168 plugin_info = mod.PLUGIN_INFO |
169 __plugins_to_import[plugin_info['import_name']] = (plugin_path, mod, plugin_info) | 169 __plugins_to_import[plugin_info['import_name']] = (plugin_path, mod, plugin_info) |
170 while True: | 170 while True: |
178 @param import_name: name of the plugin to import as found in PLUGIN_INFO['import_name'] | 178 @param import_name: name of the plugin to import as found in PLUGIN_INFO['import_name'] |
179 @param optional: if False and plugin is not found, an ImportError exception is raised | 179 @param optional: if False and plugin is not found, an ImportError exception is raised |
180 | 180 |
181 """ | 181 """ |
182 if import_name in self.plugins: | 182 if import_name in self.plugins: |
183 log.debug('Plugin [%s] already imported, passing' % import_name) | 183 log.debug(u'Plugin [%s] already imported, passing' % import_name) |
184 return | 184 return |
185 if not import_name: | 185 if not import_name: |
186 import_name, (plugin_path, mod, plugin_info) = plugins_to_import.popitem() | 186 import_name, (plugin_path, mod, plugin_info) = plugins_to_import.popitem() |
187 else: | 187 else: |
188 if not import_name in plugins_to_import: | 188 if not import_name in plugins_to_import: |
189 if optional: | 189 if optional: |
190 log.warning(_("Recommended plugin not found: %s") % import_name) | 190 log.warning(_(u"Recommended plugin not found: %s") % import_name) |
191 return | 191 return |
192 log.error(_("Dependency not found: %s") % import_name) | 192 log.error(_(u"Dependency not found: %s") % import_name) |
193 raise ImportError(_('Dependency plugin not found: [%s]') % import_name) | 193 raise ImportError(_('Dependency plugin not found: [%s]') % import_name) |
194 plugin_path, mod, plugin_info = plugins_to_import.pop(import_name) | 194 plugin_path, mod, plugin_info = plugins_to_import.pop(import_name) |
195 dependencies = plugin_info.setdefault("dependencies", []) | 195 dependencies = plugin_info.setdefault("dependencies", []) |
196 recommendations = plugin_info.setdefault("recommendations", []) | 196 recommendations = plugin_info.setdefault("recommendations", []) |
197 for to_import in dependencies + recommendations: | 197 for to_import in dependencies + recommendations: |
198 if to_import not in self.plugins: | 198 if to_import not in self.plugins: |
199 log.debug('Recursively import dependency of [%s]: [%s]' % (import_name, to_import)) | 199 log.debug(u'Recursively import dependency of [%s]: [%s]' % (import_name, to_import)) |
200 try: | 200 try: |
201 self._import_plugins_from_dict(plugins_to_import, to_import, to_import not in dependencies) | 201 self._import_plugins_from_dict(plugins_to_import, to_import, to_import not in dependencies) |
202 except ImportError as e: | 202 except ImportError as e: |
203 log.error(_("Can't import plugin %(name)s: %(error)s") % {'name':plugin_info['name'], 'error':e}) | 203 log.error(_(u"Can't import plugin %(name)s: %(error)s") % {'name':plugin_info['name'], 'error':e}) |
204 return | 204 return |
205 log.info(_("importing plugin: %s") % plugin_info['name']) | 205 log.info(_("importing plugin: %s") % plugin_info['name']) |
206 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self) | 206 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self) |
207 if 'handler' in plugin_info and plugin_info['handler'] == 'yes': | 207 if 'handler' in plugin_info and plugin_info['handler'] == 'yes': |
208 self.plugins[import_name].is_handler = True | 208 self.plugins[import_name].is_handler = True |
303 list_d = defer.DeferredList(conn_cb_list) | 303 list_d = defer.DeferredList(conn_cb_list) |
304 | 304 |
305 def logPluginResults(results): | 305 def logPluginResults(results): |
306 all_succeed = all([success for success, result in results]) | 306 all_succeed = all([success for success, result in results]) |
307 if not all_succeed: | 307 if not all_succeed: |
308 log.error(_("Plugins initialisation error")) | 308 log.error(_(u"Plugins initialisation error")) |
309 for idx, (success, result) in enumerate(results): | 309 for idx, (success, result) in enumerate(results): |
310 if not success: | 310 if not success: |
311 log.error("error (plugin %(name)s): %(failure)s" % | 311 log.error(u"error (plugin %(name)s): %(failure)s" % |
312 {'name': plugin_conn_cb[idx][0], 'failure': result}) | 312 {'name': plugin_conn_cb[idx][0], 'failure': result}) |
313 | 313 |
314 yield list_d.addCallback(logPluginResults) # FIXME: we should have a timeout here, and a way to know if a plugin freeze | 314 yield list_d.addCallback(logPluginResults) # FIXME: we should have a timeout here, and a way to know if a plugin freeze |
315 # TODO: mesure launch time of each plugin | 315 # TODO: mesure launch time of each plugin |
316 | 316 |
328 # submitting a form with empty passwords is restricted to local frontends. | 328 # submitting a form with empty passwords is restricted to local frontends. |
329 return defer.succeed(None) | 329 return defer.succeed(None) |
330 | 330 |
331 def check_result(result): | 331 def check_result(result): |
332 if not result: | 332 if not result: |
333 log.warning(_('Authentication failure of profile %s') % profile) | 333 log.warning(_(u'Authentication failure of profile %s') % profile) |
334 raise exceptions.PasswordError(D_("The provided profile password doesn't match.")) | 334 raise exceptions.PasswordError(D_("The provided profile password doesn't match.")) |
335 if not session_data: # avoid to create two profile sessions when password if specified | 335 if not session_data: # avoid to create two profile sessions when password if specified |
336 return self.memory.newAuthSession(password, profile) | 336 return self.memory.newAuthSession(password, profile) |
337 | 337 |
338 d = self.memory.asyncGetParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile) | 338 d = self.memory.asyncGetParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile) |
614 @param raw_jid: unicode entity's jid | 614 @param raw_jid: unicode entity's jid |
615 @param profile_key: profile""" | 615 @param profile_key: profile""" |
616 profile = self.memory.getProfileName(profile_key) | 616 profile = self.memory.getProfileName(profile_key) |
617 assert profile | 617 assert profile |
618 to_jid = jid.JID(raw_jid) | 618 to_jid = jid.JID(raw_jid) |
619 log.debug(_('subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type': subs_type, 'jid': to_jid.full()}) | 619 log.debug(_(u'subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type': subs_type, 'jid': to_jid.full()}) |
620 if subs_type == "subscribe": | 620 if subs_type == "subscribe": |
621 self.profiles[profile].presence.subscribe(to_jid) | 621 self.profiles[profile].presence.subscribe(to_jid) |
622 elif subs_type == "subscribed": | 622 elif subs_type == "subscribed": |
623 self.profiles[profile].presence.subscribed(to_jid) | 623 self.profiles[profile].presence.subscribed(to_jid) |
624 elif subs_type == "unsubscribe": | 624 elif subs_type == "unsubscribe": |
719 self.bridge.askConfirmation(conf_id, conf_type, data, profile) | 719 self.bridge.askConfirmation(conf_id, conf_type, data, profile) |
720 | 720 |
721 def confirmationAnswer(self, conf_id, accepted, data, profile): | 721 def confirmationAnswer(self, conf_id, accepted, data, profile): |
722 """Called by frontends to answer confirmation requests""" | 722 """Called by frontends to answer confirmation requests""" |
723 client = self.getClient(profile) | 723 client = self.getClient(profile) |
724 log.debug(_("Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success': _("accepted") if accepted else _("refused")}) | 724 log.debug(_(u"Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success': _("accepted") if accepted else _("refused")}) |
725 if conf_id not in client._waiting_conf: | 725 if conf_id not in client._waiting_conf: |
726 log.error(_("Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile}) | 726 log.error(_(u"Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile}) |
727 else: | 727 else: |
728 cb = client._waiting_conf[conf_id][-1] | 728 cb = client._waiting_conf[conf_id][-1] |
729 del client._waiting_conf[conf_id] | 729 del client._waiting_conf[conf_id] |
730 cb(conf_id, accepted, data, profile) | 730 cb(conf_id, accepted, data, profile) |
731 | 731 |