From 96d58f81c4134d7762d027e9c1f1b9725b8eb771 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 8 Jun 2013 21:15:04 -0500 Subject: [PATCH] Dispatch: support file targets if for some reason (spoilers: i have a reason) you would want to have dispatched stuff go to a file, that can now be done. prepend the (fully-qualified) filename with FILE: in the database and off you go --- logging.cfg | 8 +++++++- modules/Dispatch.py | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/logging.cfg b/logging.cfg index c473aac..1912805 100644 --- a/logging.cfg +++ b/logging.cfg @@ -1,5 +1,5 @@ [loggers] -keys = root,drbotzo,irclib,drbotzo.markov,drbotzo.weather +keys = root,drbotzo,irclib,drbotzo.markov,drbotzo.weather,drbotzo.dispatch [handlers] keys = stdout,logfile @@ -29,6 +29,12 @@ handlers = stdout,logfile propagate = 0 qualname = drbotzo.markov +[logger_drbotzo.dispatch] +level = DEBUG +handlers = stdout,logfile +propagate = 0 +qualname = drbotzo.dispatch + [logger_drbotzo.weather] level = DEBUG handlers = stdout,logfile diff --git a/modules/Dispatch.py b/modules/Dispatch.py index 00e89c1..477f2c5 100644 --- a/modules/Dispatch.py +++ b/modules/Dispatch.py @@ -18,6 +18,9 @@ along with this program. If not, see . """ import MySQLdb as mdb +import os + +from extlib import irclib from Module import Module @@ -94,9 +97,17 @@ class Dispatch(Module): notified = [] for key, dest in self._get_key_and_destination(key): - msg = "[{0:s}] {1:s}".format(key, message.encode('utf-8', 'ignore')) - self.sendmsg(dest, msg) - notified.append(dest) + if irclib.is_channel(dest): + msg = "[{0:s}] {1:s}".format(key, message.encode('utf-8', 'ignore')) + self.sendmsg(dest, msg) + notified.append(dest) + elif dest.find('FILE:') == 0: + filename = dest.replace('FILE:', '') + filename = os.path.abspath(filename) + self.log.info("filename: {0:s}".format(filename)) + msg = "[{0:s}] {1:s}\n".format(key, message.encode('utf-8', 'ignore')) + with open(filename, 'w') as f: + f.write(msg) return notified