Pass config to plugin, but only if it has a section for the plugin

This commit is contained in:
3onyc 2013-12-10 08:57:47 +01:00
parent 23c586e616
commit d6e1da7073
3 changed files with 11 additions and 5 deletions

View File

@ -150,7 +150,7 @@ def parseArguments(argv):
if not args.logfile and configs.has_option('settings', 'logfile'):
args.logfile = configs.get('settings', 'logfile')
return args
return args, configs
def should_ignore(fileName, patterns):
@ -244,7 +244,7 @@ def send_action(project=None, branch=None, stats={}, key=None, targetFile=None,
def main(argv=None):
if not argv:
argv = sys.argv
args = parseArguments(argv)
args, config = parseArguments(argv)
setup_logging(args, __version__)
ignore = should_ignore(args.targetFile, args.ignore)
if ignore is not False:
@ -254,7 +254,7 @@ def main(argv=None):
branch = None
name = None
stats = get_file_stats(args.targetFile)
project = find_project(args.targetFile, args.config)
project = find_project(args.targetFile, config)
if project:
branch = project.branch()
name = project.name()

View File

@ -32,7 +32,12 @@ PLUGINS = [
def find_project(path, config):
for plugin in PLUGINS:
project = plugin(path)
plugin_name = plugin.__name__.lower()
if config.has_section(plugin_name):
plugin_config = config
else:
plugin_config = None
project = plugin(path, plugin_config)
if project.process():
return project
return None

View File

@ -22,8 +22,9 @@ class BaseProject(object):
be found for the current path.
"""
def __init__(self, path):
def __init__(self, path, config):
self.path = path
self.config = config
def type(self):
""" Returns None if this is the base class.