Add the ability to reload submodule or a module part after a import reload (useful for reload imports of this module)

This commit is contained in:
Némunaire 2012-07-03 04:13:10 +02:00
parent d37aeeda4c
commit b4b24c4543
6 changed files with 29 additions and 10 deletions

View File

@ -68,7 +68,7 @@ def parseanswer (msg):
def parseask (msg):
global ALIAS
if re.match(".*(set|cr[ée]{2}|nouvel(le)?) alias.*", msg.content) is not None:
result = re.match(".*alias !?([a-zA-Z0-9_-]+) (pour|=|:) (.+)$", msg.content)
result = re.match(".*alias !?([^ ]+) (pour|=|:) (.+)$", msg.content)
if result.group(1) in DATAS.getNode("aliases").index or result.group(3).find("alias") >= 0:
msg.send_snd("Cet alias est déjà défini.")
else:

View File

@ -1,8 +1,10 @@
# coding=utf-8
import imp
nemubotversion = 3.0
from .DDGSearch import DDGSearch
from . import DDGSearch
from . import WFASearch
lastSearch = dict()
@ -11,6 +13,10 @@ def load():
global CONF
WFASearch.CONF = CONF
def reload():
imp.reload(DDGSearch)
imp.reload(WFASearch)
def parseanswer(msg):
global lastSearch
req = None
@ -30,11 +36,12 @@ def parseanswer(msg):
if len(msg.cmd) > 1:
if req == "wfa":
s = WFASearch.WFASearch(' '.join(msg.cmd[1:]))
#print (s.wfares)
if not s.success:
msg.send_chn("An error occurs during computation")
msg.send_chn(s.error)
return True
else:
s = DDGSearch(' '.join(msg.cmd[1:]))
s = DDGSearch.DDGSearch(' '.join(msg.cmd[1:]))
if req == "def":
msg.send_chn(s.definition)

View File

@ -1,5 +1,6 @@
# coding=utf-8
import imp
import re
import sys
from datetime import timedelta
@ -7,10 +8,10 @@ from datetime import datetime
import time
import threading
from module_state import ModuleState
nemubotversion = 3.0
from module_state import ModuleState
from . import Manager
def help_tiny ():
@ -32,6 +33,9 @@ def load():
threadManager = Manager.Manager(DATAS, SRVS)
threadManager.start()
def reload():
imp.reload(Manager)
def close():
global threadManager
if threadManager is not None:

View File

@ -2,6 +2,7 @@
import http.client
import threading
import re
class Tinyfier(threading.Thread):
def __init__(self, url, msg):

View File

@ -1,10 +1,11 @@
# coding=utf-8
import http.client
import imp
import re
import sys
from .Tinyfier import Tinyfier
from . import Tinyfier
nemubotversion = 3.0
@ -13,8 +14,10 @@ def help_tiny ():
return "Gets YCC urls"
def help_full ():
return "TODO"
return "!ycc [<url>]: with an argument, reduce the given <url> thanks to ycc.fr; without argument, reduce the last URL said on the current channel."
def reload():
imp.reload(Tinyfier)
def parseanswer(msg):
global LAST_URLS
@ -22,14 +25,14 @@ def parseanswer(msg):
if len(msg.cmd) == 1:
if msg.channel in LAST_URLS and len(LAST_URLS[msg.channel]) > 0:
url = LAST_URLS[msg.channel].pop()
t = Tinyfier(url, msg)
t = Tinyfier.Tinyfier(url, msg)
t.start()
else:
msg.send_chn("%s: je n'ai pas d'autre URL reduire" % msg.sender)
else:
if len(msg.cmd) < 6:
for url in msg.cmd[1:]:
t = Tinyfier(url, msg)
t = Tinyfier.Tinyfier(url, msg)
t.start()
else:
msg.send_chn("%s: je ne peux pas réduire autant d'URL d'un seul coup." % msg.sender)

View File

@ -120,6 +120,10 @@ def load_module_from_name(name, servers, config=None):
if md.name == name:
mod = imp.reload(md)
loaded = True
try:
mod.reload()
except AttributeError:
pass
break
if not loaded:
mod = __import__(name)