Add support for subdirectories in the plugins directory.
svn: r11631
This commit is contained in:
parent
b77c14b74a
commit
a6fa59cc35
@ -123,34 +123,36 @@ class PluginManager(gen.utils.Callback):
|
|||||||
if not os.path.isdir(direct):
|
if not os.path.isdir(direct):
|
||||||
return False # return value is True for error
|
return False # return value is True for error
|
||||||
|
|
||||||
# if the path has not already been loaded, save it in the loaddir_list
|
|
||||||
# list for use on reloading
|
|
||||||
|
|
||||||
if direct not in self.__loaddir_list:
|
|
||||||
self.__loaddir_list.append(direct)
|
|
||||||
|
|
||||||
# add the directory to the python search path
|
|
||||||
sys.path.append(direct)
|
|
||||||
|
|
||||||
pymod = re.compile(r"^(.*)\.py$")
|
pymod = re.compile(r"^(.*)\.py$")
|
||||||
|
|
||||||
# loop through each file in the directory, looking for files that
|
# loop through each file in the directory, looking for files that
|
||||||
# have a .py extention, and attempt to load the file. If it succeeds,
|
# have a .py extention, and attempt to load the file. If it succeeds,
|
||||||
# add it to the success_list list. If it fails, add it to the _failure
|
# add it to the success_list list. If it fails, add it to the _failure
|
||||||
# list
|
# list
|
||||||
|
|
||||||
for filename in os.listdir(direct):
|
for (dirpath, dirnames, filenames) in os.walk(direct):
|
||||||
name = os.path.split(filename)
|
|
||||||
match = pymod.match(name[1])
|
# add the directory to the python search path
|
||||||
if not match:
|
sys.path.append(dirpath)
|
||||||
continue
|
|
||||||
self.__attempt_list.append(filename)
|
# if the path has not already been loaded, save it in the
|
||||||
plugin = match.groups()[0]
|
# loaddir_list list for use on reloading.
|
||||||
try:
|
if dirpath not in self.__loaddir_list:
|
||||||
_module = __import__(plugin)
|
self.__loaddir_list.append(dirpath)
|
||||||
self.__success_list.append((filename, _module))
|
|
||||||
except:
|
for filename in filenames:
|
||||||
self.__failmsg_list.append((filename, sys.exc_info()))
|
name = os.path.split(filename)
|
||||||
|
match = pymod.match(name[1])
|
||||||
|
if not match:
|
||||||
|
continue
|
||||||
|
self.__attempt_list.append(filename)
|
||||||
|
plugin = match.groups()[0]
|
||||||
|
try:
|
||||||
|
_module = __import__(plugin)
|
||||||
|
self.__success_list.append((filename, _module))
|
||||||
|
except:
|
||||||
|
self.__failmsg_list.append((filename, sys.exc_info()))
|
||||||
|
|
||||||
return len(self.__failmsg_list) != 0 # return True if there are errors
|
return len(self.__failmsg_list) != 0 # return True if there are errors
|
||||||
|
|
||||||
def reload_plugins(self):
|
def reload_plugins(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user