From ae8e58b819c64332b28f6cf597d33c6a37b012de Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 30 May 2019 14:43:28 -0400 Subject: [PATCH] logs without bot --- sopel_modules/SpiceBot/Logs.py | 27 +++++++++---------- sopel_modules/SpiceBot_Logs/Logs_Command.py | 2 +- sopel_modules/SpiceBot_Logs/Queue.py | 3 +-- .../StartupMonologue_Display_Errors.py | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/sopel_modules/SpiceBot/Logs.py b/sopel_modules/SpiceBot/Logs.py index 0b13058..9e201d5 100644 --- a/sopel_modules/SpiceBot/Logs.py +++ b/sopel_modules/SpiceBot/Logs.py @@ -11,6 +11,8 @@ import threading import os import spicemanip +from .Config import config as botconfig + class BotLogs(): """This Is a contained source of log information""" @@ -20,9 +22,6 @@ class BotLogs(): "list": {"Sopel_systemd": [], "Sopel_stdio": []}, "queue": [] } - self.sopel_config = { - "logging_channel": True - } def log(self, logtype, logentry, stdio=False): @@ -31,7 +30,7 @@ class BotLogs(): logtitle = "[" + logtype + "]" logmessage = logtitle + " " + logentry - if self.sopel_config["logging_channel"]: + if botconfig.config.core.logging_channel: self.dict["queue"].append(logmessage) if stdio: @@ -43,22 +42,22 @@ class BotLogs(): self.lock.release() - def get_logs(self, bot, logtype): + def get_logs(self, logtype): if logtype == "Sopel_systemd": - logindex = self.systemd_logs_fetch(bot) + logindex = self.systemd_logs_fetch() elif logtype == "Sopel_stdio": - logindex = self.stdio_logs_fetch(bot) + logindex = self.stdio_logs_fetch() else: logindex = self.dict["list"][logtype] return logindex - def stdio_logs_fetch(self, bot): + def stdio_logs_fetch(self): stdio_ignore = [] for logtype in self.dict["list"].keys(): stdio_ignore.append("[" + logtype + "]") - logfile = os.path.os.path.join(bot.config.core.logdir, 'stdio.log') + logfile = os.path.os.path.join(botconfig.config.core.logdir, 'stdio.log') try: log_file_lines = [] @@ -92,8 +91,8 @@ class BotLogs(): return debuglines - def systemd_logs_fetch(self, bot): - servicepid = self.get_running_pid(bot) + def systemd_logs_fetch(self): + servicepid = self.get_running_pid() debuglines = [] for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'): line = str(line).split(str(os.uname()[1] + " "))[-1] @@ -104,14 +103,14 @@ class BotLogs(): debuglines.append(str(line)) return debuglines - def get_running_pid(self, bot): + def get_running_pid(self): try: - filename = "/run/sopel/sopel-" + str(bot.nick) + ".pid" + filename = "/run/sopel/sopel-" + str(botconfig.config.core.nick) + ".pid" with open(filename, 'r') as pid_file: pidnum = int(pid_file.read()) except Exception as e: pidnum = e - pidnum = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1] + pidnum = str(os.popen("systemctl show " + str(botconfig.config.core.nick) + " --property=MainPID").read()).split("=")[-1] return pidnum diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index 0819ab6..99545f1 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -33,7 +33,7 @@ def bot_command_logs(bot, trigger): logtype = SpiceBot.inlist_match(logtype, SpiceBot.logs.dict["list"].keys()) - logindex = SpiceBot.logs.get_logs(bot, logtype) + logindex = SpiceBot.logs.get_logs(logtype) if not len(logindex): bot.osd("No logs found for " + str(logtype) + ".") diff --git a/sopel_modules/SpiceBot_Logs/Queue.py b/sopel_modules/SpiceBot_Logs/Queue.py index dedfc53..274bdeb 100644 --- a/sopel_modules/SpiceBot_Logs/Queue.py +++ b/sopel_modules/SpiceBot_Logs/Queue.py @@ -18,7 +18,7 @@ def setup(bot): @sopel.module.rule('.*') def join_log_channel(bot, trigger): - if bot.config.core.logging_channel: + if SpiceBot.config.config.core.logging_channel: channel = bot.config.core.logging_channel if channel not in bot.channels.keys(): bot.write(('JOIN', bot.nick, channel)) @@ -30,5 +30,4 @@ def join_log_channel(bot, trigger): bot.osd(str(SpiceBot.logs.dict["queue"][0]), channel) del SpiceBot.logs.dict["queue"][0] else: - SpiceBot.logs.sopel_config["logging_channel"] = False SpiceBot.logs.dict["queue"] = [] diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Errors.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Errors.py index 34b0ede..4cd49db 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Errors.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display_Errors.py @@ -10,7 +10,7 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.rule('.*') def bot_startup_monologue_start(bot, trigger): - debuglines = SpiceBot.logs.stdio_logs_fetch(bot) + debuglines = SpiceBot.logs.stdio_logs_fetch() searchphrasefound = [] for line in debuglines: