From e2463a4f26090be4653b61825d582941aaed2306 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Nov 23 2015 14:07:24 +0000 Subject: get the list of all the active services --- diff --git a/bugyou_plugins/plugins/base.py b/bugyou_plugins/plugins/base.py index 36e281d..600642e 100644 --- a/bugyou_plugins/plugins/base.py +++ b/bugyou_plugins/plugins/base.py @@ -13,6 +13,7 @@ class BasePlugin(object): def __init__(self, *args, **kwargs): filepath = '/etc/bugyou/bugyou_plugins.cfg' self.config = load_config(filepath) + self.active_services = get_active_services(self) def initialize(self): self.init_retask_connection() @@ -38,8 +39,14 @@ class BasePlugin(object): def load_services(self): """ Load the services for the plugin """ - raise NotImplementedError() + services = self.config.get(self.plugin_name, 'services') + for service in services: + self.services.append(self.active_services[serivce].load()) @abc.abstractmethod def process(self): """ Consumes the messages from retask """ + + @abc.abstractmethod + def do_pagure(self): + """ Override to do activity related to pagure """ diff --git a/bugyou_plugins/utility.py b/bugyou_plugins/utility.py index 3b72520..97e08e9 100644 --- a/bugyou_plugins/utility.py +++ b/bugyou_plugins/utility.py @@ -1,8 +1,21 @@ import ConfigParser +import pkg_resources + def load_config(filepath): + """ Load the configuration file """ if not os.path.exists(name): raise Exception('Please add a proper cofig file under /etc/bugyou') config = ConfigParser.RawConfigParser() return config.read(name) + +def get_active_services(): + """ Returns a dictionary with all the currently active services """ + for entry_point in pkg_resources.iter_entry_points('bugyou.plugin'): + service_klass = entry_point.module_name + service_name = entry_point.name + active_services[service_name] = service_klass + + return active_services +