quadfile/QuadFile/output.py

36 lines
1.3 KiB
Python
Raw Normal View History

2015-12-23 13:11:38 +00:00
from datetime import datetime
import time
# TODO: I dunno, but there's gotta be a better way to do this crap. This is way too messy
# Some messages pass a True or False as should_print depending on config variables
# Default to true, but return doing nothing if they pass a False.
2018-03-20 21:14:58 +00:00
def print_log(source="None", message, should_print=True):
if should_print == False:
return
2018-03-20 18:32:20 +00:00
message_meta = build_message_meta(source)
2015-12-23 13:11:38 +00:00
if source == "Main":
2018-03-20 18:32:20 +00:00
print('\033[92m', message_meta, '\033[0m', message)
2015-12-23 22:26:40 +00:00
elif source == "Notice":
2018-03-20 18:32:20 +00:00
print('\033[93m', message_meta, '\033[0m', message)
2015-12-23 22:26:40 +00:00
elif source == "Warning":
2018-03-20 18:32:20 +00:00
print('\033[91m', message_meta, '\033[0m', message)
2015-12-23 22:26:40 +00:00
elif source == "Web":
2018-03-20 18:32:20 +00:00
print('\033[95m', message_meta, '\033[0m', message)
2015-12-23 13:11:38 +00:00
else:
2018-03-20 18:32:20 +00:00
print('\033[94m', message_meta, '\033[0m', message)
# Builds the metadata part for the messages above
def build_message_meta(source):
return current_time() + ' ' + source.center(8, '-') + ' :'
2015-12-23 13:11:38 +00:00
def current_time():
return time_to_string(time.time(), True)
def time_to_string(unixtime, time_only = False):
if time_only:
return datetime.fromtimestamp(unixtime).strftime('[%H:%M:%S - ' + time.tzname[time.daylight] + ']')
else:
return datetime.fromtimestamp(unixtime).strftime('%B %d, %Y (%H:%M:%S - ' + time.tzname[time.daylight] + ')')