improve windows compatibility

This commit is contained in:
Ryan Hitchman 2010-01-17 13:38:37 -07:00
parent 30c073495f
commit 92c6d798b5
3 changed files with 10 additions and 7 deletions

3
bot.py
View File

@ -18,7 +18,8 @@ bot = Bot()
print 'Loading plugins' print 'Loading plugins'
# bootstrap the reloader # bootstrap the reloader
eval(compile(open('core/reload.py', 'U').read(), 'core/reload.py', 'exec')) eval(compile(open(os.path.join('core', 'reload.py'), 'U').read(),
os.path.join('core', 'reload.py'), 'exec'))
reload(init=True) reload(init=True)
print 'Connecting to IRC' print 'Connecting to IRC'

View File

@ -1,7 +1,8 @@
import glob
import collections import collections
import traceback import glob
import os
import sys import sys
import traceback
if 'mtimes' not in globals(): if 'mtimes' not in globals():
mtimes = {} mtimes = {}
@ -19,7 +20,7 @@ def reload(init=False):
if init: if init:
bot.plugs = collections.defaultdict(lambda: []) bot.plugs = collections.defaultdict(lambda: [])
for filename in glob.glob("core/*.py"): for filename in glob.glob(os.path.join("core", "*.py")):
mtime = os.stat(filename).st_mtime mtime = os.stat(filename).st_mtime
if mtime != mtimes.get(filename): if mtime != mtimes.get(filename):
mtimes[filename] = mtime mtimes[filename] = mtime
@ -32,11 +33,11 @@ def reload(init=False):
sys.exit() # script on startup sys.exit() # script on startup
continue continue
if filename == 'core/reload.py': if filename == os.path.join('core', 'reload.py'):
reload(init=init) reload(init=init)
return return
fileset = set(glob.glob("plugins/*py")) fileset = set(glob.glob(os.path.join('plugins', '*py')))
for name, data in bot.plugs.iteritems(): # remove deleted/moved plugins for name, data in bot.plugs.iteritems(): # remove deleted/moved plugins
bot.plugs[name] = filter(lambda x: x[0][0] in fileset, data) bot.plugs[name] = filter(lambda x: x[0][0] in fileset, data)

View File

@ -33,6 +33,8 @@ irc_color_re = re.compile(r'(\x03(\d+,\d+|\d)|[\x0f\x02\x16\x1f])')
def get_log_filename(dir, server, chan): def get_log_filename(dir, server, chan):
if chan.startswith(':'):
chan = chan[1:]
return os.path.join(dir, 'log', gmtime('%Y'), server, return os.path.join(dir, 'log', gmtime('%Y'), server,
gmtime('%%s.%m-%d.log') % chan).lower() gmtime('%%s.%m-%d.log') % chan).lower()
@ -53,7 +55,6 @@ def beautify(input):
args['msg'] = irc_color_re.sub('', args['msg']) args['msg'] = irc_color_re.sub('', args['msg'])
if input.command == 'PRIVMSG' and input.msg.count('\x01') >= 2: if input.command == 'PRIVMSG' and input.msg.count('\x01') >= 2:
#ctcp
ctcp = input.msg.split('\x01', 2)[1].split(' ', 1) ctcp = input.msg.split('\x01', 2)[1].split(' ', 1)
if len(ctcp) == 1: if len(ctcp) == 1:
ctcp += [''] ctcp += ['']