forked from luna/vim-rana-local
upgrade wakatime-cli to v9.0.0
This commit is contained in:
parent
29b6d3fd9b
commit
23e92a5701
5 changed files with 101 additions and 37 deletions
|
@ -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__ = ('8', '0', '5')
|
__version_info__ = ('9', '0', '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'
|
||||||
|
|
|
@ -80,19 +80,6 @@ def send_heartbeat(project=None, branch=None, hostname=None, stats={}, key=None,
|
||||||
'entity': entity,
|
'entity': entity,
|
||||||
'type': entity_type,
|
'type': entity_type,
|
||||||
}
|
}
|
||||||
if hidefilenames and entity is not None and entity_type == 'file':
|
|
||||||
for pattern in hidefilenames:
|
|
||||||
try:
|
|
||||||
compiled = re.compile(pattern, re.IGNORECASE)
|
|
||||||
if compiled.search(entity):
|
|
||||||
extension = u(os.path.splitext(data['entity'])[1])
|
|
||||||
data['entity'] = u('HIDDEN{0}').format(extension)
|
|
||||||
break
|
|
||||||
except re.error as ex:
|
|
||||||
log.warning(u('Regex error ({msg}) for include pattern: {pattern}').format(
|
|
||||||
msg=u(ex),
|
|
||||||
pattern=u(pattern),
|
|
||||||
))
|
|
||||||
if stats.get('lines'):
|
if stats.get('lines'):
|
||||||
data['lines'] = stats['lines']
|
data['lines'] = stats['lines']
|
||||||
if stats.get('language'):
|
if stats.get('language'):
|
||||||
|
@ -109,6 +96,28 @@ def send_heartbeat(project=None, branch=None, hostname=None, stats={}, key=None,
|
||||||
data['project'] = project
|
data['project'] = project
|
||||||
if branch:
|
if branch:
|
||||||
data['branch'] = branch
|
data['branch'] = branch
|
||||||
|
|
||||||
|
if hidefilenames and entity is not None and entity_type == 'file':
|
||||||
|
for pattern in hidefilenames:
|
||||||
|
try:
|
||||||
|
compiled = re.compile(pattern, re.IGNORECASE)
|
||||||
|
if compiled.search(entity):
|
||||||
|
extension = u(os.path.splitext(data['entity'])[1])
|
||||||
|
data['entity'] = u('HIDDEN{0}').format(extension)
|
||||||
|
|
||||||
|
# also delete any sensitive info when hiding file names
|
||||||
|
sensitive = ['dependencies', 'lines', 'lineno', 'cursorpos', 'branch']
|
||||||
|
for key in sensitive:
|
||||||
|
if key in data:
|
||||||
|
del data[key]
|
||||||
|
|
||||||
|
break
|
||||||
|
except re.error as ex:
|
||||||
|
log.warning(u('Regex error ({msg}) for include pattern: {pattern}').format(
|
||||||
|
msg=u(ex),
|
||||||
|
pattern=u(pattern),
|
||||||
|
))
|
||||||
|
|
||||||
log.debug(data)
|
log.debug(data)
|
||||||
|
|
||||||
# setup api request
|
# setup api request
|
||||||
|
@ -219,8 +228,6 @@ def send_heartbeat(project=None, branch=None, hostname=None, stats={}, key=None,
|
||||||
queue = Queue()
|
queue = Queue()
|
||||||
queue.push(data, json.dumps(stats), plugin)
|
queue.push(data, json.dumps(stats), plugin)
|
||||||
log.warn(exception_data)
|
log.warn(exception_data)
|
||||||
session_cache.delete()
|
|
||||||
return API_ERROR
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
code = response.status_code if response is not None else None
|
code = response.status_code if response is not None else None
|
||||||
|
|
|
@ -13,9 +13,9 @@ import logging
|
||||||
|
|
||||||
from .projects.git import Git
|
from .projects.git import Git
|
||||||
from .projects.mercurial import Mercurial
|
from .projects.mercurial import Mercurial
|
||||||
|
from .projects.projectfile import ProjectFile
|
||||||
from .projects.projectmap import ProjectMap
|
from .projects.projectmap import ProjectMap
|
||||||
from .projects.subversion import Subversion
|
from .projects.subversion import Subversion
|
||||||
from .projects.wakatime_project_file import WakaTimeProjectFile
|
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger('WakaTime')
|
log = logging.getLogger('WakaTime')
|
||||||
|
@ -23,7 +23,7 @@ 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.
|
||||||
CONFIG_PLUGINS = [
|
CONFIG_PLUGINS = [
|
||||||
WakaTimeProjectFile,
|
ProjectFile,
|
||||||
ProjectMap,
|
ProjectMap,
|
||||||
]
|
]
|
||||||
REV_CONTROL_PLUGINS = [
|
REV_CONTROL_PLUGINS = [
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .base import BaseProject
|
from .base import BaseProject
|
||||||
|
@ -21,21 +22,19 @@ log = logging.getLogger('WakaTime')
|
||||||
|
|
||||||
|
|
||||||
class Git(BaseProject):
|
class Git(BaseProject):
|
||||||
|
_submodule = None
|
||||||
|
_project_name = None
|
||||||
|
_head_file = None
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
self.configFile = self._find_git_config_file(self.path)
|
return self._find_git_config_file(self.path)
|
||||||
return self.configFile is not None
|
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
base = self._project_base()
|
return u(self._project_name) if self._project_name else None
|
||||||
if base:
|
|
||||||
return u(os.path.basename(base))
|
|
||||||
return None # pragma: nocover
|
|
||||||
|
|
||||||
def branch(self):
|
def branch(self):
|
||||||
base = self._project_base()
|
head = self._head_file
|
||||||
if base:
|
if head:
|
||||||
head = os.path.join(self._project_base(), '.git', 'HEAD')
|
|
||||||
try:
|
try:
|
||||||
with open(head, 'r', encoding='utf-8') as fh:
|
with open(head, 'r', encoding='utf-8') as fh:
|
||||||
return self._get_branch_from_head_file(fh.readline())
|
return self._get_branch_from_head_file(fh.readline())
|
||||||
|
@ -49,23 +48,81 @@ class Git(BaseProject):
|
||||||
log.traceback(logging.WARNING)
|
log.traceback(logging.WARNING)
|
||||||
return u('master')
|
return u('master')
|
||||||
|
|
||||||
def _project_base(self):
|
|
||||||
if self.configFile:
|
|
||||||
return os.path.dirname(os.path.dirname(self.configFile))
|
|
||||||
return None # pragma: nocover
|
|
||||||
|
|
||||||
def _find_git_config_file(self, path):
|
def _find_git_config_file(self, path):
|
||||||
path = os.path.realpath(path)
|
path = os.path.realpath(path)
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
path = os.path.split(path)[0]
|
path = os.path.split(path)[0]
|
||||||
if os.path.isfile(os.path.join(path, '.git', 'config')):
|
if os.path.isfile(os.path.join(path, '.git', 'config')):
|
||||||
return os.path.join(path, '.git', 'config')
|
self._project_name = os.path.basename(path)
|
||||||
|
self._head_file = os.path.join(path, '.git', 'HEAD')
|
||||||
|
return True
|
||||||
|
if self._submodules_supported_for_path(path):
|
||||||
|
submodule_path = self._find_path_from_submodule(path)
|
||||||
|
if submodule_path:
|
||||||
|
self._project_name = os.path.basename(path)
|
||||||
|
self._head_file = os.path.join(submodule_path, 'HEAD')
|
||||||
|
return True
|
||||||
split_path = os.path.split(path)
|
split_path = os.path.split(path)
|
||||||
if split_path[1] == '':
|
if split_path[1] == '':
|
||||||
return None
|
return False
|
||||||
return self._find_git_config_file(split_path[0])
|
return self._find_git_config_file(split_path[0])
|
||||||
|
|
||||||
def _get_branch_from_head_file(self, line):
|
def _get_branch_from_head_file(self, line):
|
||||||
if u(line.strip()).startswith('ref: '):
|
if u(line.strip()).startswith('ref: '):
|
||||||
return u(line.strip().rsplit('/', 1)[-1])
|
return u(line.strip().rsplit('/', 1)[-1])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _submodules_supported_for_path(self, path):
|
||||||
|
if not self._configs:
|
||||||
|
return True
|
||||||
|
|
||||||
|
disabled = self._configs.get('submodules_disabled')
|
||||||
|
if not disabled:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if disabled.strip().lower() == 'true':
|
||||||
|
return False
|
||||||
|
if disabled.strip().lower() == 'false':
|
||||||
|
return True
|
||||||
|
|
||||||
|
for pattern in disabled.split("\n"):
|
||||||
|
if pattern.strip():
|
||||||
|
try:
|
||||||
|
compiled = re.compile(pattern, re.IGNORECASE)
|
||||||
|
if compiled.search(path):
|
||||||
|
return False
|
||||||
|
except re.error as ex:
|
||||||
|
log.warning(u('Regex error ({msg}) for disable git submodules pattern: {pattern}').format(
|
||||||
|
msg=u(ex),
|
||||||
|
pattern=u(pattern),
|
||||||
|
))
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _find_path_from_submodule(self, path):
|
||||||
|
link = os.path.join(path, '.git')
|
||||||
|
if not os.path.isfile(link):
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(link, 'r', encoding='utf-8') as fh:
|
||||||
|
return self._get_path_from_submodule_link(path, fh.readline())
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
with open(link, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
|
return self._get_path_from_submodule_link(path, fh.readline())
|
||||||
|
except:
|
||||||
|
log.traceback(logging.WARNING)
|
||||||
|
except IOError:
|
||||||
|
log.traceback(logging.WARNING)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _get_path_from_submodule_link(self, path, line):
|
||||||
|
if line.startswith('gitdir: '):
|
||||||
|
subpath = line[len('gitdir: '):].strip()
|
||||||
|
if os.path.isfile(os.path.join(path, subpath, 'config')) and \
|
||||||
|
os.path.isfile(os.path.join(path, subpath, 'HEAD')):
|
||||||
|
return os.path.join(path, subpath)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
wakatime.projects.wakatime_project_file
|
wakatime.projects.projectfile
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
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
|
||||||
|
@ -22,7 +22,7 @@ from ..compat import u, open
|
||||||
log = logging.getLogger('WakaTime')
|
log = logging.getLogger('WakaTime')
|
||||||
|
|
||||||
|
|
||||||
class WakaTimeProjectFile(BaseProject):
|
class ProjectFile(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