def __init__(self, option, name=None, parent=None, user=None): StatsGroup.__init__(self, option, name, parent, user) config = dict(Config().section(option)) # Check Sentry url if "url" not in config: raise ConfigError("No url set in the [{0}] section".format(option)) # Check Sentry organization if "organization" not in config: raise ConfigError( "No organization set in the [{0}] section".format(option)) # Check Sentry token if "token" not in config: raise ConfigError( "No token set in the [{0}] section".format(option)) # Set up the Sentry API sentry = SentryAPI(config=config) # Construct the list of stats self.stats = [ ResolvedIssues(sentry=sentry, option=option + '-resolved', parent=self), CommentedIssues(sentry=sentry, option=option + '-commented', parent=self), ]
def detect(): """ Detect available plugins and return enabled/configured stats Yields tuples of the form (section, statsgroup) sorted by the default StatsGroup order which maybe overriden in the config file. The 'section' is the name of the configuration section as well as the option used to enable those particular stats. """ # Load plugins and config plugins = load() config = Config() # Make sure that all sections have a valid plugin type defined for section in config.sections(): if section == 'general': continue try: type_ = config.item(section, 'type') except ConfigError: raise ConfigError( "Plugin type not defined in section '{0}'.".format(section)) if type_ not in plugins: raise ConfigError( "Invalid plugin type '{0}' in section '{1}'.".format( type_, section)) # Detect classes inherited from StatsGroup and return them sorted stats = [] for plugin in plugins: module = getattr(PLUGINS, plugin) for object_name in dir(module): statsgroup = getattr(module, object_name) # Filter out anything except for StatsGroup descendants if (not isinstance(statsgroup, (type, types.ClassType)) or not issubclass(statsgroup, StatsGroup) or statsgroup is StatsGroup or statsgroup is EmptyStatsGroup): continue # Search config for sections with type matching the plugin, # use order provided there or class default otherwise for section in config.sections(kind=plugin): try: order = int(config.item(section, "order")) except ConfigError: order = statsgroup.order except ValueError: log.warn("Invalid {0} stats order: '{1}'".format( section, config.item(section, "order"))) order = statsgroup.order stats.append((section, statsgroup, order)) log.info("Found {0}, an instance of {1}, order {2}".format( section, statsgroup.__name__, order)) # Custom stats are handled with a single instance if statsgroup.__name__ == "CustomStats": break for section, statsgroup, _ in sorted(stats, key=lambda x: x[2]): yield section, statsgroup
def __init__(self, option, name=None, parent=None, user=None): StatsGroup.__init__(self, option, name, parent, user) # Check config for required fields config = dict(Config().section(option)) for field in ['url', 'organization', 'token']: if field not in config: raise ConfigError( "No {0} set in the [{1}] section".format(field, option)) # Set up the Sentry API and construct the list of stats self.sentry = Sentry(config=config, stats=self) self.stats = [ ResolvedIssues(option=option + '-resolved', parent=self), CommentedIssues(option=option + '-commented', parent=self), ]
def __init__(self, option, name=None, parent=None, user=None): """ Process config, prepare investigator, construct stats """ # Check Request Tracker instance url and custom prefix super(BitlyStats, self).__init__(option, name, parent, user) config = dict(Config().section(option)) try: self.token = config["token"] except KeyError: raise ConfigError("No token in the [{0}] section".format(option)) self.bitly = Bitly(parent=self) # Construct the list of stats self.stats = [ SavedLinks(option=option + "-saved", parent=self), ]
def __init__(self, parent, token=None): """ Initialize bit.ly OAuth Connection """ self.parent = parent self.token = token or getattr(parent, 'token') if not self.token: raise ConfigError("bitly requires token to be defined in config")