pantalaimon: Allow pan users to be dynamically updated in the ui thread.

This commit is contained in:
Damir Jelić 2019-05-17 14:56:40 +02:00
parent ed13f78383
commit 694903e8bd
4 changed files with 61 additions and 19 deletions

View File

@ -411,6 +411,8 @@ class ProxyDaemon:
logger.info(f"Succesfully started new background sync client for "
f"{user_id}")
await self.send_queue.put(UpdateUsersMessage())
self.pan_clients[user_id] = pan_client
keyring.set_password(

View File

@ -160,7 +160,10 @@ def main(
servers.append((proxy, runner, site))
proxies.append(proxy)
glib_thread = GlibT(pan_queue.sync_q, ui_queue.sync_q, data_dir)
print(pan_conf.servers.keys())
glib_thread = GlibT(pan_queue.sync_q, ui_queue.sync_q, data_dir,
pan_conf.servers.values())
glib_fut = loop.run_in_executor(
None,

View File

@ -39,7 +39,7 @@ class PanctlParser():
def __init__(self):
self.parser = PanctlArgParse()
subparsers = self.parser.add_subparsers(dest="subcommand")
subparsers.add_parser("list-users")
subparsers.add_parser("list-servers")
list_devices = subparsers.add_parser("list-devices")
list_devices.add_argument("pan_user", type=str)
@ -134,8 +134,9 @@ class PanCompleter(Completer):
return compl_words
def complete_pan_users(self, last_word):
users = self.ctl.ListUsers()
compl_words = self.filter_words([i[0] for i in users], last_word)
servers = self.ctl.ListServers()
users = [item[0] for sublist in servers.values() for item in sublist]
compl_words = self.filter_words(users, last_word)
for compl_word in compl_words:
yield Completion(compl_word, -len(last_word))
@ -260,7 +261,7 @@ class PanCtl:
devices = attr.ib(init=False)
commands = [
"list-users",
"list-servers",
"list-devices",
"export-keys",
"import-keys",
@ -348,12 +349,34 @@ class PanCtl:
f"user {pan_user} from {user_id} via "
f"{device_id}:\n{short_string}")
def list_users(self):
def list_servers(self):
"""List the daemons users."""
users = self.ctl.ListUsers()
print("pantalaimon users:")
for user, device in users:
print(" ", user, device)
servers = self.ctl.ListServers()
print("pantalaimon servers:")
for server, server_users in servers.items():
server_c = get_color(server)
server_list = []
print_formatted_text(HTML(
f" - Name: <{server_c}>{server}</{server_c}>"
))
user_list = []
for user, device in server_users:
user_c = get_color(user)
device_c = get_color(device)
user_list.append(f" - <{user_c}>{user}</{user_c}> "
f"<{device_c}>{device}</{device_c}>")
if user_list:
print(f" - Pan users:")
user_string = "\n".join(user_list)
print_formatted_text(HTML(user_string))
def list_devices(self, args):
devices = self.devices.ListUserDevices(args.pan_user, args.user_id)
@ -398,8 +421,8 @@ class PanCtl:
command = args.subcommand
if command == "list-users":
self.list_users()
if command == "list-servers":
self.list_servers()
elif command == "import-keys":
self.own_message_ids.append(

View File

@ -37,8 +37,8 @@ class Control:
"""
<node>
<interface name='org.pantalaimon1.control'>
<method name='ListUsers'>
<arg type='a(ss)' name='users' direction='out'/>
<method name='ListServers'>
<arg type='a{sa(ss)}' name='servers' direction='out'/>
</method>
<method name='ExportKeys'>
@ -66,16 +66,25 @@ class Control:
Response = signal()
def __init__(self, queue, user_list, id_counter):
self.users = user_list
def __init__(self, queue, store, server_list, id_counter):
self.server_list = server_list
self.store = store
self.queue = queue
self.id_counter = id_counter
self.users = defaultdict(list)
self.update_users()
def update_users(self):
for server in self.server_list:
self.users[server.name] = self.store.load_users(
server.homeserver.hostname
)
@property
def message_id(self):
return self.id_counter.message_id
def ListUsers(self):
def ListServers(self):
"""Return the list of pan users."""
return self.users
@ -230,7 +239,7 @@ class Devices:
self.queue.put(message)
return message.message_id
def UnVerify(self, pan_user, user_id, device_id):
def Unverify(self, pan_user, user_id, device_id):
message = DeviceUnverifyMessage(
self.message_id,
pan_user,
@ -289,6 +298,7 @@ class GlibT:
receive_queue = attr.ib()
send_queue = attr.ib()
data_dir = attr.ib()
server_list = attr.ib()
loop = attr.ib(init=False)
store = attr.ib(init=False)
@ -306,7 +316,8 @@ class GlibT:
id_counter = IdCounter()
self.control_if = Control(self.send_queue, self.users, id_counter)
self.control_if = Control(self.send_queue, self.store,
self.server_list, id_counter)
self.device_if = Devices(self.send_queue, self.store, id_counter)
self.bus = SessionBus()
@ -323,6 +334,9 @@ class GlibT:
if isinstance(message, UpdateDevicesMessage):
self.device_if.update_devices()
if isinstance(message, UpdateUsersMessage):
self.control_if.update_users()
elif isinstance(message, InviteSasSignal):
self.device_if.VerificationInvite(
message.pan_user,