Commit 97fb67e3 authored by David Huss's avatar David Huss 💬
Browse files

Output Errors to stderr

parent a4977b26
...@@ -88,7 +88,7 @@ class Config(): ...@@ -88,7 +88,7 @@ class Config():
filtered_endpoints = [] filtered_endpoints = []
for endpoint_option in endpoint_options: for endpoint_option in endpoint_options:
if not endpoint_option in existing_names: 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: 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))) 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: if len(self.endpoints) > 0:
...@@ -164,14 +164,14 @@ def new_config(user_config_path: str, skip_prompt: bool=True): ...@@ -164,14 +164,14 @@ def new_config(user_config_path: str, skip_prompt: bool=True):
if asking and printing should be done elsewhere) if asking and printing should be done elsewhere)
""" """
if not skip_prompt: 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))) 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)
print(" [0] {}".format(SERVER_PROPERTIES_FILE)) eprint(" [0] {}".format(SERVER_PROPERTIES_FILE))
print(" [1] {}".format(user_config_path)) eprint(" [1] {}".format(user_config_path))
print() eprint()
print("For now the file just needs to contain three lines:") eprint("For now the file just needs to contain three lines:")
for line in EXAMPLE_CONFIG.splitlines(): for line in EXAMPLE_CONFIG.splitlines():
click.echo(click.style((line), fg="bright_black")) click.echo(click.style((line), fg="bright_black"), err=True)
print() 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): 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 # Create all directories in the path to the config, if they don't exist yet
......
...@@ -14,6 +14,7 @@ import click ...@@ -14,6 +14,7 @@ import click
from bbbmon.xmldict import XmlListConfig, XmlDictConfig 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 from bbbmon.configuration import Config, Endpoint, SERVER_PROPERTIES_FILE, Url, Secret, get_user_config_path, init_config, new_config
import bbbmon.printing as printing 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_: ...@@ -53,17 +54,17 @@ def request_meetings(secret: Secret, bbb_url: Url, user_config_path: str, sum_:
root = ElementTree.XML(r.text) root = ElementTree.XML(r.text)
except ElementTree.ParseError as e: except ElementTree.ParseError as e:
if not sum_: 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)) 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)
print("Exiting...") eprint("Exiting...")
exit() exit()
xmldict = XmlDictConfig(root) xmldict = XmlDictConfig(root)
if "returncode" in xmldict.keys(): if "returncode" in xmldict.keys():
if xmldict['returncode'] == "FAILED": if xmldict['returncode'] == "FAILED":
print(xmldict) eprint(xmldict)
exit() exit()
else: else:
print(r.text) eprint(r.text)
exit() exit()
return xmldict return xmldict
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import click import click
import sys
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import NewType, Optional, Tuple, Iterable, List from typing import NewType, Optional, Tuple, Iterable, List
...@@ -22,6 +23,10 @@ FRIENDLY_KEYNAMES = { ...@@ -22,6 +23,10 @@ FRIENDLY_KEYNAMES = {
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def strfdelta(duration: timedelta) -> str: def strfdelta(duration: timedelta) -> str:
""" """
Helper function for datetime.timedelta formatting, use like this: Helper function for datetime.timedelta formatting, use like this:
......
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