rana-cli/wakatime/project.py
Alan Hamlett 297ebb902b updates to project plugins:
- force projects to return unicode names and branches, or None
 - refactor ProjectMap to set project name from cfg file
 - pass configs to find_project() as dict from plugin's cfg section
 - clean up git project class

updates to config file:

 - rename ~/.wakatime.conf to ~/.wakatime.cfg
 - better error handling while parsing and getting configs
 - no longer need to set defaults when parsing config file
 - use configparser for python3 when python2 import fails
2013-12-13 14:46:39 +01:00

45 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
"""
wakatime.project
~~~~~~~~~~~~~~~~
Returns a project for the given file.
:copyright: (c) 2013 Alan Hamlett.
:license: BSD, see LICENSE for more details.
"""
import logging
import os
from .projects.git import Git
from .projects.mercurial import Mercurial
from .projects.projectmap import ProjectMap
from .projects.subversion import Subversion
from .projects.wakatime import WakaTime
log = logging.getLogger(__name__)
# List of plugin classes to find a project for the current file path.
# Project plugins will be processed with priority in the order below.
PLUGINS = [
WakaTime,
ProjectMap,
Git,
Mercurial,
Subversion,
]
def find_project(path, configs=None):
for plugin in PLUGINS:
plugin_name = plugin.__name__.lower()
plugin_configs = None
if configs and configs.has_section(plugin_name):
plugin_configs = dict(configs.items(plugin_name))
project = plugin(path, configs=plugin_configs)
if project.process():
return project
return None