Merge pull request #31 from gandarez/master

Added X-Machine-Name header
This commit is contained in:
Alan Hamlett 2015-07-03 22:41:23 -07:00
commit f10faca3ee

View file

@ -19,6 +19,7 @@ import re
import sys
import time
import traceback
import socket
try:
import ConfigParser as configparser
except ImportError:
@ -161,6 +162,7 @@ def parseArguments(argv):
help='optional project name')
parser.add_argument('--alternate-project', dest='alternate_project',
help='optional alternate project name; auto-discovered project takes priority')
parser.add_argument('--workplace', dest='workplace', help='workplace you are currently logging.')
parser.add_argument('--disableoffline', dest='offline',
action='store_false',
help='disables offline time logging instead of queuing logged time')
@ -302,8 +304,10 @@ def get_user_agent(plugin):
)
return user_agent
def get_hostname():
return socket.gethostname()
def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=None,
def send_heartbeat(project=None, branch=None, workplace=None, stats={}, key=None, targetFile=None,
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.
@ -350,7 +354,9 @@ def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=Non
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': auth,
'X-Machine-Name': workplace
}
log.debug(headers)
proxies = {}
if proxy:
proxies['https'] = proxy
@ -447,10 +453,15 @@ def main(argv=None):
if not args.notfile:
project, branch = get_project_info(configs=configs, args=args)
workplace = args.workplace
if not args.workplace:
workplace = get_hostname()
kwargs = vars(args)
kwargs['project'] = project
kwargs['branch'] = branch
kwargs['stats'] = stats
kwargs['workplace'] = workplace
if send_heartbeat(**kwargs):
queue = Queue()
@ -463,6 +474,7 @@ def main(argv=None):
targetFile=heartbeat['file'],
timestamp=heartbeat['time'],
branch=heartbeat['branch'],
workplace=heartbeat['workplace'],
stats=json.loads(heartbeat['stats']),
key=args.key,
isWrite=heartbeat['is_write'],