forked from luna/vim-rana-local
upgrade wakatime-cli to v10.0.1
This commit is contained in:
parent
f177bdc959
commit
41a0d98f49
3 changed files with 54 additions and 31 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', '0')
|
__version_info__ = ('10', '0', '1')
|
||||||
__version__ = '.'.join(__version_info__)
|
__version__ = '.'.join(__version_info__)
|
||||||
__author__ = 'Alan Hamlett'
|
__author__ = 'Alan Hamlett'
|
||||||
__author_email__ = 'alan@wakatime.com'
|
__author_email__ = 'alan@wakatime.com'
|
||||||
|
|
|
@ -16,12 +16,7 @@ import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from .compat import u, is_py3, json
|
from .compat import u, is_py3, json
|
||||||
from .constants import (
|
from .constants import API_ERROR, AUTH_ERROR, SUCCESS, UNKNOWN_ERROR
|
||||||
API_ERROR,
|
|
||||||
AUTH_ERROR,
|
|
||||||
SUCCESS,
|
|
||||||
UNKNOWN_ERROR,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .offlinequeue import Queue
|
from .offlinequeue import Queue
|
||||||
from .packages.requests.exceptions import RequestException
|
from .packages.requests.exceptions import RequestException
|
||||||
|
@ -54,7 +49,7 @@ def send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=False):
|
||||||
|
|
||||||
api_url = args.api_url
|
api_url = args.api_url
|
||||||
if not api_url:
|
if not api_url:
|
||||||
api_url = 'https://api.wakatime.com/api/v1/heartbeats.bulk'
|
api_url = 'https://api.wakatime.com/api/v1/users/current/heartbeats.bulk'
|
||||||
log.debug('Sending heartbeats to api at %s' % api_url)
|
log.debug('Sending heartbeats to api at %s' % api_url)
|
||||||
timeout = args.timeout
|
timeout = args.timeout
|
||||||
if not timeout:
|
if not timeout:
|
||||||
|
@ -143,16 +138,50 @@ def send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=False):
|
||||||
else:
|
else:
|
||||||
code = response.status_code if response is not None else None
|
code = response.status_code if response is not None else None
|
||||||
content = response.text if response is not None else None
|
content = response.text if response is not None else None
|
||||||
|
try:
|
||||||
|
results = response.json() if response is not None else []
|
||||||
|
except:
|
||||||
|
if log.isEnabledFor(logging.DEBUG):
|
||||||
|
log.traceback(logging.WARNING)
|
||||||
|
results = []
|
||||||
if code == requests.codes.created or code == requests.codes.accepted:
|
if code == requests.codes.created or code == requests.codes.accepted:
|
||||||
log.debug({
|
log.debug({
|
||||||
'response_code': code,
|
'response_code': code,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for i in range(len(results)):
|
||||||
|
if len(heartbeats) <= i:
|
||||||
|
log.debug('Results from server do not match heartbeats sent.')
|
||||||
|
break
|
||||||
|
|
||||||
|
try:
|
||||||
|
c = results[i][1]
|
||||||
|
except:
|
||||||
|
c = 0
|
||||||
|
try:
|
||||||
|
text = json.dumps(results[i][0])
|
||||||
|
except:
|
||||||
|
if log.isEnabledFor(logging.DEBUG):
|
||||||
|
log.traceback(logging.WARNING)
|
||||||
|
text = ''
|
||||||
|
handle_result([heartbeats[i]], c, text, args, configs)
|
||||||
|
|
||||||
session_cache.save(session)
|
session_cache.save(session)
|
||||||
return SUCCESS
|
return SUCCESS
|
||||||
|
|
||||||
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)
|
||||||
else:
|
else:
|
||||||
|
handle_result(heartbeats, code, content, args, configs)
|
||||||
|
|
||||||
|
session_cache.delete()
|
||||||
|
return AUTH_ERROR if code == 401 else API_ERROR
|
||||||
|
|
||||||
|
|
||||||
|
def handle_result(h, code, content, args, configs):
|
||||||
|
if code == requests.codes.created or code == requests.codes.accepted:
|
||||||
|
return
|
||||||
|
|
||||||
if args.offline:
|
if args.offline:
|
||||||
if code == 400:
|
if code == 400:
|
||||||
log.error({
|
log.error({
|
||||||
|
@ -166,12 +195,9 @@ def send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=False):
|
||||||
'response_content': content,
|
'response_content': content,
|
||||||
})
|
})
|
||||||
queue = Queue(args, configs)
|
queue = Queue(args, configs)
|
||||||
queue.push_many(heartbeats)
|
queue.push_many(h)
|
||||||
else:
|
else:
|
||||||
log.error({
|
log.error({
|
||||||
'response_code': code,
|
'response_code': code,
|
||||||
'response_content': content,
|
'response_content': content,
|
||||||
})
|
})
|
||||||
|
|
||||||
session_cache.delete()
|
|
||||||
return AUTH_ERROR if code == 401 else API_ERROR
|
|
||||||
|
|
|
@ -24,10 +24,7 @@ from .__about__ import __version__
|
||||||
from .api import send_heartbeats
|
from .api import send_heartbeats
|
||||||
from .arguments import parse_arguments
|
from .arguments import parse_arguments
|
||||||
from .compat import u, json
|
from .compat import u, json
|
||||||
from .constants import (
|
from .constants import SUCCESS, UNKNOWN_ERROR
|
||||||
SUCCESS,
|
|
||||||
UNKNOWN_ERROR,
|
|
||||||
)
|
|
||||||
from .logger import setup_logging
|
from .logger import setup_logging
|
||||||
|
|
||||||
log = logging.getLogger('WakaTime')
|
log = logging.getLogger('WakaTime')
|
||||||
|
|
Loading…
Reference in a new issue