2008-02-21 07:06:33 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
reload.py - Phenny Module Reloader Module
|
|
|
|
Copyright 2008, Sean B. Palmer, inamidst.com
|
|
|
|
Licensed under the Eiffel Forum License 2.
|
|
|
|
|
|
|
|
http://inamidst.com/phenny/
|
|
|
|
"""
|
|
|
|
|
2011-02-24 13:57:21 -05:00
|
|
|
import sys, os.path, time, imp
|
2008-02-21 07:06:33 -05:00
|
|
|
import irc
|
|
|
|
|
|
|
|
def f_reload(phenny, input):
|
2012-01-03 14:09:34 -05:00
|
|
|
"""Reloads a module, for use by admins only."""
|
|
|
|
if not input.admin: return
|
2008-02-21 07:06:33 -05:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
name = input.group(2)
|
|
|
|
if name == phenny.config.owner:
|
|
|
|
return phenny.reply('What?')
|
2008-08-09 11:01:20 -04:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
if (not name) or (name == '*'):
|
|
|
|
phenny.variables = None
|
|
|
|
phenny.commands = None
|
|
|
|
phenny.setup()
|
|
|
|
return phenny.reply('done')
|
2008-02-29 10:36:18 -05:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
if name not in sys.modules:
|
|
|
|
return phenny.reply('%s: no such module!' % name)
|
2011-02-24 13:57:21 -05:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
# Thanks to moot for prodding me on this
|
|
|
|
path = sys.modules[name].__file__
|
|
|
|
if path.endswith('.pyc') or path.endswith('.pyo'):
|
|
|
|
path = path[:-1]
|
|
|
|
if not os.path.isfile(path):
|
|
|
|
return phenny.reply('Found %s, but not the source file' % name)
|
2011-02-24 13:57:21 -05:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
module = imp.load_source(name, path)
|
|
|
|
sys.modules[name] = module
|
|
|
|
if hasattr(module, 'setup'):
|
|
|
|
module.setup(phenny)
|
2008-02-21 07:06:33 -05:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
mtime = os.path.getmtime(module.__file__)
|
|
|
|
modified = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime))
|
2008-02-21 07:06:33 -05:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
phenny.register(vars(module))
|
|
|
|
phenny.bind_commands()
|
2008-02-21 07:06:33 -05:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
phenny.reply('%r (version: %s)' % (module, modified))
|
2008-02-21 07:06:33 -05:00
|
|
|
f_reload.name = 'reload'
|
2008-02-29 10:36:18 -05:00
|
|
|
f_reload.rule = ('$nick', ['reload'], r'(\S+)?')
|
|
|
|
f_reload.priority = 'low'
|
2011-03-10 08:41:02 -05:00
|
|
|
f_reload.thread = False
|
2008-02-21 07:06:33 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-01-03 14:09:34 -05:00
|
|
|
print(__doc__.strip())
|