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:
parent
fb477a57b9
commit
96d58f81c4
@ -1,5 +1,5 @@
|
|||||||
[loggers]
|
[loggers]
|
||||||
keys = root,drbotzo,irclib,drbotzo.markov,drbotzo.weather
|
keys = root,drbotzo,irclib,drbotzo.markov,drbotzo.weather,drbotzo.dispatch
|
||||||
|
|
||||||
[handlers]
|
[handlers]
|
||||||
keys = stdout,logfile
|
keys = stdout,logfile
|
||||||
@ -29,6 +29,12 @@ handlers = stdout,logfile
|
|||||||
propagate = 0
|
propagate = 0
|
||||||
qualname = drbotzo.markov
|
qualname = drbotzo.markov
|
||||||
|
|
||||||
|
[logger_drbotzo.dispatch]
|
||||||
|
level = DEBUG
|
||||||
|
handlers = stdout,logfile
|
||||||
|
propagate = 0
|
||||||
|
qualname = drbotzo.dispatch
|
||||||
|
|
||||||
[logger_drbotzo.weather]
|
[logger_drbotzo.weather]
|
||||||
level = DEBUG
|
level = DEBUG
|
||||||
handlers = stdout,logfile
|
handlers = stdout,logfile
|
||||||
|
@ -18,6 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import MySQLdb as mdb
|
import MySQLdb as mdb
|
||||||
|
import os
|
||||||
|
|
||||||
|
from extlib import irclib
|
||||||
|
|
||||||
from Module import Module
|
from Module import Module
|
||||||
|
|
||||||
@ -94,9 +97,17 @@ class Dispatch(Module):
|
|||||||
|
|
||||||
notified = []
|
notified = []
|
||||||
for key, dest in self._get_key_and_destination(key):
|
for key, dest in self._get_key_and_destination(key):
|
||||||
msg = "[{0:s}] {1:s}".format(key, message.encode('utf-8', 'ignore'))
|
if irclib.is_channel(dest):
|
||||||
self.sendmsg(dest, msg)
|
msg = "[{0:s}] {1:s}".format(key, message.encode('utf-8', 'ignore'))
|
||||||
notified.append(dest)
|
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
|
return notified
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user