comparison src/plugins/plugin_misc_account.py @ 993:301b342c697a

core: use of the new core.log module: /!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author Goffi <goffi@goffi.org>
date Sat, 19 Apr 2014 19:19:19 +0200
parents 3a96920c07b7
children e90125d07072
comparison
equal deleted inserted replaced
992:f51a1895275c 993:301b342c697a
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _, D_ 20 from sat.core.i18n import _, D_
21 from logging import debug, info, warning, error 21 from sat.core.log import getLogger
22 log = getLogger(__name__)
22 from sat.core import exceptions 23 from sat.core import exceptions
23 from twisted.internet import reactor, defer, protocol 24 from twisted.internet import reactor, defer, protocol
24 from os.path import join, dirname 25 from os.path import join, dirname
25 from twisted.python.procutils import which 26 from twisted.python.procutils import which
26 from twisted.python.failure import Failure 27 from twisted.python.failure import Failure
86 def errReceived(self, data): 87 def errReceived(self, data):
87 self.data += data 88 self.data += data
88 89
89 def processEnded(self, reason): 90 def processEnded(self, reason):
90 if (reason.value.exitCode == 0): 91 if (reason.value.exitCode == 0):
91 info(_('Prosody command succeed')) 92 log.info(_('Prosody command succeed'))
92 self.deferred.callback(None) 93 self.deferred.callback(None)
93 else: 94 else:
94 error(_(u"Can't complete Prosody command (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data}) 95 log.error(_(u"Can't complete Prosody command (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data})
95 self.deferred.errback(Failure(exceptions.InternalError)) 96 self.deferred.errback(Failure(exceptions.InternalError))
96 97
97 @classmethod 98 @classmethod
98 def prosodyctl(cls, plugin, command, password=None, profile=None): 99 def prosodyctl(cls, plugin, command, password=None, profile=None):
99 """Create a new ProsodyRegisterProtocol and execute the given prosodyctl command. 100 """Create a new ProsodyRegisterProtocol and execute the given prosodyctl command.
115 """Account plugin: create a SàT + Prosody account, used by Libervia""" 116 """Account plugin: create a SàT + Prosody account, used by Libervia"""
116 #XXX: This plugin is a Q&D one used for the demo. Something more generic (and not 117 #XXX: This plugin is a Q&D one used for the demo. Something more generic (and not
117 # only focused on Prosody) is planed 118 # only focused on Prosody) is planed
118 119
119 def __init__(self, host): 120 def __init__(self, host):
120 info(_(u"Plugin Account initialization")) 121 log.info(_(u"Plugin Account initialization"))
121 self.host = host 122 self.host = host
122 host.bridge.addMethod("registerSatAccount", ".plugin", in_sign='sss', out_sign='', method=self._registerAccount, async=True) 123 host.bridge.addMethod("registerSatAccount", ".plugin", in_sign='sss', out_sign='', method=self._registerAccount, async=True)
123 host.bridge.addMethod("getNewAccountDomain", ".plugin", in_sign='', out_sign='s', method=self.getNewAccountDomain, async=False) 124 host.bridge.addMethod("getNewAccountDomain", ".plugin", in_sign='', out_sign='s', method=self.getNewAccountDomain, async=False)
124 host.bridge.addMethod("getAccountDialogUI", ".plugin", in_sign='s', out_sign='s', method=self._getAccountDialogUI, async=False) 125 host.bridge.addMethod("getAccountDialogUI", ".plugin", in_sign='s', out_sign='s', method=self._getAccountDialogUI, async=False)
125 self._prosody_path = self.getConfig('prosody_path') 126 self._prosody_path = self.getConfig('prosody_path')
126 if self._prosody_path is None: 127 if self._prosody_path is None:
127 paths = which(self.getConfig('prosodyctl')) 128 paths = which(self.getConfig('prosodyctl'))
128 if not paths: 129 if not paths:
129 error(_("Can't find %s") % (self.getConfig('prosodyctl'), )) 130 log.error(_("Can't find %s") % (self.getConfig('prosodyctl'), ))
130 else: 131 else:
131 self._prosody_path = dirname(paths[0]) 132 self._prosody_path = dirname(paths[0])
132 info(_('Prosody path found: %s') % (self._prosody_path, )) 133 log.info(_('Prosody path found: %s') % (self._prosody_path, ))
133 134
134 self.__account_cb_id = host.registerCallback(self._accountDialogCb, with_data=True) 135 self.__account_cb_id = host.registerCallback(self._accountDialogCb, with_data=True)
135 self.__delete_account_id = host.registerCallback(self.__deleteAccountCb, with_data=True) 136 self.__delete_account_id = host.registerCallback(self.__deleteAccountCb, with_data=True)
136 137
137 def deleteBlogCallback(posts, comments): 138 def deleteBlogCallback(posts, comments):
191 def email_ok(ignore): 192 def email_ok(ignore):
192 print ("Account creation email sent to %s" % email) 193 print ("Account creation email sent to %s" % email)
193 194
194 def email_ko(ignore): 195 def email_ko(ignore):
195 #TODO: return error code to user 196 #TODO: return error code to user
196 error("Failed to send email to %s" % email) 197 log.error("Failed to send email to %s" % email)
197 198
198 body = (u"""Welcome to Libervia, a Salut à Toi project part 199 body = (u"""Welcome to Libervia, a Salut à Toi project part
199 200
200 /!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\ 201 /!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\
201 202