diff --git a/util.py b/util.py index cb8eea7..dad201f 100644 --- a/util.py +++ b/util.py @@ -3,6 +3,29 @@ import sys, traceback EXIT_SUCCESS=0 EXIT_ERROR=1 +def info(message): + # print info to sys.stderr because it isn’t 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 isn’t 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))