daemon: Move the data dir creation out of the login handler.

This commit is contained in:
Damir Jelić 2019-04-03 13:49:36 +02:00
parent fa3caa1c01
commit 9a3329e86e

View File

@ -29,6 +29,7 @@ from multidict import CIMultiDict
@attr.s @attr.s
class ProxyDaemon: class ProxyDaemon:
homeserver = attr.ib() homeserver = attr.ib()
data_dir = attr.ib()
proxy = attr.ib(default=None) proxy = attr.ib(default=None)
ssl = attr.ib(default=None) ssl = attr.ib(default=None)
@ -122,18 +123,11 @@ class ProxyDaemon:
device_id = body.get("device_id", "") device_id = body.get("device_id", "")
device_name = body.get("initial_device_display_name", "pantalaimon") device_name = body.get("initial_device_display_name", "pantalaimon")
store_path = user_data_dir("pantalaimon", "")
try:
os.makedirs(store_path)
except OSError:
pass
client = AsyncClient( client = AsyncClient(
self.homeserver, self.homeserver,
user, user,
device_id, device_id,
store_path=store_path, store_path=self.data_dir,
ssl=self.ssl, ssl=self.ssl,
proxy=self.proxy proxy=self.proxy
) )
@ -333,7 +327,14 @@ class ProxyDaemon:
async def init(homeserver, http_proxy, ssl): async def init(homeserver, http_proxy, ssl):
"""Initialize the proxy and the http server.""" """Initialize the proxy and the http server."""
proxy = ProxyDaemon(homeserver, proxy=http_proxy, ssl=ssl) data_dir = user_data_dir("pantalaimon", "")
try:
os.makedirs(data_dir)
except OSError:
pass
proxy = ProxyDaemon(homeserver, data_dir, proxy=http_proxy, ssl=ssl)
app = web.Application() app = web.Application()
app.add_routes([ app.add_routes([