upgrade wakatime cli to v4.1.0

This commit is contained in:
Alan Hamlett 2015-06-29 19:47:04 -07:00
parent 7ee7de70d5
commit f0b518862a
4 changed files with 60 additions and 28 deletions

View File

@ -1,7 +1,7 @@
__title__ = 'wakatime'
__description__ = 'Common interface to the WakaTime api.'
__url__ = 'https://github.com/wakatime/wakatime'
__version_info__ = ('4', '0', '16')
__version_info__ = ('4', '1', '0')
__version__ = '.'.join(__version_info__)
__author__ = 'Alan Hamlett'
__author_email__ = 'alan@wakatime.com'

View File

@ -34,7 +34,7 @@ from .offlinequeue import Queue
from .packages import argparse
from .packages import simplejson as json
from .packages.requests.exceptions import RequestException
from .project import find_project
from .project import get_project_info
from .session_cache import SessionCache
from .stats import get_file_stats
try:
@ -443,20 +443,12 @@ def main(argv=None):
stats = get_file_stats(args.targetFile, notfile=args.notfile,
lineno=args.lineno, cursorpos=args.cursorpos)
project = None
project, branch = None, None
if not args.notfile:
project = find_project(args.targetFile, configs=configs)
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
project, branch = get_project_info(configs=configs, args=args)
kwargs = vars(args)
kwargs['project'] = project_name
kwargs['project'] = project
kwargs['branch'] = branch
kwargs['stats'] = stats

View File

@ -15,30 +15,70 @@ 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
from .projects.wakatime_project_file import WakaTimeProjectFile
log = logging.getLogger('WakaTime')
# 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,
CONFIG_PLUGINS = [
WakaTimeProjectFile,
ProjectMap,
]
REV_CONTROL_PLUGINS = [
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)
def get_project_info(configs=None, args=None):
"""Find the current project and branch.
First looks for a .wakatime-project file. Second, uses the --project arg.
Third, uses the folder name from a revision control repository. Last, uses
the --alternate-project arg.
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():
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

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
wakatime.projects.wakatime
~~~~~~~~~~~~~~~~~~~~~~~~~~
wakatime.projects.wakatime_project_file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Information from a .wakatime-project file about the project for
a given file. First line of .wakatime-project sets the project
@ -21,7 +21,7 @@ from ..compat import u, open
log = logging.getLogger('WakaTime')
class WakaTime(BaseProject):
class WakaTimeProjectFile(BaseProject):
def process(self):
self.config = self._find_config(self.path)