upgrade wakatime cli to v4.0.8

This commit is contained in:
Alan Hamlett 2015-04-04 11:03:55 -07:00
parent aaff2503fb
commit c7ee7258fb
3 changed files with 34 additions and 23 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', '6') __version_info__ = ('4', '0', '8')
__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

@ -26,12 +26,11 @@ except ImportError:
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'packages')) sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'packages'))
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'packages', 'requests', 'packages'))
from .__about__ import __version__ from .__about__ import __version__
from .compat import u, open, is_py3 from .compat import u, open, is_py3
from .offlinequeue import Queue from .offlinequeue import Queue
from .log import setup_logging from .logger import setup_logging
from .project import find_project from .project import find_project
from .stats import get_file_stats from .stats import get_file_stats
from .packages import argparse from .packages import argparse
@ -155,7 +154,7 @@ def parseArguments(argv):
help='optional https proxy url; for example: '+ help='optional https proxy url; for example: '+
'https://user:pass@localhost:8080') 'https://user:pass@localhost:8080')
parser.add_argument('--project', dest='project_name', parser.add_argument('--project', dest='project_name',
help='optional project name; will auto-discover by default') help='optional project name; auto-discovered project takes priority')
parser.add_argument('--disableoffline', dest='offline', parser.add_argument('--disableoffline', 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')
@ -173,6 +172,8 @@ def parseArguments(argv):
help=argparse.SUPPRESS) help=argparse.SUPPRESS)
parser.add_argument('--logfile', dest='logfile', parser.add_argument('--logfile', dest='logfile',
help='defaults to ~/.wakatime.log') 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', parser.add_argument('--config', dest='config',
help='defaults to ~/.wakatime.conf') help='defaults to ~/.wakatime.conf')
parser.add_argument('--verbose', dest='verbose', action='store_true', parser.add_argument('--verbose', dest='verbose', action='store_true',
@ -239,6 +240,8 @@ def parseArguments(argv):
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.logfile and configs.has_option('settings', 'logfile'):
args.logfile = configs.get('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 return args, configs
@ -295,10 +298,14 @@ def get_user_agent(plugin):
def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=None, def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=None,
timestamp=None, isWrite=None, plugin=None, offline=None, timestamp=None, isWrite=None, plugin=None, offline=None, notfile=False,
hidefilenames=None, notfile=False, proxy=None, **kwargs): hidefilenames=None, proxy=None, api_url=None, **kwargs):
url = 'https://wakatime.com/api/v1/heartbeats' """Sends heartbeat as POST request to WakaTime api server.
log.debug('Sending heartbeat to api at %s' % url) """
if not api_url:
api_url = 'https://wakatime.com/api/v1/heartbeats'
log.debug('Sending heartbeat to api at %s' % api_url)
data = { data = {
'time': timestamp, 'time': timestamp,
'file': targetFile, 'file': targetFile,
@ -348,7 +355,7 @@ def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=Non
# log time to api # log time to api
response = None response = None
try: try:
response = requests.post(url, data=request_body, headers=headers, response = requests.post(api_url, data=request_body, headers=headers,
proxies=proxies) proxies=proxies)
except RequestException: except RequestException:
exception_data = { exception_data = {
@ -439,18 +446,21 @@ def main(argv=None):
heartbeat = queue.pop() heartbeat = queue.pop()
if heartbeat is None: if heartbeat is None:
break break
sent = send_heartbeat(project=heartbeat['project'], sent = send_heartbeat(
targetFile=heartbeat['file'], project=heartbeat['project'],
timestamp=heartbeat['time'], targetFile=heartbeat['file'],
branch=heartbeat['branch'], timestamp=heartbeat['time'],
stats=json.loads(heartbeat['stats']), branch=heartbeat['branch'],
key=args.key, stats=json.loads(heartbeat['stats']),
isWrite=heartbeat['is_write'], key=args.key,
plugin=heartbeat['plugin'], isWrite=heartbeat['is_write'],
offline=args.offline, plugin=heartbeat['plugin'],
hidefilenames=args.hidefilenames, offline=args.offline,
notfile=args.notfile, hidefilenames=args.hidefilenames,
proxy=args.proxy) notfile=args.notfile,
proxy=args.proxy,
api_url=args.api_url,
)
if not sent: if not sent:
break break
return 0 # success return 0 # success

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
wakatime.log wakatime.logger
~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Provides the configured logger for writing JSON to the log file. Provides the configured logger for writing JSON to the log file.
@ -73,6 +73,7 @@ def set_log_level(logger, args):
def setup_logging(args, version): def setup_logging(args, version):
logging.captureWarnings(True)
logger = logging.getLogger('WakaTime') logger = logging.getLogger('WakaTime')
set_log_level(logger, args) set_log_level(logger, args)
if len(logger.handlers) > 0: if len(logger.handlers) > 0: