correct priority for project detection
Priority of project detection: 1. .wakatime-project file 2. [project_map] section in .wakatime.cfg INI file 3. --project arg 3. revision control directory name 5. --alternate-project arg
This commit is contained in:
parent
006bab2d71
commit
e8bd8bba76
3 changed files with 59 additions and 27 deletions
|
@ -34,7 +34,7 @@ from .offlinequeue import Queue
|
||||||
from .packages import argparse
|
from .packages import argparse
|
||||||
from .packages import simplejson as json
|
from .packages import simplejson as json
|
||||||
from .packages.requests.exceptions import RequestException
|
from .packages.requests.exceptions import RequestException
|
||||||
from .project import find_project
|
from .project import get_project_info
|
||||||
from .session_cache import SessionCache
|
from .session_cache import SessionCache
|
||||||
from .stats import get_file_stats
|
from .stats import get_file_stats
|
||||||
try:
|
try:
|
||||||
|
@ -443,20 +443,12 @@ def main(argv=None):
|
||||||
stats = get_file_stats(args.targetFile, notfile=args.notfile,
|
stats = get_file_stats(args.targetFile, notfile=args.notfile,
|
||||||
lineno=args.lineno, cursorpos=args.cursorpos)
|
lineno=args.lineno, cursorpos=args.cursorpos)
|
||||||
|
|
||||||
project = None
|
project, branch = None, None
|
||||||
if not args.notfile:
|
if not args.notfile:
|
||||||
project = find_project(args.targetFile, configs=configs)
|
project, branch = get_project_info(configs=configs, args=args)
|
||||||
branch = None
|
|
||||||
project_name = args.project
|
|
||||||
if project:
|
|
||||||
branch = project.branch()
|
|
||||||
if not project_name:
|
|
||||||
project_name = project.name()
|
|
||||||
if not project_name:
|
|
||||||
project_name = args.alternate_project
|
|
||||||
|
|
||||||
kwargs = vars(args)
|
kwargs = vars(args)
|
||||||
kwargs['project'] = project_name
|
kwargs['project'] = project
|
||||||
kwargs['branch'] = branch
|
kwargs['branch'] = branch
|
||||||
kwargs['stats'] = stats
|
kwargs['stats'] = stats
|
||||||
|
|
||||||
|
|
|
@ -15,30 +15,70 @@ from .projects.git import Git
|
||||||
from .projects.mercurial import Mercurial
|
from .projects.mercurial import Mercurial
|
||||||
from .projects.projectmap import ProjectMap
|
from .projects.projectmap import ProjectMap
|
||||||
from .projects.subversion import Subversion
|
from .projects.subversion import Subversion
|
||||||
from .projects.wakatime import WakaTime
|
from .projects.wakatime_project_file import WakaTimeProjectFile
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger('WakaTime')
|
log = logging.getLogger('WakaTime')
|
||||||
|
|
||||||
|
|
||||||
# List of plugin classes to find a project for the current file path.
|
# List of plugin classes to find a project for the current file path.
|
||||||
# Project plugins will be processed with priority in the order below.
|
CONFIG_PLUGINS = [
|
||||||
PLUGINS = [
|
WakaTimeProjectFile,
|
||||||
WakaTime,
|
|
||||||
ProjectMap,
|
ProjectMap,
|
||||||
|
]
|
||||||
|
REV_CONTROL_PLUGINS = [
|
||||||
Git,
|
Git,
|
||||||
Mercurial,
|
Mercurial,
|
||||||
Subversion,
|
Subversion,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def find_project(path, configs=None):
|
def get_project_info(configs=None, args=None):
|
||||||
for plugin in PLUGINS:
|
"""Find the current project and branch.
|
||||||
plugin_name = plugin.__name__.lower()
|
|
||||||
plugin_configs = None
|
First looks for a .wakatime-project file. Second, uses the --project arg.
|
||||||
if configs and configs.has_section(plugin_name):
|
Third, uses the folder name from a revision control repository. Last, uses
|
||||||
plugin_configs = dict(configs.items(plugin_name))
|
the --alternate-project arg.
|
||||||
project = plugin(path, configs=plugin_configs)
|
|
||||||
|
Returns a project, branch tuple.
|
||||||
|
"""
|
||||||
|
|
||||||
|
project_name, branch_name = None, None
|
||||||
|
|
||||||
|
for plugin_cls in CONFIG_PLUGINS:
|
||||||
|
|
||||||
|
plugin_name = plugin_cls.__name__.lower()
|
||||||
|
plugin_configs = get_configs_for_plugin(plugin_name, configs)
|
||||||
|
|
||||||
|
project = plugin_cls(args.targetFile, configs=plugin_configs)
|
||||||
if project.process():
|
if project.process():
|
||||||
return project
|
project_name = project.name()
|
||||||
|
branch_name = project.branch()
|
||||||
|
break
|
||||||
|
|
||||||
|
if project_name is None:
|
||||||
|
project_name = args.project
|
||||||
|
|
||||||
|
if project_name is None or branch_name is None:
|
||||||
|
|
||||||
|
for plugin_cls in REV_CONTROL_PLUGINS:
|
||||||
|
|
||||||
|
plugin_name = plugin_cls.__name__.lower()
|
||||||
|
plugin_configs = get_configs_for_plugin(plugin_name, configs)
|
||||||
|
|
||||||
|
project = plugin_cls(args.targetFile, configs=plugin_configs)
|
||||||
|
if project.process():
|
||||||
|
project_name = project_name or project.name()
|
||||||
|
branch_name = branch_name or project.branch()
|
||||||
|
break
|
||||||
|
|
||||||
|
if project_name is None:
|
||||||
|
project_name = args.alternate_project
|
||||||
|
|
||||||
|
return project_name, branch_name
|
||||||
|
|
||||||
|
|
||||||
|
def get_configs_for_plugin(plugin_name, configs):
|
||||||
|
if configs and configs.has_section(plugin_name):
|
||||||
|
return dict(configs.items(plugin_name))
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
wakatime.projects.wakatime
|
wakatime.projects.wakatime_project_file
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Information from a .wakatime-project file about the project for
|
Information from a .wakatime-project file about the project for
|
||||||
a given file. First line of .wakatime-project sets the project
|
a given file. First line of .wakatime-project sets the project
|
||||||
|
@ -21,7 +21,7 @@ from ..compat import u, open
|
||||||
log = logging.getLogger('WakaTime')
|
log = logging.getLogger('WakaTime')
|
||||||
|
|
||||||
|
|
||||||
class WakaTime(BaseProject):
|
class WakaTimeProjectFile(BaseProject):
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
self.config = self._find_config(self.path)
|
self.config = self._find_config(self.path)
|
Loading…
Reference in a new issue