Fix pep8 support in src/plugins.
This commit is contained in:
parent
e51a8a650b
commit
0dca274360
1 changed files with 1052 additions and 1079 deletions
|
|
@ -28,14 +28,14 @@ from email.mime.text import MIMEText
|
|||
from twisted.mail.smtp import sendmail
|
||||
|
||||
PLUGIN_INFO = {
|
||||
"name": "Account Plugin",
|
||||
"import_name": "MISC-ACCOUNT",
|
||||
"type": "MISC",
|
||||
"protocols": [],
|
||||
"dependencies": [],
|
||||
"main": "MiscAccount",
|
||||
"handler": "no",
|
||||
"description": _(u"""SàT account creation""")
|
||||
"name": "Account Plugin",
|
||||
"import_name": "MISC-ACCOUNT",
|
||||
"type": "MISC",
|
||||
"protocols": [],
|
||||
"dependencies": [],
|
||||
"main": "MiscAccount",
|
||||
"handler": "no",
|
||||
"description": _(u"""SàT account creation""")
|
||||
}
|
||||
|
||||
#You need do adapt the following consts to your server
|
||||
|
|
@ -45,24 +45,24 @@ _REG_ADMIN_EMAIL = "admin@example.net"
|
|||
_NEW_ACCOUNT_SERVER = "localhost"
|
||||
_NEW_ACCOUNT_DOMAIN = "example.net"
|
||||
_NEW_ACCOUNT_RESOURCE = "libervia"
|
||||
_PROSODY_PATH = None #prosody path (where prosodyctl will be executed from), or None to automaticaly find it
|
||||
_PROSODY_PATH = None # prosody path (where prosodyctl will be executed from), or None to automaticaly find it
|
||||
_PROSODYCTL = "prosodyctl"
|
||||
|
||||
RESERVED = ['libervia']
|
||||
|
||||
|
||||
class ProsodyRegisterProtocol(protocol.ProcessProtocol):
|
||||
""" Try to register an account with prosody """
|
||||
|
||||
def __init__(self, password, deferred = None):
|
||||
def __init__(self, password, deferred=None):
|
||||
self.password = password
|
||||
self.deferred = deferred
|
||||
self.data = ''
|
||||
|
||||
def connectionMade(self):
|
||||
self.transport.write("%s\n%s" % ((self.password.encode('utf-8'),)*2))
|
||||
self.transport.write("%s\n%s" % ((self.password.encode('utf-8'), ) * 2))
|
||||
self.transport.closeStdin()
|
||||
|
||||
|
||||
def outReceived(self, data):
|
||||
self.data += data
|
||||
|
||||
|
|
@ -87,14 +87,14 @@ class MiscAccount(object):
|
|||
def __init__(self, host):
|
||||
info(_(u"Plugin Account initialization"))
|
||||
self.host = host
|
||||
host.bridge.addMethod("registerSatAccount", ".plugin", in_sign='sss', out_sign='', method=self._registerAccount, async = True)
|
||||
host.bridge.addMethod("registerSatAccount", ".plugin", in_sign='sss', out_sign='', method=self._registerAccount, async=True)
|
||||
if not self._prosody_path:
|
||||
paths = which(_PROSODYCTL)
|
||||
if not paths:
|
||||
error(_("Can't find %s") % (_PROSODYCTL,))
|
||||
error(_("Can't find %s") % (_PROSODYCTL, ))
|
||||
else:
|
||||
self._prosody_path = dirname(paths[0])
|
||||
info(_('Prosody path found: %s') % (self._prosody_path,))
|
||||
info(_('Prosody path found: %s') % (self._prosody_path, ))
|
||||
|
||||
def _registerAccount(self, email, password, profile):
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ class MiscAccount(object):
|
|||
# and just change the password if the account already exists
|
||||
d = defer.Deferred()
|
||||
prosody_reg = ProsodyRegisterProtocol(password, d)
|
||||
prosody_exe = join (self._prosody_path, _PROSODYCTL)
|
||||
prosody_exe = join(self._prosody_path, _PROSODYCTL)
|
||||
reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, 'adduser', "%s@%s" % (profile, _NEW_ACCOUNT_DOMAIN)], path=self._prosody_path)
|
||||
|
||||
d.addCallback(self._accountCreated, profile, email, password)
|
||||
|
|
@ -145,7 +145,7 @@ class MiscAccount(object):
|
|||
|
||||
def email_ko(ignore):
|
||||
#TODO: return error code to user
|
||||
error ("Failed to send email to %s" % email)
|
||||
error("Failed to send email to %s" % email)
|
||||
|
||||
body = (u"""Welcome to Libervia, a Salut à Toi project part
|
||||
|
||||
|
|
@ -165,7 +165,7 @@ follow SàT news: http://www.goffi.org
|
|||
Any feedback welcome
|
||||
|
||||
Cheers
|
||||
Goffi""" % { 'login': login, 'password': password, 'jid':"%s@%s" % (login, _NEW_ACCOUNT_DOMAIN) }).encode('utf-8')
|
||||
Goffi""" % {'login': login, 'password': password, 'jid': "%s@%s" % (login, _NEW_ACCOUNT_DOMAIN)}).encode('utf-8')
|
||||
msg = MIMEText(body, 'plain', 'UTF-8')
|
||||
msg['Subject'] = 'Libervia account created'
|
||||
msg['From'] = _email_from
|
||||
|
|
@ -173,10 +173,9 @@ Goffi""" % { 'login': login, 'password': password, 'jid':"%s@%s" % (login, _NEW_
|
|||
|
||||
d = sendmail(_email_host, _email_from, email, msg.as_string())
|
||||
d.addCallbacks(email_ok, email_ko)
|
||||
|
||||
#email to the administrator
|
||||
|
||||
body = (u"""New account created: %(login)s [%(email)s]""" % { 'login': login, 'email': email }).encode('utf-8')
|
||||
body = (u"""New account created: %(login)s [%(email)s]""" % {'login': login, 'email': email}).encode('utf-8')
|
||||
msg = MIMEText(body, 'plain', 'UTF-8')
|
||||
msg['Subject'] = 'Libervia new account created'
|
||||
msg['From'] = _email_from
|
||||
|
|
|
|||
Loading…
Reference in a new issue