summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean B. Palmer <sbp@aldebaran.local>2011-02-24 18:57:21 +0000
committerSean B. Palmer <sbp@aldebaran.local>2011-02-24 18:57:21 +0000
commitecb8af1bbea0dee31903b1e962c0b731f2d36318 (patch)
tree3e1b283480610037177c2fbaeb740c7e3da009b0
parent22dfed082cadf05897ce4d077b2d80569376e2d7 (diff)
downloadbot-ecb8af1bbea0dee31903b1e962c0b731f2d36318.tar.gz
bot-ecb8af1bbea0dee31903b1e962c0b731f2d36318.tar.bz2
bot-ecb8af1bbea0dee31903b1e962c0b731f2d36318.zip
Better reload function.
-rwxr-xr-xmodules/reload.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/modules/reload.py b/modules/reload.py
index fc508a6..50e1a56 100755
--- a/modules/reload.py
+++ b/modules/reload.py
@@ -7,6 +7,7 @@ Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
+import sys, os.path, time, imp
import irc
def f_reload(phenny, input):
@@ -21,18 +22,23 @@ def f_reload(phenny, input):
phenny.setup()
return phenny.reply('done')
- try: module = getattr(__import__('modules.' + name), name)
- except ImportError:
- module = getattr(__import__('opt.' + name), name)
- reload(module)
+ if not sys.modules.has_key(name):
+ return phenny.reply('%s: no such module!' % name)
+
+ # 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'):
module.setup(phenny)
- if hasattr(module, '__file__'):
- import os.path, time
- mtime = os.path.getmtime(module.__file__)
- modified = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime))
- else: modified = 'unknown'
+ mtime = os.path.getmtime(module.__file__)
+ modified = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime))
phenny.register(vars(module))
phenny.bind_commands()