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
This commit is contained in:
Brian S. Stephan 2013-06-08 21:15:04 -05:00
parent fb477a57b9
commit 96d58f81c4
2 changed files with 21 additions and 4 deletions

View File

@ -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

View File

@ -18,6 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
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