This commit is contained in:
nemunaire 2015-01-05 03:07:41 +01:00
parent 38aea5dd37
commit 2b9c810e88
2 changed files with 10 additions and 13 deletions

View File

@ -24,7 +24,7 @@ import os
import sys import sys
import nemubot import nemubot
import nemubot.prompt as prompt import nemubot.prompt
from nemubot.prompt.builtins import load_file from nemubot.prompt.builtins import load_file
from nemubot.prompt.reset import PromptReset from nemubot.prompt.reset import PromptReset
from nemubot.importer import ModuleFinder from nemubot.importer import ModuleFinder
@ -98,7 +98,7 @@ if __name__ == "__main__":
context.noautoconnect = True context.noautoconnect = True
# Load the prompt # Load the prompt
prmpt = prompt.Prompt() prmpt = nemubot.prompt.Prompt()
# Register the hook for futur import # Register the hook for futur import
sys.meta_path.append(ModuleFinder(context, prmpt)) sys.meta_path.append(ModuleFinder(context, prmpt))
@ -116,26 +116,24 @@ if __name__ == "__main__":
print ("Nemubot v%s ready, my PID is %i!" % (nemubot.__version__, print ("Nemubot v%s ready, my PID is %i!" % (nemubot.__version__,
os.getpid())) os.getpid()))
context.start()
while True: while True:
try: try:
prmpt.run(context) context.start()
if prmpt.run(context):
break
except PromptReset as e: except PromptReset as e:
if e.type == "quit": if e.type == "quit":
break break
try: try:
# Reload context
imp.reload(bot)
context = nemubot.hotswap(context)
# Reload prompt
imp.reload(prompt)
prmpt = prompt.hotswap(prmpt)
# Reload all other modules # Reload all other modules
imp.reload(nemubot)
imp.reload(nemubot.prompt)
nemubot.reload() nemubot.reload()
context = nemubot.hotswap(context)
prmpt = nemubot.prompt.hotswap(prmpt)
print("\033[1;32mContext reloaded\033[0m, now in Nemubot %s" % print("\033[1;32mContext reloaded\033[0m, now in Nemubot %s" %
nemubot.__version__) nemubot.__version__)
context.start()
except: except:
logger.exception("\033[1;31mUnable to reload the prompt due to " logger.exception("\033[1;31mUnable to reload the prompt due to "
"errors.\033[0m Fix them before trying to reload " "errors.\033[0m Fix them before trying to reload "
@ -143,5 +141,4 @@ if __name__ == "__main__":
context.quit() context.quit()
print("\nWaiting for other threads shuts down...") print("\nWaiting for other threads shuts down...")
sys.exit(0) sys.exit(0)

View File

@ -123,7 +123,7 @@ class Prompt:
print("") print("")
except EOFError: except EOFError:
print("quit") print("quit")
raise PromptReset("quit") return True
def hotswap(bak): def hotswap(bak):