diff --git a/bbbmon/configuration.py b/bbbmon/configuration.py index a1586ebda00f741040a79baff1a51fb39d3640d3..aa3474ecb65fdd0ce86765fcba0f5ddf2539911d 100644 --- a/bbbmon/configuration.py +++ b/bbbmon/configuration.py @@ -88,7 +88,7 @@ class Config(): filtered_endpoints = [] for endpoint_option in endpoint_options: if not endpoint_option in existing_names: - click.echo("{} there is no endpoint called \"{}\" in the configuration. It will be ignored.\n".format(click.style('Error:', fg='red', bold=True), click.style(endpoint_option, fg='red', bold=True))) + click.echo("{} there is no endpoint called \"{}\" in the configuration. It will be ignored.\n".format(click.style('Error:', fg='red', bold=True), click.style(endpoint_option, fg='red', bold=True)), err=True) if self.on_server: click.echo("{} bbbmon is using the server config. You can use a user config using the {} flag.\n".format(click.style('Hint:', fg='yellow', bold=True), click.style("--userconfig", fg='bright_black', bold=True))) if len(self.endpoints) > 0: @@ -164,14 +164,14 @@ def new_config(user_config_path: str, skip_prompt: bool=True): if asking and printing should be done elsewhere) """ if not skip_prompt: - click.echo("{} There was no config file found. Make sure it exists and is readable at either location:".format(click.style('Error:', fg='red', bold=True), click.style("Error:", fg='red', bold=True))) - print(" [0] {}".format(SERVER_PROPERTIES_FILE)) - print(" [1] {}".format(user_config_path)) - print() - print("For now the file just needs to contain three lines:") + click.echo("{} There was no config file found. Make sure it exists and is readable at either location:".format(click.style('Error:', fg='red', bold=True), click.style("Error:", fg='red', bold=True)), err=True) + eprint(" [0] {}".format(SERVER_PROPERTIES_FILE)) + eprint(" [1] {}".format(user_config_path)) + eprint() + eprint("For now the file just needs to contain three lines:") for line in EXAMPLE_CONFIG.splitlines(): - click.echo(click.style((line), fg="bright_black")) - print() + click.echo(click.style((line), fg="bright_black"), err=True) + eprint() if skip_prompt or click.confirm(click.style('Do you want to create a config file at {}?'.format(user_config_path), fg="green"), abort=True): # Create all directories in the path to the config, if they don't exist yet diff --git a/bbbmon/meetings.py b/bbbmon/meetings.py index b49cce68e9de281f5921eb130043740949bde5b8..9b33fb85157d60b6ec8038865fe24f65b8f90154 100644 --- a/bbbmon/meetings.py +++ b/bbbmon/meetings.py @@ -14,6 +14,7 @@ import click from bbbmon.xmldict import XmlListConfig, XmlDictConfig from bbbmon.configuration import Config, Endpoint, SERVER_PROPERTIES_FILE, Url, Secret, get_user_config_path, init_config, new_config import bbbmon.printing as printing +from bbbmon.printing import eprint @@ -53,17 +54,17 @@ def request_meetings(secret: Secret, bbb_url: Url, user_config_path: str, sum_: root = ElementTree.XML(r.text) except ElementTree.ParseError as e: if not sum_: - click.echo("{} The XML returned from {} couldn't be properly parsed. The response text from the Server was:\n{}".format(click.style('Error:', fg='red', bold=True), url, r.text)) - print("Exiting...") + click.echo("{} The XML returned from {} couldn't be properly parsed. The response text from the Server was:\n{}".format(click.style('Error:', fg='red', bold=True), url, r.text), err=True) + eprint("Exiting...") exit() xmldict = XmlDictConfig(root) if "returncode" in xmldict.keys(): if xmldict['returncode'] == "FAILED": - print(xmldict) + eprint(xmldict) exit() else: - print(r.text) + eprint(r.text) exit() return xmldict diff --git a/bbbmon/printing.py b/bbbmon/printing.py index 0c8d4fb6a101e6d161e95998c5a4df101fcdf034..d2db7955d60792c942c65f7ec75fc8d5db4b2fcc 100644 --- a/bbbmon/printing.py +++ b/bbbmon/printing.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import click +import sys from datetime import datetime, timedelta from typing import NewType, Optional, Tuple, Iterable, List @@ -22,6 +23,10 @@ FRIENDLY_KEYNAMES = { +def eprint(*args, **kwargs): + print(*args, file=sys.stderr, **kwargs) + + def strfdelta(duration: timedelta) -> str: """ Helper function for datetime.timedelta formatting, use like this: