put Communication at the end of util.py so it can use warn()

master
BodgeMaster 2022-03-19 08:51:52 +01:00
parent 02e095c321
commit 80e735937c
1 changed files with 24 additions and 24 deletions

48
util.py
View File

@ -3,6 +3,29 @@ import sys, traceback
EXIT_SUCCESS=0
EXIT_ERROR=1
def info(message):
# print info to sys.stderr because it isnt really output, just debug information
print("INFO: "+str(message), file=sys.stderr)
traceback.print_stack()
def warn(message, is_exception=False):
print("WARNING: "+str(message), file=sys.stderr)
if is_exception:
traceback.print_exc()
else:
traceback.print_stack()
def error(message, is_exception=True, handle_gracefully=True):
print("ERROR: "+str(message), file=sys.stderr)
if is_exception:
traceback.print_exc()
else:
traceback.print_stack()
if handle_gracefully:
pass
else:
sys.exit(EXIT_ERROR)
# easy way to communicate across events
class Communication:
def __init__(self):
@ -46,27 +69,4 @@ class Communication:
def __del__(self):
if len(self.__messages)>0:
util.warn("__messages not empty upon destruction of Communitation object:\n"+str(self.__messages))
def info(message):
# print info to sys.stderr because it isnt really output, just debug information
print("INFO: "+str(message), file=sys.stderr)
traceback.print_stack()
def warn(message, is_exception=False):
print("WARNING: "+str(message), file=sys.stderr)
if is_exception:
traceback.print_exc()
else:
traceback.print_stack()
def error(message, is_exception=True, handle_gracefully=True):
print("ERROR: "+str(message), file=sys.stderr)
if is_exception:
traceback.print_exc()
else:
traceback.print_stack()
if handle_gracefully:
pass
else:
sys.exit(EXIT_ERROR)
warn("__messages not empty upon destruction of Communitation object:\n"+str(self.__messages))