Commit 218a1b75 authored by David Huss's avatar David Huss 💬
Browse files

Add --sum flag and handle one more edge case

parent 830f7e4b
...@@ -69,7 +69,8 @@ def main(userconfig, watch): ...@@ -69,7 +69,8 @@ def main(userconfig, watch):
@click.option('--twolines', '-2', is_flag=True, help="Print essentials on two lines") @click.option('--twolines', '-2', is_flag=True, help="Print essentials on two lines")
@click.option('--all', '-a', 'all_', is_flag=True, help="Print all") @click.option('--all', '-a', 'all_', is_flag=True, help="Print all")
@click.option('--fancy/--no-fancy', default=False, show_default=True, help="Use fancy headers") @click.option('--fancy/--no-fancy', default=False, show_default=True, help="Use fancy headers")
def meetings(ctx, userconfig, watch, short, compact, n, all_, twolines, leaderboards, participants, presenter, presenter_id, meetings, endpoint, fancy): @click.option('--sum','sum_', is_flag=True, help="Print all")
def meetings(ctx, userconfig, watch, short, compact, n, all_, twolines, leaderboards, participants, presenter, presenter_id, meetings, endpoint, fancy, sum_):
"""View currently active meetings""" """View currently active meetings"""
if short: if short:
leaderboards = False leaderboards = False
...@@ -92,15 +93,15 @@ def meetings(ctx, userconfig, watch, short, compact, n, all_, twolines, leaderbo ...@@ -92,15 +93,15 @@ def meetings(ctx, userconfig, watch, short, compact, n, all_, twolines, leaderbo
if watch is not None: if watch is not None:
while watch is not None: while watch is not None:
if twolines: if twolines:
meetings_twolines(config, watch, fancy) meetings_twolines(config, watch, fancy, sum_)
else: else:
list_meetings(config, leaderboards, n, participants, presenter, presenter_id, meetings, watch, fancy, compact) list_meetings(config, leaderboards, n, participants, presenter, presenter_id, meetings, watch, fancy, compact, sum_)
time.sleep(watch) time.sleep(watch)
else: else:
if twolines: if twolines:
meetings_twolines(config, watch, fancy) meetings_twolines(config, watch, fancy, sum_)
else: else:
list_meetings(config, leaderboards, n, participants, presenter, presenter_id, meetings, watch, fancy, compact) list_meetings(config, leaderboards, n, participants, presenter, presenter_id, meetings, watch, fancy, compact, sum_)
......
...@@ -116,7 +116,7 @@ def get_duration(meeting: XmlDictConfig) -> timedelta: ...@@ -116,7 +116,7 @@ def get_duration(meeting: XmlDictConfig) -> timedelta:
return duration return duration
def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool, presenter: bool, presenter_id: bool, show_meetings: bool, watch: int, fancy: bool, compact: bool): def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool, presenter: bool, presenter_id: bool, show_meetings: bool, watch: int, fancy: bool, compact: bool, sum_:bool):
""" """
For each endpoint in the configuration get the active meetings and print For each endpoint in the configuration get the active meetings and print
out an overview of the current bbb-usage out an overview of the current bbb-usage
...@@ -125,6 +125,10 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool ...@@ -125,6 +125,10 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
# Request Meetings from API # Request Meetings from API
meetings = [get_meetings(e.secret, e.url, config.path) for e in config.endpoints] meetings = [get_meetings(e.secret, e.url, config.path) for e in config.endpoints]
# Collate all meetings from all endpoints together for --sum flag
if sum_:
config, meetings = sum_meetings(config, meetings)
# Clear screen after request is done, and before printing new data to keep # Clear screen after request is done, and before printing new data to keep
# blinking to a minimum # blinking to a minimum
if watch is not None: if watch is not None:
...@@ -132,18 +136,25 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool ...@@ -132,18 +136,25 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
for i, endpoint in enumerate(config.endpoints): for i, endpoint in enumerate(config.endpoints):
meeting = meetings[i]
# Print divider if there is more than one endpoint # Print divider if there is more than one endpoint
if i > 0: if i > 0:
print() print()
print("="*click.get_terminal_size()[0]) print("="*click.get_terminal_size()[0])
print() print()
if meeting[0] == "unreachable": # If there are no meetings at all, skip to next endpoint
printing.print_header(endpoint.name, "No connection..", fancy) if len(meetings) == 0:
if show_meetings:
printing.print_header(endpoint.name, "MEETINGS", fancy)
print(" └─── Currently no active meetings.")
continue continue
# If we are in summing mode meeting contains all active sessions
if not sum_:
meeting = meetings[i]
else:
meeting = meetings
# If there are no meetings, skip to next endpoint # If there are no meetings, skip to next endpoint
if len(meeting) == 0: if len(meeting) == 0:
if show_meetings: if show_meetings:
...@@ -151,6 +162,16 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool ...@@ -151,6 +162,16 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
print(" └─── Currently no active meetings.") print(" └─── Currently no active meetings.")
continue 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
# Make sure that meeting is an actual list
if type(meeting) is XmlDictConfig:
meeting = [meeting]
n_running = len(meeting) n_running = len(meeting)
n_recording = len([m for m in meeting if m["recording"] == "true"]) n_recording = len([m for m in meeting if m["recording"] == "true"])
n_participants = sum([int(m["participantCount"]) for m in meeting]) n_participants = sum([int(m["participantCount"]) for m in meeting])
...@@ -198,8 +219,29 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool ...@@ -198,8 +219,29 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
printing.print_duration_leaderboard(meeting, n, endpoint.name, presenter, presenter_id, fancy) printing.print_duration_leaderboard(meeting, n, endpoint.name, presenter, presenter_id, fancy)
def sum_meetings(config: Config, meetings: Optional[XmlDictConfig]) -> Optional[XmlDictConfig]:
active_endpoints = [m for m in meetings if m != ["unreachable"]]
if len(active_endpoints) == 0:
return None
summed_endpoint = []
for meetings in active_endpoints:
for meeting in meetings:
summed_endpoint.append(meeting)
summed_endpoint_names= "+".join([e.name for e in config.endpoints])
config.endpoints = [Endpoint(url="", secret="", name=summed_endpoint_names)]
return config, summed_endpoint
def meetings_twolines(config: Config, watch: int, fancy: bool):
def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
""" """
For each endpoint in the configuration get the active meetings and print For each endpoint in the configuration get the active meetings and print
out an overview of the current bbb-usage. This is guaranteed to fit within out an overview of the current bbb-usage. This is guaranteed to fit within
...@@ -209,18 +251,38 @@ def meetings_twolines(config: Config, watch: int, fancy: bool): ...@@ -209,18 +251,38 @@ def meetings_twolines(config: Config, watch: int, fancy: bool):
# Request Meetings from API # Request Meetings from API
meetings = [get_meetings(e.secret, e.url, config.path) for e in config.endpoints] meetings = [get_meetings(e.secret, e.url, config.path) for e in config.endpoints]
# Collate meetings from all endpoints together in sum mode
if sum_:
config, meetings = sum_meetings(config, meetings)
# Clear screen after request is done, and before printing new data to keep # Clear screen after request is done, and before printing new data to keep
# blinking to a minimum # blinking to a minimum
if watch is not None: if watch is not None:
click.clear() click.clear()
for i, endpoint in enumerate(config.endpoints): for i, endpoint in enumerate(config.endpoints):
meeting = meetings[i]
# Print divider if there is more than one endpoint # Print divider if there is more than one endpoint
if i > 0: if i > 0:
print("="*click.get_terminal_size()[0]) print("="*click.get_terminal_size()[0])
# No meetings in none of the endpoints
if len(meetings) == 0:
lines = [
"{:^60}".format("{} there are currently no sessions.").format(endpoint.name[:3]),
""
]
# Cut above 60 characters fill empty
lines = ["{:<60}".format(l[:61]) for l in lines]
lines = "\n".join(lines)
print(lines)
continue
# If we are in sum mode there is only one (summed) endpoint, so use all
if not sum_:
meeting = meetings[i]
else:
meeting = meetings
# If there are no meetings, skip to next endpoint # If there are no meetings, skip to next endpoint
if len(meeting) == 0: if len(meeting) == 0:
lines = [ lines = [
...@@ -233,9 +295,15 @@ def meetings_twolines(config: Config, watch: int, fancy: bool): ...@@ -233,9 +295,15 @@ def meetings_twolines(config: Config, watch: int, fancy: bool):
print(lines) print(lines)
continue continue
if meeting[0] == "unreachable": # There should be no unreachable meetings in sum mode
printing.print_header(endpoint.name, "No connection..", fancy) if not sum_:
continue 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:
meeting = [meeting]
n_running = len(meeting) n_running = len(meeting)
n_recording = len([m for m in meeting if m["recording"] == "true"]) n_recording = len([m for m in meeting if m["recording"] == "true"])
......
[tool.poetry] [tool.poetry]
name = "bbbmon" name = "bbbmon"
version = "0.1.25" version = "0.1.26"
description = "A small CLI utility to monitor bbb usage" description = "A small CLI utility to monitor bbb usage"
authors = ["David Huss <david.huss@hfbk-hamburg.de>"] authors = ["David Huss <david.huss@hfbk-hamburg.de>"]
maintainers = ["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