mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
move account initialization to separate function
This commit is contained in:
@@ -60,29 +60,10 @@ def run_cmdline(argv=None, account_plugins=None):
|
|||||||
|
|
||||||
ac = Account(args.db)
|
ac = Account(args.db)
|
||||||
|
|
||||||
if args.show_ffi:
|
ac.run_account(addr=args.email,
|
||||||
ac.set_config("displayname", "bot")
|
password=args.password,
|
||||||
log = events.FFIEventLogger(ac)
|
account_plugins=account_plugins,
|
||||||
ac.add_account_plugin(log)
|
show_ffi=args.show_ffi)
|
||||||
|
|
||||||
for plugin in account_plugins or []:
|
|
||||||
print("adding plugin", plugin)
|
|
||||||
ac.add_account_plugin(plugin)
|
|
||||||
|
|
||||||
if not ac.is_configured():
|
|
||||||
assert (
|
|
||||||
args.email and args.password
|
|
||||||
), "you must specify --email and --password once to configure this database/account"
|
|
||||||
ac.set_config("addr", args.email)
|
|
||||||
ac.set_config("mail_pw", args.password)
|
|
||||||
ac.set_config("mvbox_move", "0")
|
|
||||||
ac.set_config("sentbox_watch", "0")
|
|
||||||
ac.set_config("bot", "1")
|
|
||||||
configtracker = ac.configure()
|
|
||||||
configtracker.wait_finish()
|
|
||||||
|
|
||||||
# start IO threads and configure if neccessary
|
|
||||||
ac.start_io()
|
|
||||||
|
|
||||||
print("{}: waiting for message".format(ac.get_config("addr")))
|
print("{}: waiting for message".format(ac.get_config("addr")))
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from .cutil import (
|
|||||||
from_optional_dc_charpointer,
|
from_optional_dc_charpointer,
|
||||||
iter_array,
|
iter_array,
|
||||||
)
|
)
|
||||||
from .events import EventThread
|
from .events import EventThread, FFIEventLogger
|
||||||
from .message import Message
|
from .message import Message
|
||||||
from .tracker import ConfigureTracker, ImexTracker
|
from .tracker import ConfigureTracker, ImexTracker
|
||||||
|
|
||||||
@@ -598,6 +598,38 @@ class Account(object):
|
|||||||
# meta API for start/stop and event based processing
|
# meta API for start/stop and event based processing
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def run_account(self, addr=None, password=None, account_plugins=None, show_ffi=False):
|
||||||
|
"""get the account running, configure it if necessary. add plugins if provided.
|
||||||
|
|
||||||
|
:param addr: the email address of the account
|
||||||
|
:param password: the password of the account
|
||||||
|
:param account_plugins: a list of plugins to add
|
||||||
|
:param show_ffi: show low level ffi events
|
||||||
|
"""
|
||||||
|
if show_ffi:
|
||||||
|
self.set_config("displayname", "bot")
|
||||||
|
log = FFIEventLogger(self)
|
||||||
|
self.add_account_plugin(log)
|
||||||
|
|
||||||
|
for plugin in account_plugins or []:
|
||||||
|
print("adding plugin", plugin)
|
||||||
|
self.add_account_plugin(plugin)
|
||||||
|
|
||||||
|
if not self.is_configured():
|
||||||
|
assert (
|
||||||
|
addr and password
|
||||||
|
), "you must specify email and password once to configure this database/account"
|
||||||
|
self.set_config("addr", addr)
|
||||||
|
self.set_config("mail_pw", password)
|
||||||
|
self.set_config("mvbox_move", "0")
|
||||||
|
self.set_config("sentbox_watch", "0")
|
||||||
|
self.set_config("bot", "1")
|
||||||
|
configtracker = self.configure()
|
||||||
|
configtracker.wait_finish()
|
||||||
|
|
||||||
|
# start IO threads and configure if neccessary
|
||||||
|
self.start_io()
|
||||||
|
|
||||||
def add_account_plugin(self, plugin, name=None):
|
def add_account_plugin(self, plugin, name=None):
|
||||||
"""add an account plugin which implements one or more of
|
"""add an account plugin which implements one or more of
|
||||||
the :class:`deltachat.hookspec.PerAccount` hooks.
|
the :class:`deltachat.hookspec.PerAccount` hooks.
|
||||||
|
|||||||
Reference in New Issue
Block a user