Better reload function.
parent
22dfed082c
commit
ecb8af1bbe
|
@ -7,6 +7,7 @@ Licensed under the Eiffel Forum License 2.
|
||||||
http://inamidst.com/phenny/
|
http://inamidst.com/phenny/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import sys, os.path, time, imp
|
||||||
import irc
|
import irc
|
||||||
|
|
||||||
def f_reload(phenny, input):
|
def f_reload(phenny, input):
|
||||||
|
@ -21,18 +22,23 @@ def f_reload(phenny, input):
|
||||||
phenny.setup()
|
phenny.setup()
|
||||||
return phenny.reply('done')
|
return phenny.reply('done')
|
||||||
|
|
||||||
try: module = getattr(__import__('modules.' + name), name)
|
if not sys.modules.has_key(name):
|
||||||
except ImportError:
|
return phenny.reply('%s: no such module!' % name)
|
||||||
module = getattr(__import__('opt.' + name), name)
|
|
||||||
reload(module)
|
# 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)
|
||||||
|
|
||||||
|
module = imp.load_source(name, path)
|
||||||
|
sys.modules[name] = module
|
||||||
if hasattr(module, 'setup'):
|
if hasattr(module, 'setup'):
|
||||||
module.setup(phenny)
|
module.setup(phenny)
|
||||||
|
|
||||||
if hasattr(module, '__file__'):
|
mtime = os.path.getmtime(module.__file__)
|
||||||
import os.path, time
|
modified = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime))
|
||||||
mtime = os.path.getmtime(module.__file__)
|
|
||||||
modified = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime))
|
|
||||||
else: modified = 'unknown'
|
|
||||||
|
|
||||||
phenny.register(vars(module))
|
phenny.register(vars(module))
|
||||||
phenny.bind_commands()
|
phenny.bind_commands()
|
||||||
|
|
Loading…
Reference in New Issue