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.log import logger
from pantalaimon.thread_messages import DaemonResponse
from pantalaimon.ui import GlibT
from pantalaimon.ui import UI_ENABLED
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,
data_dir,
send_queue=send_queue,
recv_queue=recv_queue,
send_queue=send_queue.async_q if send_queue else None,
recv_queue=recv_queue.async_q if recv_queue else None,
proxy=server_conf.proxy.geturl() if server_conf.proxy else None,
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
StderrHandler().push_application()
servers = []
proxies = []
if UI_ENABLED:
from pantalaimon.ui import GlibT
pan_queue = janus.Queue(loop=loop)
ui_queue = janus.Queue(loop=loop)
servers = []
proxies = []
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:
for server_conf in pan_conf.servers.values():
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))
proxies.append(proxy)
@ -172,20 +191,10 @@ def main(context, log_level, config):
except keyring.errors.KeyringError as 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):
glib_thread.stop()
await fut
message_router_task = loop.create_task(
message_router(ui_queue.async_q, pan_queue.async_q, proxies)
)
home = os.path.expanduser("~")
os.chdir(home)
@ -208,9 +217,13 @@ def main(context, log_level, config):
for _, runner, _ in servers:
loop.run_until_complete(runner.cleanup())
if glib_fut:
loop.run_until_complete(wait_for_glib(glib_thread, glib_fut))
if message_router_task:
message_router_task.cancel()
loop.run_until_complete(asyncio.wait({message_router_task}))
loop.close()

View File

@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from importlib import util
if util.find_spec("pybdubs") and util.find_spec("gi.repository") and False:
from collections import defaultdict
from queue import Empty
@ -46,6 +49,8 @@ from pantalaimon.thread_messages import (
UpdateUsersMessage,
)
UI_ENABLED = True
class IdCounter:
def __init__(self):
@ -574,3 +579,6 @@ class GlibT:
if self.loop:
self.loop.quit()
self.loop = None
else:
UI_ENABLED = False

View File

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