pantalaimon: Make the dbus UI optional.

This commit is contained in:
Damir Jelić 2019-07-12 14:47:20 +02:00
parent dfa5501a6c
commit ad65fbf1a7
3 changed files with 591 additions and 568 deletions

View File

@ -28,7 +28,7 @@ from pantalaimon.config import PanConfig, PanConfigError, parse_log_level
from pantalaimon.daemon import ProxyDaemon from pantalaimon.daemon import ProxyDaemon
from pantalaimon.log import logger from pantalaimon.log import logger
from pantalaimon.thread_messages import DaemonResponse from pantalaimon.thread_messages import DaemonResponse
from pantalaimon.ui import GlibT from pantalaimon.ui import UI_ENABLED
def create_dirs(data_dir, conf_dir): def create_dirs(data_dir, conf_dir):
@ -50,8 +50,8 @@ async def init(data_dir, server_conf, send_queue, recv_queue):
server_conf.homeserver, server_conf.homeserver,
server_conf, server_conf,
data_dir, data_dir,
send_queue=send_queue, send_queue=send_queue.async_q if send_queue else None,
recv_queue=recv_queue, recv_queue=recv_queue.async_q if recv_queue else None,
proxy=server_conf.proxy.geturl() if server_conf.proxy else None, proxy=server_conf.proxy.geturl() if server_conf.proxy else None,
ssl=None if server_conf.ssl is True else False, ssl=None if server_conf.ssl is True else False,
) )
@ -154,17 +154,36 @@ def main(context, log_level, config):
logger.level = pan_conf.log_level logger.level = pan_conf.log_level
StderrHandler().push_application() StderrHandler().push_application()
pan_queue = janus.Queue(loop=loop)
ui_queue = janus.Queue(loop=loop)
servers = [] servers = []
proxies = [] proxies = []
if UI_ENABLED:
from pantalaimon.ui import GlibT
pan_queue = janus.Queue(loop=loop)
ui_queue = janus.Queue(loop=loop)
glib_thread = GlibT(
pan_queue.sync_q, ui_queue.sync_q, data_dir, pan_conf.servers.values(), pan_conf
)
glib_fut = loop.run_in_executor(None, glib_thread.run)
message_router_task = loop.create_task(
message_router(ui_queue.async_q, pan_queue.async_q, proxies)
)
else:
glib_thread = None
glib_fut = None
pan_queue = None
ui_queue = None
message_router_task = None
try: try:
for server_conf in pan_conf.servers.values(): for server_conf in pan_conf.servers.values():
proxy, runner, site = loop.run_until_complete( proxy, runner, site = loop.run_until_complete(
init(data_dir, server_conf, pan_queue.async_q, ui_queue.async_q) init(data_dir, server_conf, pan_queue, ui_queue)
) )
servers.append((proxy, runner, site)) servers.append((proxy, runner, site))
proxies.append(proxy) proxies.append(proxy)
@ -172,20 +191,10 @@ def main(context, log_level, config):
except keyring.errors.KeyringError as e: except keyring.errors.KeyringError as e:
context.fail(f"Error initializing keyring: {e}") context.fail(f"Error initializing keyring: {e}")
glib_thread = GlibT(
pan_queue.sync_q, ui_queue.sync_q, data_dir, pan_conf.servers.values(), pan_conf
)
glib_fut = loop.run_in_executor(None, glib_thread.run)
async def wait_for_glib(glib_thread, fut): async def wait_for_glib(glib_thread, fut):
glib_thread.stop() glib_thread.stop()
await fut await fut
message_router_task = loop.create_task(
message_router(ui_queue.async_q, pan_queue.async_q, proxies)
)
home = os.path.expanduser("~") home = os.path.expanduser("~")
os.chdir(home) os.chdir(home)
@ -208,9 +217,13 @@ def main(context, log_level, config):
for _, runner, _ in servers: for _, runner, _ in servers:
loop.run_until_complete(runner.cleanup()) loop.run_until_complete(runner.cleanup())
loop.run_until_complete(wait_for_glib(glib_thread, glib_fut)) if glib_fut:
message_router_task.cancel() loop.run_until_complete(wait_for_glib(glib_thread, glib_fut))
loop.run_until_complete(asyncio.wait({message_router_task}))
if message_router_task:
message_router_task.cancel()
loop.run_until_complete(asyncio.wait({message_router_task}))
loop.close() loop.close()

File diff suppressed because it is too large Load Diff

View File

@ -25,18 +25,20 @@ setup(
"keyring", "keyring",
"logbook", "logbook",
"peewee", "peewee",
"dbus-python",
"PyGObject",
"pydbus",
"janus", "janus",
"prompt_toolkit", "prompt_toolkit",
"notify2",
"typing;python_version<'3.5'", "typing;python_version<'3.5'",
"matrix-nio[e2e] >= 0.4" "matrix-nio[e2e] >= 0.4"
], ],
extras_require={ extras_require={
"e2e_search": [ "e2e_search": [
"tantivy", "tantivy",
],
"ui": [
"dbus-python",
"PyGObject",
"pydbus",
"notify2",
] ]
}, },
entry_points={ entry_points={