3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-30 23:09:23 +01:00

main.py: catch ImportError nicely

This commit is contained in:
James Lu 2015-06-07 17:04:23 -07:00
parent 36a93320d7
commit 38df372471

View File

@ -67,8 +67,14 @@ class Irc():
# Here, we override the module lookup and import the plugins # Here, we override the module lookup and import the plugins
# dynamically depending on which were configured. # dynamically depending on which were configured.
for plugin in to_load: for plugin in to_load:
try:
moduleinfo = imp.find_module(plugin, plugins_folder) moduleinfo = imp.find_module(plugin, plugins_folder)
self.loaded.append(imp.load_source(plugin, moduleinfo[1])) self.loaded.append(imp.load_source(plugin, moduleinfo[1]))
except ImportError as e:
if str(e).startswith('No module named'):
print('Failed to load plugin %r: the plugin could not be found.' % plugin)
else:
print('Failed to load plugin %r: import error %s' (plugin, str(e)))
print("loaded plugins: %s" % self.loaded) print("loaded plugins: %s" % self.loaded)
if __name__ == '__main__': if __name__ == '__main__':