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

Restructure CLI, add config command

parent 1fd56d58
......@@ -11,7 +11,7 @@ from typing import NewType, Optional, Tuple, Iterable, List
# Local module imports
from bbbmon.xmldict import XmlListConfig, XmlDictConfig
from bbbmon.configuration import Config, Endpoint, SERVER_PROPERTIES_FILE, Url, Secret
from bbbmon.configuration import Config, Endpoint, SERVER_PROPERTIES_FILE, Url, Secret, get_user_config_path
......@@ -35,6 +35,8 @@ bigbluebutton.web.serverURL=https://bbb.example.com/
; bigbluebutton.web.serverURL=https://bbb.test.com/
"""
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
def generate_checksum(call_name: str, query_string: str, secret: Secret) -> str:
"""
......@@ -55,7 +57,7 @@ def request_meetings(secret: Secret, bbb_url: Url, user_config_path: str) -> Xml
call_name = "getMeetings"
checksum = generate_checksum(call_name, "", secret)
url = "{}/api/{}?checksum={}".format(bbb_url, call_name, checksum)
try:
r = requests.get(url)
except:
......@@ -270,8 +272,7 @@ def init_config() -> Optional[Config]:
the user config path. Display a message if neither of these files exist.
"""
# Get OS dependend properties file
user_config_path = click.get_app_dir("bbbmon")
user_config_path = "{}.properties".format(user_config_path)
user_config_path = get_user_config_path()
# Check if we are on the server and try to read that properties file first
if os.path.isfile(SERVER_PROPERTIES_FILE):
......@@ -309,7 +310,13 @@ def new_config(user_config_path: str):
@click.command()
@click.group()
def main():
pass
@main.command(context_settings=CONTEXT_SETTINGS)
@click.pass_context
@click.option('--endpoint', '-e', multiple=True, help="Filter by one or more endpoints as named in the user configuration (e.g. [servername]). Order is respected.")
@click.option('--watch', '-w', help="Run repeatedly with the given interval in seconds", type=click.IntRange(2, 2147483647, clamp=True))
@click.option('--leaderboards/--no-leaderboards', default=True, show_default=True, help="Hide or show the meeting leaderboards")
......@@ -318,7 +325,8 @@ def new_config(user_config_path: str):
@click.option('--presenter/--no-presenter', default=True, show_default=True, help="Hide or show the presenters")
@click.option('--presenter-id/--no-presenter-id', default=True, show_default=True, help="Hide or show the presenter IDs")
@click.option('--fancy/--no-fancy', default=True, show_default=True, help="Use fancy headers")
def main(leaderboards, participants, presenter, watch, presenter_id, meetings, endpoint, fancy):
def meetings(ctx, leaderboards, participants, presenter, watch, presenter_id, meetings, endpoint, fancy):
"""View currently active meetings"""
config = init_config()
config.filter_endpoints(endpoint)
if watch is not None:
......@@ -329,5 +337,28 @@ def main(leaderboards, participants, presenter, watch, presenter_id, meetings, e
print_overview(config, leaderboards, participants, presenter, presenter_id, meetings, watch, fancy)
@main.command(context_settings=CONTEXT_SETTINGS)
@click.pass_context
@click.option('--edit', is_flag=True, help="Open the config in the default editor")
@click.option('--print', 'print_', is_flag=True, help="Print the config to stdout")
@click.option('--path', is_flag=True, help="Print the path to the config")
def config(ctx, edit, path, print_):
"""Print, show or edit the config"""
user_config_path = get_user_config_path()
if edit:
click.edit(filename=user_config_path)
elif path:
print(get_user_config_path())
elif print_:
with open(get_user_config_path(), "r") as f:
print(f.read())
else:
ctx = click.get_current_context()
click.echo(ctx.get_help())
if __name__ == "__main__":
main()
\ No newline at end of file
......@@ -13,6 +13,15 @@ Secret = NewType('Secret', str)
Url = NewType('Url', str)
def get_user_config_path() -> str:
"""
Return the user config path
"""
user_config_path = click.get_app_dir("bbbmon")
user_config_path = "{}.properties".format(user_config_path)
return user_config_path
class Config():
"""
Holds the Server Configurations for multiple endpoints
......
[tool.poetry]
name = "bbbmon"
version = "0.1.10"
version = "0.1.11"
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