diff --git a/bbbmon/bbbmon.py b/bbbmon/bbbmon.py index 29f3fd53684b91b7fc4a788565d7b557c2f3d6b4..34ac6c977b52bab3be4b4df1aa119084a198b630 100755 --- a/bbbmon/bbbmon.py +++ b/bbbmon/bbbmon.py @@ -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 diff --git a/bbbmon/configuration.py b/bbbmon/configuration.py index 9f1516f7712bd3a312c69a342e2cddf532f4cab0..f92559cf4539508f2a4436a5331e0d9bc79c1c94 100644 --- a/bbbmon/configuration.py +++ b/bbbmon/configuration.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index cbd0ca49e8507319a937733e9107f99067743b51..1ea6c171f5fac4d23407c4b6891e6472afeffdc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [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>"]