Beispiel #1
0
 def test_ini_config_get_authoritative(self):
     cfg = INIConfig('conf/test.ini')
     self.assertEquals(
         cfg.get_authoritative(),
         {'ocupado.plugin.test': {
             'class': 'Test',
             'kwargs': {'key': 'value'}}})
Beispiel #2
0
 def test_ini_config_list_outputs(self):
     cfg = INIConfig('conf/test.ini')
     self.assertEquals(
         cfg.list_outputs(),
         {'ocupado.output.test': {
             'class': 'Test',
             'kwargs': {'key': ['value', 'value2']}}})
Beispiel #3
0
 def test_ini_config_load_equate_users_with_no_section(self):
     cfg = INIConfig('conf/test.ini')
     cfg._cp.remove_section('equate_users')
     self.assertIsNone(cfg.load_equate_users())
     self.assertEquals(cfg._user_equate_mapping, {})
Beispiel #4
0
 def test_ini_config_load_equate_users(self):
     cfg = INIConfig('conf/test.ini')
     self.assertIsNone(cfg.load_equate_users())
     self.assertEquals(cfg._user_equate_mapping, {'alias': 'test'})
Beispiel #5
0
 def test_ini_config_load_ignored_users_with_no_section(self):
     cfg = INIConfig('conf/test.ini')
     cfg._cp.remove_section('ignored_users')
     self.assertIsNone(cfg.load_ignored_users())
     self.assertEquals(cfg.ignored_users, [])
Beispiel #6
0
 def test_ini_config_load_ignored_users(self):
     cfg = INIConfig('conf/test.ini')
     self.assertIsNone(cfg.load_ignored_users())
     self.assertEquals(cfg.ignored_users, ['ignoreme'])
Beispiel #7
0
 def test_ini_config_list_plugins(self):
     cfg = INIConfig('conf/test.ini')
     self.assertEquals(
         cfg.list_plugins(),
         {'ocupado.plugin.test': {
             'class': 'Test', 'kwargs': {'key': 'value'}}})
Beispiel #8
0
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.')