From 96d8908396b347f6a6e9f6eaa176f2fb6bcd8d30 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Sat, 4 Apr 2015 11:02:28 -0700 Subject: [PATCH] update wakatime cli to v4.0.8 --- plugin/packages/wakatime/__about__.py | 2 +- plugin/packages/wakatime/base.py | 45 +++++++++++++++++---------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/plugin/packages/wakatime/__about__.py b/plugin/packages/wakatime/__about__.py index 35e0fd9..4e3dd84 100644 --- a/plugin/packages/wakatime/__about__.py +++ b/plugin/packages/wakatime/__about__.py @@ -1,7 +1,7 @@ __title__ = 'wakatime' __description__ = 'Common interface to the WakaTime api.' __url__ = 'https://github.com/wakatime/wakatime' -__version_info__ = ('4', '0', '7') +__version_info__ = ('4', '0', '8') __version__ = '.'.join(__version_info__) __author__ = 'Alan Hamlett' __author_email__ = 'alan@wakatime.com' diff --git a/plugin/packages/wakatime/base.py b/plugin/packages/wakatime/base.py index c425810..8c47287 100644 --- a/plugin/packages/wakatime/base.py +++ b/plugin/packages/wakatime/base.py @@ -172,6 +172,8 @@ def parseArguments(argv): help=argparse.SUPPRESS) parser.add_argument('--logfile', dest='logfile', help='defaults to ~/.wakatime.log') + parser.add_argument('--apiurl', dest='api_url', + help='heartbeats api url; for debugging with a local server') parser.add_argument('--config', dest='config', help='defaults to ~/.wakatime.conf') parser.add_argument('--verbose', dest='verbose', action='store_true', @@ -238,6 +240,8 @@ def parseArguments(argv): args.verbose = configs.getboolean('settings', 'debug') if not args.logfile and configs.has_option('settings', 'logfile'): args.logfile = configs.get('settings', 'logfile') + if not args.api_url and configs.has_option('settings', 'api_url'): + args.api_url = configs.get('settings', 'api_url') return args, configs @@ -294,10 +298,14 @@ def get_user_agent(plugin): def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=None, - timestamp=None, isWrite=None, plugin=None, offline=None, - hidefilenames=None, notfile=False, proxy=None, **kwargs): - url = 'https://wakatime.com/api/v1/heartbeats' - log.debug('Sending heartbeat to api at %s' % url) + timestamp=None, isWrite=None, plugin=None, offline=None, notfile=False, + hidefilenames=None, proxy=None, api_url=None, **kwargs): + """Sends heartbeat as POST request to WakaTime api server. + """ + + if not api_url: + api_url = 'https://wakatime.com/api/v1/heartbeats' + log.debug('Sending heartbeat to api at %s' % api_url) data = { 'time': timestamp, 'file': targetFile, @@ -347,7 +355,7 @@ def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=Non # log time to api response = None try: - response = requests.post(url, data=request_body, headers=headers, + response = requests.post(api_url, data=request_body, headers=headers, proxies=proxies) except RequestException: exception_data = { @@ -438,18 +446,21 @@ def main(argv=None): heartbeat = queue.pop() if heartbeat is None: break - sent = send_heartbeat(project=heartbeat['project'], - targetFile=heartbeat['file'], - timestamp=heartbeat['time'], - branch=heartbeat['branch'], - stats=json.loads(heartbeat['stats']), - key=args.key, - isWrite=heartbeat['is_write'], - plugin=heartbeat['plugin'], - offline=args.offline, - hidefilenames=args.hidefilenames, - notfile=args.notfile, - proxy=args.proxy) + sent = send_heartbeat( + project=heartbeat['project'], + targetFile=heartbeat['file'], + timestamp=heartbeat['time'], + branch=heartbeat['branch'], + stats=json.loads(heartbeat['stats']), + key=args.key, + isWrite=heartbeat['is_write'], + plugin=heartbeat['plugin'], + offline=args.offline, + hidefilenames=args.hidefilenames, + notfile=args.notfile, + proxy=args.proxy, + api_url=args.api_url, + ) if not sent: break return 0 # success