forked from luna/vim-rana-local
upgrade wakatime-cli to v10.1.0
This commit is contained in:
parent
48b4e59dcd
commit
e35c74e5b4
7 changed files with 81 additions and 38 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__ = ('10', '0', '5')
|
__version_info__ = ('10', '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'
|
||||||
|
|
|
@ -144,6 +144,11 @@ def send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=False):
|
||||||
_process_server_results(heartbeats, code, content, results, args, configs)
|
_process_server_results(heartbeats, code, content, results, args, configs)
|
||||||
session_cache.save(session)
|
session_cache.save(session)
|
||||||
return SUCCESS
|
return SUCCESS
|
||||||
|
else:
|
||||||
|
log.debug({
|
||||||
|
'response_code': code,
|
||||||
|
'response_text': content,
|
||||||
|
})
|
||||||
|
|
||||||
if should_try_ntlm:
|
if should_try_ntlm:
|
||||||
return send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=True)
|
return send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=True)
|
||||||
|
@ -157,6 +162,7 @@ def send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=False):
|
||||||
def _process_server_results(heartbeats, code, content, results, args, configs):
|
def _process_server_results(heartbeats, code, content, results, args, configs):
|
||||||
log.debug({
|
log.debug({
|
||||||
'response_code': code,
|
'response_code': code,
|
||||||
|
'results': results,
|
||||||
})
|
})
|
||||||
|
|
||||||
for i in range(len(results)):
|
for i in range(len(results)):
|
||||||
|
|
|
@ -103,12 +103,17 @@ def parse_arguments():
|
||||||
'auto-detected language')
|
'auto-detected language')
|
||||||
parser.add_argument('--hostname', dest='hostname', action=StoreWithoutQuotes, help='hostname of '+
|
parser.add_argument('--hostname', dest='hostname', action=StoreWithoutQuotes, help='hostname of '+
|
||||||
'current machine.')
|
'current machine.')
|
||||||
parser.add_argument('--disableoffline', dest='offline',
|
parser.add_argument('--disable-offline', dest='offline',
|
||||||
action='store_false',
|
action='store_false',
|
||||||
help='disables offline time logging instead of queuing logged time')
|
help='disables offline time logging instead of queuing logged time')
|
||||||
parser.add_argument('--hidefilenames', dest='hidefilenames',
|
parser.add_argument('--disableoffline', dest='offline_deprecated',
|
||||||
|
action='store_true', help=argparse.SUPPRESS)
|
||||||
|
parser.add_argument('--hide-filenames', dest='hide_filenames',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='obfuscate filenames; will not send file names to api')
|
help='obfuscate filenames; will not send file names to api')
|
||||||
|
parser.add_argument('--hidefilenames', dest='hidefilenames',
|
||||||
|
action='store_true',
|
||||||
|
help=argparse.SUPPRESS)
|
||||||
parser.add_argument('--exclude', dest='exclude', action='append',
|
parser.add_argument('--exclude', dest='exclude', action='append',
|
||||||
help='filename patterns to exclude from logging; POSIX regex '+
|
help='filename patterns to exclude from logging; POSIX regex '+
|
||||||
'syntax; can be used more than once')
|
'syntax; can be used more than once')
|
||||||
|
@ -116,15 +121,24 @@ def parse_arguments():
|
||||||
help='filename patterns to log; when used in combination with '+
|
help='filename patterns to log; when used in combination with '+
|
||||||
'--exclude, files matching include will still be logged; '+
|
'--exclude, files matching include will still be logged; '+
|
||||||
'POSIX regex syntax; can be used more than once')
|
'POSIX regex syntax; can be used more than once')
|
||||||
|
parser.add_argument('--include-only-with-project-file',
|
||||||
|
dest='include_only_with_project_file',
|
||||||
|
action='store_true',
|
||||||
|
help='disables tracking folders unless they contain '+
|
||||||
|
'a .wakatime-project file; defaults to false')
|
||||||
parser.add_argument('--ignore', dest='ignore', action='append',
|
parser.add_argument('--ignore', dest='ignore', action='append',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
parser.add_argument('--extra-heartbeats', dest='extra_heartbeats',
|
parser.add_argument('--extra-heartbeats', dest='extra_heartbeats',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='reads extra heartbeats from STDIN as a JSON array until EOF')
|
help='reads extra heartbeats from STDIN as a JSON array until EOF')
|
||||||
parser.add_argument('--logfile', dest='logfile', action=StoreWithoutQuotes,
|
parser.add_argument('--log-file', dest='log_file', action=StoreWithoutQuotes,
|
||||||
help='defaults to ~/.wakatime.log')
|
help='defaults to ~/.wakatime.log')
|
||||||
parser.add_argument('--apiurl', dest='api_url', action=StoreWithoutQuotes,
|
parser.add_argument('--logfile', dest='logfile', action=StoreWithoutQuotes,
|
||||||
|
help=argparse.SUPPRESS)
|
||||||
|
parser.add_argument('--api-url', dest='api_url', action=StoreWithoutQuotes,
|
||||||
help='heartbeats api url; for debugging with a local server')
|
help='heartbeats api url; for debugging with a local server')
|
||||||
|
parser.add_argument('--apiurl', dest='apiurl', action=StoreWithoutQuotes,
|
||||||
|
help=argparse.SUPPRESS)
|
||||||
parser.add_argument('--timeout', dest='timeout', type=int, action=StoreWithoutQuotes,
|
parser.add_argument('--timeout', dest='timeout', type=int, action=StoreWithoutQuotes,
|
||||||
help='number of seconds to wait when sending heartbeats to api; '+
|
help='number of seconds to wait when sending heartbeats to api; '+
|
||||||
'defaults to 60 seconds')
|
'defaults to 60 seconds')
|
||||||
|
@ -194,6 +208,8 @@ def parse_arguments():
|
||||||
args.exclude.append(pattern)
|
args.exclude.append(pattern)
|
||||||
except TypeError: # pragma: nocover
|
except TypeError: # pragma: nocover
|
||||||
pass
|
pass
|
||||||
|
if not args.include_only_with_project_file and configs.has_option('settings', 'include_only_with_project_file'):
|
||||||
|
args.include_only_with_project_file = configs.get('settings', 'include_only_with_project_file')
|
||||||
if not args.include:
|
if not args.include:
|
||||||
args.include = []
|
args.include = []
|
||||||
if configs.has_option('settings', 'include'):
|
if configs.has_option('settings', 'include'):
|
||||||
|
@ -203,18 +219,26 @@ def parse_arguments():
|
||||||
args.include.append(pattern)
|
args.include.append(pattern)
|
||||||
except TypeError: # pragma: nocover
|
except TypeError: # pragma: nocover
|
||||||
pass
|
pass
|
||||||
if args.hidefilenames:
|
if not args.hide_filenames and args.hidefilenames:
|
||||||
args.hidefilenames = ['.*']
|
args.hide_filenames = args.hidefilenames
|
||||||
|
if args.hide_filenames:
|
||||||
|
args.hide_filenames = ['.*']
|
||||||
else:
|
else:
|
||||||
args.hidefilenames = []
|
args.hide_filenames = []
|
||||||
|
option = None
|
||||||
if configs.has_option('settings', 'hidefilenames'):
|
if configs.has_option('settings', 'hidefilenames'):
|
||||||
option = configs.get('settings', 'hidefilenames')
|
option = configs.get('settings', 'hidefilenames')
|
||||||
|
if configs.has_option('settings', 'hide_filenames'):
|
||||||
|
option = configs.get('settings', 'hide_filenames')
|
||||||
|
if option is not None:
|
||||||
if option.strip().lower() == 'true':
|
if option.strip().lower() == 'true':
|
||||||
args.hidefilenames = ['.*']
|
args.hide_filenames = ['.*']
|
||||||
elif option.strip().lower() != 'false':
|
elif option.strip().lower() != 'false':
|
||||||
for pattern in option.split("\n"):
|
for pattern in option.split("\n"):
|
||||||
if pattern.strip() != '':
|
if pattern.strip() != '':
|
||||||
args.hidefilenames.append(pattern)
|
args.hide_filenames.append(pattern)
|
||||||
|
if args.offline_deprecated:
|
||||||
|
args.offline = False
|
||||||
if args.offline and configs.has_option('settings', 'offline'):
|
if args.offline and configs.has_option('settings', 'offline'):
|
||||||
args.offline = configs.getboolean('settings', 'offline')
|
args.offline = configs.getboolean('settings', 'offline')
|
||||||
if not args.proxy and configs.has_option('settings', 'proxy'):
|
if not args.proxy and configs.has_option('settings', 'proxy'):
|
||||||
|
@ -235,11 +259,15 @@ def parse_arguments():
|
||||||
args.verbose = configs.getboolean('settings', 'verbose')
|
args.verbose = configs.getboolean('settings', 'verbose')
|
||||||
if not args.verbose and configs.has_option('settings', 'debug'):
|
if not args.verbose and configs.has_option('settings', 'debug'):
|
||||||
args.verbose = configs.getboolean('settings', 'debug')
|
args.verbose = configs.getboolean('settings', 'debug')
|
||||||
if not args.logfile and configs.has_option('settings', 'logfile'):
|
if not args.log_file and args.logfile:
|
||||||
args.logfile = configs.get('settings', 'logfile')
|
args.log_file = args.logfile
|
||||||
if not args.logfile and os.environ.get('WAKATIME_HOME'):
|
if not args.log_file and configs.has_option('settings', 'log_file'):
|
||||||
|
args.log_file = configs.get('settings', 'log_file')
|
||||||
|
if not args.log_file and os.environ.get('WAKATIME_HOME'):
|
||||||
home = os.environ.get('WAKATIME_HOME')
|
home = os.environ.get('WAKATIME_HOME')
|
||||||
args.logfile = os.path.join(os.path.expanduser(home), '.wakatime.log')
|
args.log_file = os.path.join(os.path.expanduser(home), '.wakatime.log')
|
||||||
|
if not args.api_url and args.apiurl:
|
||||||
|
args.api_url = args.apiurl
|
||||||
if not args.api_url and configs.has_option('settings', 'api_url'):
|
if not args.api_url and configs.has_option('settings', 'api_url'):
|
||||||
args.api_url = configs.get('settings', 'api_url')
|
args.api_url = configs.get('settings', 'api_url')
|
||||||
if not args.timeout and configs.has_option('settings', 'timeout'):
|
if not args.timeout and configs.has_option('settings', 'timeout'):
|
||||||
|
|
|
@ -14,7 +14,7 @@ import re
|
||||||
from .compat import u, json
|
from .compat import u, json
|
||||||
from .project import get_project_info
|
from .project import get_project_info
|
||||||
from .stats import get_file_stats
|
from .stats import get_file_stats
|
||||||
from .utils import get_user_agent, should_exclude, format_file_path
|
from .utils import get_user_agent, should_exclude, format_file_path, find_project_file
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger('WakaTime')
|
log = logging.getLogger('WakaTime')
|
||||||
|
@ -66,9 +66,12 @@ class Heartbeat(object):
|
||||||
return
|
return
|
||||||
if self.type == 'file':
|
if self.type == 'file':
|
||||||
self.entity = format_file_path(self.entity)
|
self.entity = format_file_path(self.entity)
|
||||||
if self.type == 'file' and (not self.entity or not os.path.isfile(self.entity)):
|
if not self.entity or not os.path.isfile(self.entity):
|
||||||
self.skip = u('File does not exist; ignoring this heartbeat.')
|
self.skip = u('File does not exist; ignoring this heartbeat.')
|
||||||
return
|
return
|
||||||
|
if self._excluded_by_missing_project_file():
|
||||||
|
self.skip = u('Skipping because missing .wakatime-project file in parent path.')
|
||||||
|
return
|
||||||
|
|
||||||
project, branch = get_project_info(configs, self, data)
|
project, branch = get_project_info(configs, self, data)
|
||||||
self.project = project
|
self.project = project
|
||||||
|
@ -103,7 +106,7 @@ class Heartbeat(object):
|
||||||
Returns a Heartbeat.
|
Returns a Heartbeat.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not self.args.hidefilenames:
|
if not self.args.hide_filenames:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
if self.entity is None:
|
if self.entity is None:
|
||||||
|
@ -112,7 +115,7 @@ class Heartbeat(object):
|
||||||
if self.type != 'file':
|
if self.type != 'file':
|
||||||
return self
|
return self
|
||||||
|
|
||||||
for pattern in self.args.hidefilenames:
|
for pattern in self.args.hide_filenames:
|
||||||
try:
|
try:
|
||||||
compiled = re.compile(pattern, re.IGNORECASE)
|
compiled = re.compile(pattern, re.IGNORECASE)
|
||||||
if compiled.search(self.entity):
|
if compiled.search(self.entity):
|
||||||
|
@ -183,6 +186,11 @@ class Heartbeat(object):
|
||||||
def _excluded_by_pattern(self):
|
def _excluded_by_pattern(self):
|
||||||
return should_exclude(self.entity, self.args.include, self.args.exclude)
|
return should_exclude(self.entity, self.args.include, self.args.exclude)
|
||||||
|
|
||||||
|
def _excluded_by_missing_project_file(self):
|
||||||
|
if not self.args.include_only_with_project_file:
|
||||||
|
return False
|
||||||
|
return find_project_file(self.entity) is None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.json()
|
return self.json()
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ def setup_logging(args, version):
|
||||||
for handler in logger.handlers:
|
for handler in logger.handlers:
|
||||||
logger.removeHandler(handler)
|
logger.removeHandler(handler)
|
||||||
set_log_level(logger, args)
|
set_log_level(logger, args)
|
||||||
logfile = args.logfile
|
logfile = args.log_file
|
||||||
if not logfile:
|
if not logfile:
|
||||||
logfile = '~/.wakatime.log'
|
logfile = '~/.wakatime.log'
|
||||||
handler = logging.FileHandler(os.path.expanduser(logfile))
|
handler = logging.FileHandler(os.path.expanduser(logfile))
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .base import BaseProject
|
from .base import BaseProject
|
||||||
from ..compat import u, open
|
from ..compat import u, open
|
||||||
|
from ..utils import find_project_file
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger('WakaTime')
|
log = logging.getLogger('WakaTime')
|
||||||
|
@ -25,7 +25,7 @@ log = logging.getLogger('WakaTime')
|
||||||
class ProjectFile(BaseProject):
|
class ProjectFile(BaseProject):
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
self.config = self._find_config(self.path)
|
self.config = find_project_file(self.path)
|
||||||
self._project_name = None
|
self._project_name = None
|
||||||
self._project_branch = None
|
self._project_branch = None
|
||||||
|
|
||||||
|
@ -33,13 +33,13 @@ class ProjectFile(BaseProject):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(self.config, 'r', encoding='utf-8') as fh:
|
with open(self.config, 'r', encoding='utf-8') as fh:
|
||||||
self._project_name = u(fh.readline().strip())
|
self._project_name = u(fh.readline().strip()) or None
|
||||||
self._project_branch = u(fh.readline().strip())
|
self._project_branch = u(fh.readline().strip()) or None
|
||||||
except UnicodeDecodeError: # pragma: nocover
|
except UnicodeDecodeError: # pragma: nocover
|
||||||
try:
|
try:
|
||||||
with open(self.config, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
with open(self.config, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
self._project_name = u(fh.readline().strip())
|
self._project_name = u(fh.readline().strip()) or None
|
||||||
self._project_branch = u(fh.readline().strip())
|
self._project_branch = u(fh.readline().strip()) or None
|
||||||
except:
|
except:
|
||||||
log.traceback(logging.WARNING)
|
log.traceback(logging.WARNING)
|
||||||
except IOError: # pragma: nocover
|
except IOError: # pragma: nocover
|
||||||
|
@ -53,14 +53,3 @@ class ProjectFile(BaseProject):
|
||||||
|
|
||||||
def branch(self):
|
def branch(self):
|
||||||
return self._project_branch
|
return self._project_branch
|
||||||
|
|
||||||
def _find_config(self, path):
|
|
||||||
path = os.path.realpath(path)
|
|
||||||
if os.path.isfile(path):
|
|
||||||
path = os.path.split(path)[0]
|
|
||||||
if os.path.isfile(os.path.join(path, '.wakatime-project')):
|
|
||||||
return os.path.join(path, '.wakatime-project')
|
|
||||||
split_path = os.path.split(path)
|
|
||||||
if split_path[1] == '':
|
|
||||||
return None
|
|
||||||
return self._find_config(split_path[0])
|
|
||||||
|
|
|
@ -82,3 +82,15 @@ def format_file_path(filepath):
|
||||||
|
|
||||||
def get_hostname(args):
|
def get_hostname(args):
|
||||||
return args.hostname or socket.gethostname()
|
return args.hostname or socket.gethostname()
|
||||||
|
|
||||||
|
|
||||||
|
def find_project_file(path):
|
||||||
|
path = os.path.realpath(path)
|
||||||
|
if os.path.isfile(path):
|
||||||
|
path = os.path.split(path)[0]
|
||||||
|
if os.path.isfile(os.path.join(path, '.wakatime-project')):
|
||||||
|
return os.path.join(path, '.wakatime-project')
|
||||||
|
split_path = os.path.split(path)
|
||||||
|
if split_path[1] == '':
|
||||||
|
return None
|
||||||
|
return find_project_file(split_path[0])
|
||||||
|
|
Loading…
Reference in a new issue