From e7c7cc87e411c1496d0cbe4b2534840ca0d39f17 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 16:57:32 -0400 Subject: [PATCH] migrate Logging Features --- sopel_modules/SpiceBot_Botevents/BotEvents.py | 2 +- .../SpiceBot_Botevents/Startup_Complete.py | 2 +- sopel_modules/SpiceBot_Channels/Channels.py | 4 +-- .../SpiceBot_CommandsQuery/CommandsQuery.py | 3 +- .../Databaseaddons.py | 2 +- .../SpiceBot_Database_Cache/DatabaseCache.py | 2 +- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 3 +- sopel_modules/SpiceBot_Logs/Logs.py | 23 --------------- sopel_modules/SpiceBot_Restart/Restart.py | 3 +- sopel_modules/SpiceBot_SBTools/__init__.py | 28 +++++++++++++++++-- .../StartupMonologue.py | 3 +- sopel_modules/SpiceBot_Update/Update.py | 3 +- sopel_modules/SpiceBot_Uptime/Uptime.py | 2 +- sopel_modules/SpiceBot_osd/__init__.py | 2 +- 14 files changed, 39 insertions(+), 43 deletions(-) diff --git a/sopel_modules/SpiceBot_Botevents/BotEvents.py b/sopel_modules/SpiceBot_Botevents/BotEvents.py index 63701e2..57db01d 100644 --- a/sopel_modules/SpiceBot_Botevents/BotEvents.py +++ b/sopel_modules/SpiceBot_Botevents/BotEvents.py @@ -6,7 +6,7 @@ Sopel BotEvents is a poor mans way to create module load order dependencies from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging import threading diff --git a/sopel_modules/SpiceBot_Botevents/Startup_Complete.py b/sopel_modules/SpiceBot_Botevents/Startup_Complete.py index 0fcd84f..ad8e106 100644 --- a/sopel_modules/SpiceBot_Botevents/Startup_Complete.py +++ b/sopel_modules/SpiceBot_Botevents/Startup_Complete.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging from .BotEvents import set_bot_event, check_bot_startup diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index e3f697d..54dca05 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event @@ -15,7 +14,8 @@ import spicemanip from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, topic_compile, channel_privs, - join_all_channels, chanadmin_all_channels, channel_list_current + join_all_channels, chanadmin_all_channels, channel_list_current, + bot_logging ) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 57774cb..45deae7 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging import os from difflib import SequenceMatcher @@ -12,7 +11,7 @@ from operator import itemgetter import threading -from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events +from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events, bot_logging import spicemanip diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index 3bd1806..7c07129 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module from sopel.tools import Identifier -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging from sopel.db import _deserialize, SopelDB import json diff --git a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py index 1ae2841..754d0ed 100644 --- a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py +++ b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging def setup(bot): diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index f2e9bcb..a12c189 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -3,14 +3,13 @@ from __future__ import unicode_literals, absolute_import, division, print_function import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register, commandsquery_register_type -from sopel_modules.SpiceBot_SBTools import read_directory_json_to_dict, sopel_triggerargs +from sopel_modules.SpiceBot_SBTools import read_directory_json_to_dict, sopel_triggerargs, bot_logging import spicemanip diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 3aa7879..9bf46d1 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -69,26 +69,3 @@ def bot_command_action(bot, trigger): bot.osd("Is Examining " + str(logtype) + " log(s).") for line in bot.memory['SpiceBot_Logs'][logtype]: bot.osd(str(line), trigger.sender, 'action') - - -def bot_logging(bot, logtype, logentry): - - if 'SpiceBot_Logs_queue' not in bot.memory: - bot.memory['SpiceBot_Logs_queue'] = [] - - logmessage = "[" + logtype + "] " + logentry - - if bot.config.SpiceBot_Logs.logging_channel: - bot.memory['SpiceBot_Logs_queue'].append(logmessage) - - stderr(logmessage) - - if 'SpiceBot_Logs' not in bot.memory: - bot.memory['SpiceBot_Logs'] = {} - - if logtype not in bot.memory['SpiceBot_Logs'].keys(): - bot.memory['SpiceBot_Logs'][logtype] = [] - - bot.memory['SpiceBot_Logs'][logtype].append(logentry) - if len(bot.memory['SpiceBot_Logs'][logtype]) > 10: - del bot.memory['SpiceBot_Logs'][logtype][0] diff --git a/sopel_modules/SpiceBot_Restart/Restart.py b/sopel_modules/SpiceBot_Restart/Restart.py index 246f7b8..58baea5 100644 --- a/sopel_modules/SpiceBot_Restart/Restart.py +++ b/sopel_modules/SpiceBot_Restart/Restart.py @@ -6,8 +6,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_SBTools import service_manip -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import service_manip, bot_logging @sopel.module.nickname_commands('restart') diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 8de382d..26fb14c 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -7,8 +7,6 @@ import sopel from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP HOP = HALFOP -from sopel_modules.SpiceBot_Logs.Logs import bot_logging - import collections import re import os @@ -88,6 +86,32 @@ def command_permissions_check(bot, trigger, privslist): return True +"""Logging""" + + +def bot_logging(bot, logtype, logentry): + + if 'SpiceBot_Logs_queue' not in bot.memory: + bot.memory['SpiceBot_Logs_queue'] = [] + + logmessage = "[" + logtype + "] " + logentry + + if bot.config.SpiceBot_Logs.logging_channel: + bot.memory['SpiceBot_Logs_queue'].append(logmessage) + + stderr(logmessage) + + if 'SpiceBot_Logs' not in bot.memory: + bot.memory['SpiceBot_Logs'] = {} + + if logtype not in bot.memory['SpiceBot_Logs'].keys(): + bot.memory['SpiceBot_Logs'][logtype] = [] + + bot.memory['SpiceBot_Logs'][logtype].append(logentry) + if len(bot.memory['SpiceBot_Logs'][logtype]) > 10: + del bot.memory['SpiceBot_Logs'][logtype][0] + + """ Time """ diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index 29a5636..0a0e0ef 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -3,11 +3,10 @@ from __future__ import unicode_literals, absolute_import, division, print_function from sopel import module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events -from sopel_modules.SpiceBot_SBTools import humanized_time +from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging import time diff --git a/sopel_modules/SpiceBot_Update/Update.py b/sopel_modules/SpiceBot_Update/Update.py index 7797e44..c137b5c 100644 --- a/sopel_modules/SpiceBot_Update/Update.py +++ b/sopel_modules/SpiceBot_Update/Update.py @@ -4,14 +4,13 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel.module -from sopel_modules.SpiceBot_Logs.Logs import bot_logging from sopel.config.types import StaticSection, ValidatedAttribute import os import spicemanip -from sopel_modules.SpiceBot_SBTools import service_manip, sopel_triggerargs, command_permissions_check +from sopel_modules.SpiceBot_SBTools import service_manip, sopel_triggerargs, command_permissions_check, bot_logging class SpiceBot_Update_MainSection(StaticSection): diff --git a/sopel_modules/SpiceBot_Uptime/Uptime.py b/sopel_modules/SpiceBot_Uptime/Uptime.py index 03a5f14..1e56e13 100644 --- a/sopel_modules/SpiceBot_Uptime/Uptime.py +++ b/sopel_modules/SpiceBot_Uptime/Uptime.py @@ -8,7 +8,7 @@ import time from sopel_modules.SpiceBot_SBTools import humanized_time -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging def configure(config): diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index ae143d4..92c3810 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -14,7 +14,7 @@ from sopel import tools, module from sopel.tools import Identifier from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_Logs.Logs import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging import time from collections import abc