New builtin: refresh that doesn't shutdown modules but refresh kernel code

This commit is contained in:
Némunaire 2012-07-10 12:14:11 +02:00
parent 79251393ff
commit 010ca98ffd
3 changed files with 20 additions and 2 deletions

View File

@ -40,6 +40,8 @@ def parse_file(filename):
try:
parser.parse(open(filename, "r"))
return mod.root
except IOError:
return module_state.ModuleState("nemubotstate")
except:
if mod.root is None:
return module_state.ModuleState("nemubotstate")

View File

@ -27,7 +27,12 @@ if len(sys.argv) >= 2:
print ("Nemubot ready, my PID is %i!" % (os.getpid()))
while prompt.launch(servers):
try:
if prompt.MODS is None:
imp.reload(prompt)
else:
mods = prompt.MODS
imp.reload(prompt)
prompt.MODS = mods
except:
print ("Unable to reload the prompt due to errors. Fix them before trying to reload the prompt.")
exc_type, exc_value, exc_traceback = sys.exc_info()

View File

@ -47,6 +47,10 @@ def getPS1():
def launch(servers):
"""Launch the prompt"""
global MODS
if MODS is None:
MODS = list()
#Load messages module
server.message.load(datas_path + "general.xml")
@ -77,6 +81,9 @@ def launch(servers):
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
sys.stdout.write (traceback.format_exception_only(exc_type, exc_value)[0])
#Don't shutdown at refresh
if ret == "refresh":
return True
#Save and shutdown modules
for m in MODS:
m.save()
@ -84,6 +91,7 @@ def launch(servers):
m.close()
except AttributeError:
pass
MODS = None
return ret == "reset"
@ -185,7 +193,7 @@ def load_module_from_name(name, servers, config=None):
break
if not exitsts:
MODS.append(mod)
except AttributeError:
except AttributeError :
print (" Module `%s' is not a nemubot module." % name)
for srv in servers:
servers[srv].update_mods(MODS)
@ -438,7 +446,9 @@ def zap(cmds, servers):
def end(cmds, servers):
"""Quit the prompt for reload or exit"""
if cmds[0] == "reset":
if cmds[0] == "refresh":
return "refresh"
elif cmds[0] == "reset":
return "reset"
else:
for srv in servers.keys():
@ -450,6 +460,7 @@ CAPS = {
'quit': end, #Disconnect all server and quit
'exit': end, #Alias for quit
'reset': end, #Reload the prompt
'refresh': end, #Reload the prompt but save modules
'load': load, #Load a servers or module configuration file
'hotswap': hotswap, #Reload the server class without closing the socket
'close': close, #Disconnect and remove a server from the list