def test_plugin_manager_set_up_authoritative(self): pm = PluginManager() pm._load_plugin('ocupado.plugin.test', 'Test') pm.set_up_authoritative({ 'ocupado.plugin.test': { 'class': 'Test', 'kwargs': {'key': 'value'}}}) self.assertTrue(pm._authoritative_instance)
def test_plugin_manager_set_up_outputs(self): pm = PluginManager() pm._load_plugin('ocupado.output.test', 'Test') pm.set_up_outputs({ 'ocupado.output.test': { 'class': 'Test', 'kwargs': {}}}) self.assertEquals(len(pm._output_instances), 1)
def test_plugin_manager_set_up_plugins(self): pm = PluginManager() pm._load_plugin('ocupado.plugin.test', 'Test') pm.set_up_plugins({ 'ocupado.plugin.test': { 'class': 'Test', 'kwargs': {'key': 'value'}}}) self.assertEquals(len(pm._instances), 1)
def test_plugin_manager_set_up_plugin(self): pm = PluginManager() pm._load_plugin('ocupado.plugin.test', 'Test') pm.set_up_plugin('ocupado.plugin.test:Test', {'key': 'val'}) self.assertEquals(len(pm._instances), 1)
def test_plugin_manager__load_plugin(self): pm = PluginManager() pm._load_plugin('ocupado.plugin.test', 'Test') self.assertEquals(len(pm._plugins), 1)
def main(): """ Handler for the CLI interface. """ if int(platform.python_version_tuple()[0]) == 2: parser = argparse.ArgumentParser(version=__version__) else: parser = argparse.ArgumentParser() parser.add_argument( 'config', metavar='CONFIG', type=str, nargs=1, help='Path to the config file.') parser.add_argument( '-V', '--verbose', action='store_true', help='Enables verbose output.') args = parser.parse_args() conf = INIConfig(args.config[0]) conf.load_ignored_users() conf.load_equate_users() # Load plugins for use plugin_manager = PluginManager() plugin_manager.set_up_authoritative(conf.authoritative) plugin_manager.set_up_outputs(conf.outputs) plugin_manager.load_dict(conf.plugins) if args.verbose: print('- Plugins loaded: %s' % plugin_manager.plugins.keys()) plugin_manager.set_up_plugins(conf.plugins) if args.verbose: print('- Plugins initialized: %s' % plugin_manager.instances.keys()) unmatched = [] # Run through all the plugin instances looking for users for name in plugin_manager.instances: if args.verbose: print('- Authenticating for plugin %s' % name) plugin_manager.instances[name].authenticate() if args.verbose: print('- Getting users for plugin %s' % name) for username in plugin_manager.instances[name].get_all_usernames(): real_username = conf.user_equate(username) if real_username != username and args.verbose: print('- Username %s equates to %s' % ( username, real_username)) if (username not in conf.ignored_users and real_username not in conf.ignored_users): exists, details = plugin_manager.authoritative_instance.exists( real_username) if exists is False: if args.verbose: print( '- Could not find user %s in the authoritative ' 'plugin' % real_username) unmatched.append(real_username) else: if args.verbose: print( '- User %s is in the ignored list.' % username) # Be nice citizens and logout if args.verbose: print('- Logging out of plugin %s' % name) plugin_manager.instances[name].logout() if unmatched: # Output the results through an output plugin for output_name in plugin_manager.output_instances: print('- Notifying via %s for: %s' % (output_name, unmatched)) plugin_manager.output_instances[output_name].notify(unmatched) else: print('- No unmatched users.')