From 81f1042bf83d516a0f9290a0fcd75b14d7b7e518 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Sun, 29 Nov 2020 17:55:43 +0100 Subject: [PATCH] add debug method --- Dockerfile | 2 +- src/langfingaz/bbbRequest.py | 3 ++- src/langfingaz/logMeetingData.py | 4 ++-- src/langfingaz/main.py | 3 ++- src/langfingaz/util/util.py | 11 ++++++++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index f66afb5..39d04d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,5 +41,5 @@ RUN chmod +x ./langfingaz/main.py # unbuffered output option otherwise script sleeps before any output appears # python -u -ENTRYPOINT [ "python", "-u", "./langfingaz/main.py" ] +ENTRYPOINT [ "python", "./langfingaz/main.py" ] CMD [ "log-verbose" ] diff --git a/src/langfingaz/bbbRequest.py b/src/langfingaz/bbbRequest.py index db27389..1b22c9e 100644 --- a/src/langfingaz/bbbRequest.py +++ b/src/langfingaz/bbbRequest.py @@ -3,11 +3,12 @@ import requests from xml.etree import ElementTree import langfingaz.util.fileUtil as fileUtil +import langfingaz.util.util as util def requestMeetingData() -> str: requestUrl = getRequestUrl() - print(">> starting request for " + requestUrl) + util.debug("starting request for " + requestUrl) response = requests.get(requestUrl) if not response.ok: raise ValueError("error during request, got status code {}".format(response.status_code)) diff --git a/src/langfingaz/logMeetingData.py b/src/langfingaz/logMeetingData.py index dce29c5..0415dc3 100755 --- a/src/langfingaz/logMeetingData.py +++ b/src/langfingaz/logMeetingData.py @@ -30,7 +30,7 @@ def v2(folder: Path = saveData.getDefaultFolder()): meetings = parseMeetings.parseMeetingsData(meetingsStr) bbbStatus = parseMeetings.BbbStatus(meetings) bbbStatusStr = str(bbbStatus) - print(util.indentMultilineStr(bbbStatusStr), flush=True) + print(util.indentMultilineStr(bbbStatusStr)) sleepFiveMin(verbose=True) @@ -38,7 +38,7 @@ def v2(folder: Path = saveData.getDefaultFolder()): def v1(folder: Path = saveData.getDefaultFolder()): while True: saveData.requestAndSaveMeetingData(folder) - print('.', end='', flush=True) + print('.') sleepFiveMin() diff --git a/src/langfingaz/main.py b/src/langfingaz/main.py index 68b6036..cc8b40f 100755 --- a/src/langfingaz/main.py +++ b/src/langfingaz/main.py @@ -3,11 +3,12 @@ from sys import argv from langfingaz import plotMeetings from langfingaz import logMeetingData +from langfingaz.util import util def main(): print("=== bbb-status ===") - print(">> given args: " + str(argv)) + util.debug(str(argv)) print() usageStr = 'Usage:\n' + argv[0] + ' [log|log-verbose|plot]\n' + \ diff --git a/src/langfingaz/util/util.py b/src/langfingaz/util/util.py index 8edd337..9afcefe 100644 --- a/src/langfingaz/util/util.py +++ b/src/langfingaz/util/util.py @@ -1,9 +1,18 @@ +BBB_STATUS_DEBUG = True + + +def debug(message: str): + if BBB_STATUS_DEBUG: + print(">> " + message) + + def indentMultilineStr(s: str, indentWith='\t'): indented = indentWith + s.replace('\n', '\n' + indentWith) if s.endswith('\n'): - indented = indented[:len(indented)-len(indentWith)] + indented = indented[:len(indented) - len(indentWith)] return indented + def asString(o: object): attrs = vars(o) # attributes and their values return '\n'.join("%s: %s" % item for item in attrs.items())