Commit bc4d2d31 authored by David Huss's avatar David Huss 💬
Browse files

Fix where --watch caused malformed requests

This happened due to config not cloning implicitly, then beeing
overwritten by sum_meetings and then not containing any URL at all
during the next iteration. Solved by creating a deepcopy
parent 97fb67e3
__version__ = '0.1.30'
__version__ = '0.1.31'
......@@ -53,7 +53,7 @@ def main(userconfig, watch, version):
Internally bbbmon relies on the offical bbb-API, which means you need to have the server's secret in order to create a valid request. Create a new configuration with: bbbmon config --new
"""
__version__ = "0.1.30"
__version__ = "0.1.31"
if version:
print(__version__)
......
......@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import time
import copy
import subprocess
import hashlib
import json
......@@ -78,9 +79,11 @@ def get_meetings(secret: Secret, bbb_url: Url, user_config_path: str, sum_: bool
try:
d = request_meetings(secret, bbb_url, user_config_path, sum_)
except:
eprint("request_meetings didn't work out...")
return ["unreachable"]
if d["meetings"] is None:
eprint("No meetings returned...")
return []
if type(d["meetings"]["meeting"]) is XmlListConfig:
......@@ -127,9 +130,11 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
# Request Meetings from API
meetings = [get_meetings(e.secret, e.url, config.path, sum_) for e in config.endpoints]
config_override = copy.deepcopy(config)
# Collate all meetings from all endpoints together for --sum flag
if sum_:
config, meetings = sum_meetings(config, meetings)
config_override, meetings = sum_meetings(config_override, meetings)
# Clear screen after request is done, and before printing new data to keep
# blinking to a minimum
......@@ -137,7 +142,7 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
click.clear()
for i, endpoint in enumerate(config.endpoints):
for i, endpoint in enumerate(config_override.endpoints):
# Print divider if there is more than one endpoint
if i > 0:
print()
......@@ -164,11 +169,10 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
print(" └─── Currently no active meetings.")
continue
# There are no unreachable endpoints in sum mode
if not sum_:
if meeting[0] == "unreachable":
printing.print_header(endpoint.name, "No connection..", fancy)
continue
# print this if the endpoint (or all endpoints!) is unreachable
if meeting[0] == "unreachable":
printing.print_header(endpoint.name, "No connection..", fancy)
continue
# Make sure that meeting is an actual list
if type(meeting) is XmlDictConfig:
......@@ -226,7 +230,8 @@ def sum_meetings(config: Config, meetings: Optional[XmlDictConfig]) -> Optiona
active_endpoints = [m for m in meetings if m != ["unreachable"]]
if len(active_endpoints) == 0:
return config, None
eprint("No active endpoint...")
return config, ["unreachable"]
summed_endpoint = []
......@@ -253,9 +258,11 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
# Request Meetings from API
meetings = [get_meetings(e.secret, e.url, config.path, sum_) for e in config.endpoints]
config_override = copy.deepcopy(config)
# Collate meetings from all endpoints together in sum mode
if sum_:
config, meetings = sum_meetings(config, meetings)
config_override, meetings = sum_meetings(config_override, meetings)
if sum_ and fancy:
config.endpoints[0].name = "bbb"
......@@ -265,7 +272,7 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
if watch is not None:
click.clear()
for i, endpoint in enumerate(config.endpoints):
for i, endpoint in enumerate(config_override.endpoints):
# Print divider if there is more than one endpoint
if i > 0:
print("="*click.get_terminal_size()[0])
......@@ -300,11 +307,10 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
print(lines)
continue
# There should be no unreachable meetings in sum mode
if not sum_:
if meeting[0] == "unreachable":
printing.print_header(endpoint.name, "No connection..", fancy)
continue
# print this if the endpoint (or all endpoints!) is unreachable
if meeting[0] == "unreachable":
printing.print_header(endpoint.name, "No connection..", fancy)
continue
# Make sure meeting is always a list
if type(meeting) is XmlDictConfig:
......@@ -321,7 +327,7 @@ def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
avg_s = avg_s/60./60.
if not fancy:
if config.on_server:
if config_override.on_server:
# If on server get load
w = subprocess.run(["w | head -1"], shell=True, stdout=subprocess.PIPE)
w = w.stdout.decode('utf-8').strip().split("load average:")
......
[tool.poetry]
name = "bbbmon"
version = "0.1.30"
version = "0.1.31"
description = "A small CLI utility to monitor bbb usage"
authors = ["David Huss <david.huss@hfbk-hamburg.de>"]
maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment