def setup(self): """Set up the Sopel instance.""" load_success = 0 load_error = 0 load_disabled = 0 stderr("Welcome to Sopel. Loading modules...") usable_plugins = plugins.get_usable_plugins(self.config) for name, info in usable_plugins.items(): plugin, is_enabled = info if not is_enabled: load_disabled = load_disabled + 1 continue try: plugin.load() except Exception as e: load_error = load_error + 1 filename, lineno = tools.get_raising_file_and_line() rel_path = os.path.relpath(filename, os.path.dirname(__file__)) raising_stmt = "%s:%d" % (rel_path, lineno) stderr("Error loading %s: %s (%s)" % (name, e, raising_stmt)) else: try: if plugin.has_setup(): plugin.setup(self) plugin.register(self) except Exception as e: load_error = load_error + 1 filename, lineno = tools.get_raising_file_and_line() rel_path = os.path.relpath(filename, os.path.dirname(__file__)) raising_stmt = "%s:%d" % (rel_path, lineno) stderr("Error in %s setup procedure: %s (%s)" % (name, e, raising_stmt)) else: load_success = load_success + 1 print('Loaded: %s' % name) total = sum([load_success, load_error, load_disabled]) if total and load_success: stderr('Registered %d modules' % (load_success - 1)) stderr('%d modules failed to load' % load_error) stderr('%d modules disabled' % load_disabled) else: stderr("Warning: Couldn't load any modules")
def setup(self): stderr("\nWelcome to Sopel. Loading modules...\n\n") modules = sopel.loader.enumerate_modules(self.config) error_count = 0 success_count = 0 for name in modules: path, type_ = modules[name] try: module, _ = sopel.loader.load_module(name, path, type_) except Exception as e: error_count = error_count + 1 filename, lineno = tools.get_raising_file_and_line() rel_path = os.path.relpath(filename, os.path.dirname(__file__)) raising_stmt = "%s:%d" % (rel_path, lineno) stderr("Error loading %s: %s (%s)" % (name, e, raising_stmt)) else: try: if hasattr(module, 'setup'): module.setup(self) relevant_parts = sopel.loader.clean_module( module, self.config) except Exception as e: error_count = error_count + 1 filename, lineno = tools.get_raising_file_and_line() rel_path = os.path.relpath( filename, os.path.dirname(__file__) ) raising_stmt = "%s:%d" % (rel_path, lineno) stderr("Error in %s setup procedure: %s (%s)" % (name, e, raising_stmt)) else: self.register(*relevant_parts) success_count += 1 if len(modules) > 1: # coretasks is counted stderr('\n\nRegistered %d modules,' % (success_count - 1)) stderr('%d modules failed to load\n\n' % error_count) else: stderr("Warning: Couldn't load any modules")
def _load(bot, plugin): # handle errors while loading (if any) try: plugin.load() if plugin.has_setup(): plugin.setup(bot) plugin.register(bot) except Exception as e: filename, lineno = tools.get_raising_file_and_line() rel_path = os.path.relpath(filename, os.path.dirname(__file__)) raising_stmt = "%s:%d" % (rel_path, lineno) tools.stderr( "Error loading %s: %s (%s)" % (plugin.name, e, raising_stmt)) raise
def setup(self): stderr( u"\nXeniBot será ejecutado en la red y canales indicados. Leyendo módulos...\n\n" ) self.callables = set() self.shutdown_methods = set() filenames = self.config.enumerate_modules() # Coretasks is special. No custom user coretasks. this_dir = os.path.dirname(os.path.abspath(__file__)) filenames['coretasks'] = os.path.join(this_dir, 'coretasks.py') modules = [] error_count = 0 for name, filename in filenames.iteritems(): try: module = imp.load_source(name, filename) except Exception, e: error_count = error_count + 1 filename, lineno = tools.get_raising_file_and_line() rel_path = os.path.relpath(filename, os.path.dirname(__file__)) raising_stmt = "%s:%d" % (rel_path, lineno) stderr("Error loading %s: %s (%s)" % (name, e, raising_stmt)) else: try: if hasattr(module, 'setup'): module.setup(self) self.register(vars(module)) modules.append(name) except Exception, e: error_count = error_count + 1 filename, lineno = tools.get_raising_file_and_line() rel_path = os.path.relpath(filename, os.path.dirname(__file__)) raising_stmt = "%s:%d" % (rel_path, lineno) stderr(u"Error in the configuration protocol %s: %s (%s)" % (name, e, raising_stmt))
def _plugins_wizard(settings): usable_plugins = plugins.get_usable_plugins(settings) for plugin, is_enabled in usable_plugins.values(): if not is_enabled: # Do not configure non-enabled modules continue name = plugin.name try: _plugin_wizard(settings, plugin) except Exception as e: filename, lineno = tools.get_raising_file_and_line() rel_path = os.path.relpath(filename, os.path.dirname(__file__)) raising_stmt = "%s:%d" % (rel_path, lineno) tools.stderr("Error loading %s: %s (%s)" % (name, e, raising_stmt))
def _plugins_wizard(settings): usable_plugins = plugins.get_usable_plugins(settings) for plugin, is_enabled in usable_plugins.values(): if not is_enabled: # Do not configure non-enabled modules continue name = plugin.name try: _plugin_wizard(settings, plugin) except Exception as e: filename, lineno = tools.get_raising_file_and_line() rel_path = os.path.relpath(filename, os.path.dirname(__file__)) raising_stmt = "%s:%d" % (rel_path, lineno) tools.stderr("Error loading %s: %s (%s)" % (name, e, raising_stmt))