Skip to content
Snippets Groups Projects
Commit 218a1b75 authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Add --sum flag and handle one more edge case

parent 830f7e4b
No related branches found
No related tags found
No related merge requests found
......@@ -69,7 +69,8 @@ def main(userconfig, watch):
@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('--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"""
if short:
leaderboards = False
......@@ -92,15 +93,15 @@ def meetings(ctx, userconfig, watch, short, compact, n, all_, twolines, leaderbo
if watch is not None:
while watch is not None:
if twolines:
meetings_twolines(config, watch, fancy)
meetings_twolines(config, watch, fancy, sum_)
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)
else:
if twolines:
meetings_twolines(config, watch, fancy)
meetings_twolines(config, watch, fancy, sum_)
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:
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
out an overview of the current bbb-usage
......@@ -125,6 +125,10 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
# Request Meetings from API
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
# blinking to a minimum
if watch is not None:
......@@ -132,18 +136,25 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
for i, endpoint in enumerate(config.endpoints):
meeting = meetings[i]
# Print divider if there is more than one endpoint
if i > 0:
print()
print("="*click.get_terminal_size()[0])
print()
if meeting[0] == "unreachable":
printing.print_header(endpoint.name, "No connection..", fancy)
# If there are no meetings at all, skip to next endpoint
if len(meetings) == 0:
if show_meetings:
printing.print_header(endpoint.name, "MEETINGS", fancy)
print(" └─── Currently no active meetings.")
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 len(meeting) == 0:
if show_meetings:
......@@ -151,6 +162,16 @@ 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
# Make sure that meeting is an actual list
if type(meeting) is XmlDictConfig:
meeting = [meeting]
n_running = len(meeting)
n_recording = len([m for m in meeting if m["recording"] == "true"])
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
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)]
def meetings_twolines(config: Config, watch: int, fancy: bool):
return config, summed_endpoint
def meetings_twolines(config: Config, watch: int, fancy: bool, sum_:bool):
"""
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
......@@ -209,18 +251,38 @@ def meetings_twolines(config: Config, watch: int, fancy: bool):
# Request Meetings from API
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
# blinking to a minimum
if watch is not None:
click.clear()
for i, endpoint in enumerate(config.endpoints):
meeting = meetings[i]
# Print divider if there is more than one endpoint
if i > 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 len(meeting) == 0:
lines = [
......@@ -233,10 +295,16 @@ def meetings_twolines(config: Config, watch: int, fancy: 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
# Make sure meeting is always a list
if type(meeting) is XmlDictConfig:
meeting = [meeting]
n_running = len(meeting)
n_recording = len([m for m in meeting if m["recording"] == "true"])
n_participants = sum([int(m["participantCount"]) for m in meeting])
......
[tool.poetry]
name = "bbbmon"
version = "0.1.25"
version = "0.1.26"
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>"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment