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

Output Errors to stderr

parent a4977b26
......@@ -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
......
......@@ -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
......
......@@ -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:
......
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