From 6988ce3810c7da708b6f7f3006ba7614ad98137c Mon Sep 17 00:00:00 2001 From: Maxim Stewart Date: Thu, 7 May 2020 19:38:06 -0500 Subject: [PATCH] Fixed importing logic for mixins --- src/signal_classes/Signals.py | 3 +- src/signal_classes/__init__.py | 5 ++- src/signal_classes/mixins/DummyMixin.py | 4 ++ src/signal_classes/mixins/__init__.py | 2 +- src/utils/Logger.py | 55 +++++++++++++++++++++++++ src/utils/__init.py | 1 - src/utils/__init__.py | 6 +++ 7 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/signal_classes/mixins/DummyMixin.py create mode 100644 src/utils/Logger.py delete mode 100644 src/utils/__init.py create mode 100644 src/utils/__init__.py diff --git a/src/signal_classes/Signals.py b/src/signal_classes/Signals.py index 09894be..86ea89e 100644 --- a/src/signal_classes/Signals.py +++ b/src/signal_classes/Signals.py @@ -4,6 +4,7 @@ import threading, subprocess, os # Gtk imports # Application imports +from .mixins import * def threaded(fn): @@ -13,7 +14,7 @@ def threaded(fn): return wrapper -class CrossClassSignals: +class Signals(DummyMixin): def __init__(self, settings): self.settings = settings self.builder = self.settings.returnBuilder() diff --git a/src/signal_classes/__init__.py b/src/signal_classes/__init__.py index 6e3cdc5..159e1e6 100644 --- a/src/signal_classes/__init__.py +++ b/src/signal_classes/__init__.py @@ -1,2 +1,5 @@ +""" + Gtk Bound Signal Module +""" from .mixins import * -from . import Signals +from .Signals import Signals diff --git a/src/signal_classes/mixins/DummyMixin.py b/src/signal_classes/mixins/DummyMixin.py new file mode 100644 index 0000000..61d44f7 --- /dev/null +++ b/src/signal_classes/mixins/DummyMixin.py @@ -0,0 +1,4 @@ +class DummyMixin: + """docstring for DummyMixin""" + def printHelloWorld(self): + print("Hello World!") diff --git a/src/signal_classes/mixins/__init__.py b/src/signal_classes/mixins/__init__.py index b6e690f..e6b3866 100644 --- a/src/signal_classes/mixins/__init__.py +++ b/src/signal_classes/mixins/__init__.py @@ -1 +1 @@ -from . import * +from .DummyMixin import DummyMixin diff --git a/src/utils/Logger.py b/src/utils/Logger.py new file mode 100644 index 0000000..e9a8cc6 --- /dev/null +++ b/src/utils/Logger.py @@ -0,0 +1,55 @@ +# Python imports +import os, logging + +# Application imports + + +class Logger: + def __init__(self): + pass + + def get_logger(self, loggerName = "NO_LOGGER_NAME_PASSED", createFile = True): + """ + Create a new logging object and return it. + :note: + NOSET # Don't know the actual log level of this... (defaulting or literally none?) + Log Levels (From least to most) + Type Value + CRITICAL 50 + ERROR 40 + WARNING 30 + INFO 20 + DEBUG 10 + :param loggerName: Sets the name of the logger object. (Used in log lines) + :param createFile: Whether we create a log file or just pump to terminal + + :return: the logging object we created + """ + + globalLogLvl = logging.DEBUG # Keep this at highest so that handlers can filter to their desired levels + chLogLevel = logging.CRITICAL # Prety musch the only one we change ever + fhLogLevel = logging.DEBUG + log = logging.getLogger(loggerName) + + # Set our log output styles + fFormatter = logging.Formatter('[%(asctime)s] %(pathname)s:%(lineno)d %(levelname)s - %(message)s', '%m-%d %H:%M:%S') + cFormatter = logging.Formatter('%(pathname)s:%(lineno)d] %(levelname)s - %(message)s') + + ch = logging.StreamHandler() + ch.setLevel(level=chLogLevel) + ch.setFormatter(cFormatter) + log.addHandler(ch) + + if createFile: + folder = "core/logs" + file = folder + "/twitter-bot.log" + + if not os.path.exists(folder): + os.mkdir(folder) + + fh = logging.FileHandler(file) + fh.setLevel(level=fhLogLevel) + fh.setFormatter(fFormatter) + log.addHandler(fh) + + return log diff --git a/src/utils/__init.py b/src/utils/__init.py deleted file mode 100644 index b616ca1..0000000 --- a/src/utils/__init.py +++ /dev/null @@ -1 +0,0 @@ -from . import Settings diff --git a/src/utils/__init__.py b/src/utils/__init__.py new file mode 100644 index 0000000..415301e --- /dev/null +++ b/src/utils/__init__.py @@ -0,0 +1,6 @@ +""" + Utils module +""" + +from .Logger import Logger +from .Settings import Settings