From d6e1da707361ecdf25138f77aa06076589ee4008 Mon Sep 17 00:00:00 2001 From: 3onyc <3onyc@x3tech.com> Date: Tue, 10 Dec 2013 08:57:47 +0100 Subject: [PATCH] Pass config to plugin, but only if it has a section for the plugin --- wakatime/__init__.py | 6 +++--- wakatime/project.py | 7 ++++++- wakatime/projects/base.py | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/wakatime/__init__.py b/wakatime/__init__.py index 2e31bde..c6fa21f 100644 --- a/wakatime/__init__.py +++ b/wakatime/__init__.py @@ -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() diff --git a/wakatime/project.py b/wakatime/project.py index e158d13..9f93790 100644 --- a/wakatime/project.py +++ b/wakatime/project.py @@ -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 diff --git a/wakatime/projects/base.py b/wakatime/projects/base.py index 8e1b7a5..22426c6 100644 --- a/wakatime/projects/base.py +++ b/wakatime/projects/base.py @@ -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.