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

View file

@ -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

View file

@ -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

View file

@ -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)