New builtin: refresh that doesn't shutdown modules but refresh kernel code
This commit is contained in:
parent
79251393ff
commit
010ca98ffd
@ -40,6 +40,8 @@ def parse_file(filename):
|
|||||||
try:
|
try:
|
||||||
parser.parse(open(filename, "r"))
|
parser.parse(open(filename, "r"))
|
||||||
return mod.root
|
return mod.root
|
||||||
|
except IOError:
|
||||||
|
return module_state.ModuleState("nemubotstate")
|
||||||
except:
|
except:
|
||||||
if mod.root is None:
|
if mod.root is None:
|
||||||
return module_state.ModuleState("nemubotstate")
|
return module_state.ModuleState("nemubotstate")
|
||||||
|
@ -27,7 +27,12 @@ if len(sys.argv) >= 2:
|
|||||||
print ("Nemubot ready, my PID is %i!" % (os.getpid()))
|
print ("Nemubot ready, my PID is %i!" % (os.getpid()))
|
||||||
while prompt.launch(servers):
|
while prompt.launch(servers):
|
||||||
try:
|
try:
|
||||||
|
if prompt.MODS is None:
|
||||||
imp.reload(prompt)
|
imp.reload(prompt)
|
||||||
|
else:
|
||||||
|
mods = prompt.MODS
|
||||||
|
imp.reload(prompt)
|
||||||
|
prompt.MODS = mods
|
||||||
except:
|
except:
|
||||||
print ("Unable to reload the prompt due to errors. Fix them before trying to reload the prompt.")
|
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()
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||||
|
13
prompt.py
13
prompt.py
@ -47,6 +47,10 @@ def getPS1():
|
|||||||
|
|
||||||
def launch(servers):
|
def launch(servers):
|
||||||
"""Launch the prompt"""
|
"""Launch the prompt"""
|
||||||
|
global MODS
|
||||||
|
if MODS is None:
|
||||||
|
MODS = list()
|
||||||
|
|
||||||
#Load messages module
|
#Load messages module
|
||||||
server.message.load(datas_path + "general.xml")
|
server.message.load(datas_path + "general.xml")
|
||||||
|
|
||||||
@ -77,6 +81,9 @@ def launch(servers):
|
|||||||
except:
|
except:
|
||||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||||
sys.stdout.write (traceback.format_exception_only(exc_type, exc_value)[0])
|
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
|
#Save and shutdown modules
|
||||||
for m in MODS:
|
for m in MODS:
|
||||||
m.save()
|
m.save()
|
||||||
@ -84,6 +91,7 @@ def launch(servers):
|
|||||||
m.close()
|
m.close()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
MODS = None
|
||||||
return ret == "reset"
|
return ret == "reset"
|
||||||
|
|
||||||
|
|
||||||
@ -438,7 +446,9 @@ def zap(cmds, servers):
|
|||||||
|
|
||||||
def end(cmds, servers):
|
def end(cmds, servers):
|
||||||
"""Quit the prompt for reload or exit"""
|
"""Quit the prompt for reload or exit"""
|
||||||
if cmds[0] == "reset":
|
if cmds[0] == "refresh":
|
||||||
|
return "refresh"
|
||||||
|
elif cmds[0] == "reset":
|
||||||
return "reset"
|
return "reset"
|
||||||
else:
|
else:
|
||||||
for srv in servers.keys():
|
for srv in servers.keys():
|
||||||
@ -450,6 +460,7 @@ CAPS = {
|
|||||||
'quit': end, #Disconnect all server and quit
|
'quit': end, #Disconnect all server and quit
|
||||||
'exit': end, #Alias for quit
|
'exit': end, #Alias for quit
|
||||||
'reset': end, #Reload the prompt
|
'reset': end, #Reload the prompt
|
||||||
|
'refresh': end, #Reload the prompt but save modules
|
||||||
'load': load, #Load a servers or module configuration file
|
'load': load, #Load a servers or module configuration file
|
||||||
'hotswap': hotswap, #Reload the server class without closing the socket
|
'hotswap': hotswap, #Reload the server class without closing the socket
|
||||||
'close': close, #Disconnect and remove a server from the list
|
'close': close, #Disconnect and remove a server from the list
|
||||||
|
Loading…
Reference in New Issue
Block a user