From be24ae9dc234e47a632444c7e1c5bbf6c31be09f Mon Sep 17 00:00:00 2001 From: desvox Date: Sat, 4 Aug 2018 08:21:01 -0500 Subject: Allow server to share configuration info with clients. --- clients/network_client.py | 14 ++++++++++++++ clients/urwid/main.py | 23 ++++++++++++----------- server.py | 12 +++++++++++- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/clients/network_client.py b/clients/network_client.py index 87f870e..c45ef8b 100644 --- a/clients/network_client.py +++ b/clients/network_client.py @@ -76,6 +76,7 @@ class BBJ(object): self.send_auth = True try: self.user = self("get_me")["data"] + self.update_instance_info() except URLError: raise URLError("Cannot connect to %s (is the server down?)" % self.base[0:-2]) @@ -178,6 +179,19 @@ class BBJ(object): raise e + def update_instance_info(self): + """ + Stores configuration info for the connected BBJ server. + + { + "instance_name": (string), // a title set by the server owner + "allow_anon": (bool) // whether anonymous participation is allowed + } + """ + response = self("instance_info") + self.instance_info = response["data"] + + def validate(self, key, value, exception=AssertionError): """ Uses the server's db_validate method to verify the validty diff --git a/clients/urwid/main.py b/clients/urwid/main.py index db3c82b..8e1fec8 100644 --- a/clients/urwid/main.py +++ b/clients/urwid/main.py @@ -218,7 +218,8 @@ default_prefs = { "dramatic_exit": True, "date": "%Y/%m/%d", "time": "%H:%M", - "frame_title": "> > T I L D E T O W N < <", + "frame_title": "BBJ", + "use_custom_frame_title": False, "max_text_width": 80, "confirm_anon": True, "edit_escapes": { @@ -278,31 +279,31 @@ pinpath = os.path.join(os.getenv("HOME"), ".bbjpins") class App(object): def __init__(self): self.prefs = bbjrc("load") - - self.mode = None - self.thread = None - self.usermap = {} - self.window_split = False - self.last_index_pos = None - self.last_alarm = None self.client_pinned_threads = load_client_pins() + self.usermap = {} self.match_data = { "query": "", "matches": [], "position": 0, } - # these can be changed and manipulated by other methods + self.mode = None + self.thread = None + self.window_split = False + self.last_index_pos = None + self.last_alarm = None + self.walker = urwid.SimpleFocusListWalker([]) self.box = ActionBox(self.walker) self.body = urwid.AttrMap( urwid.LineBox( self.box, - title=self.prefs["frame_title"], + title=self.prefs["frame_title"] + if self.prefs["use_custom_frame_title"] + else network.instance_info["instance_name"], **frame_theme()), "default" ) - self.loop = urwid.MainLoop( urwid.Frame(self.body), palette=colormap, diff --git a/server.py b/server.py index 9544ad2..c40640a 100644 --- a/server.py +++ b/server.py @@ -26,7 +26,7 @@ try: app_config.update(json.load(_conf)) except FileNotFoundError: with open("config.json", "w") as _conf: - json.dump(app_config, _conf) + json.dump(app_config, _conf, indent=2) def api_method(function): @@ -185,6 +185,16 @@ class API(object): after each method definition are for use in the `mkendpoints.py` script. """ + @api_method + def instance_info(self, args, database, user, **kwargs): + """ + Return configuration info for this running instance of the BBJ server. + """ + return { + "allow_anon": app_config["allow_anon"], + "instance_name": app_config["instance_name"] + } + @api_method def user_register(self, args, database, user, **kwargs): """ -- cgit v1.2.3