Workaround for issue #20

This commit is contained in:
Carlos Henrique Gandarez 2015-05-15 11:02:46 -03:00
parent 652bf480e3
commit 1576cfc1f0

View file

@ -29,14 +29,14 @@ sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'pac
from .__about__ import __version__ from .__about__ import __version__
from .compat import u, open, is_py3 from .compat import u, open, is_py3
from .logger import setup_logging
from .offlinequeue import Queue from .offlinequeue import Queue
from .logger import setup_logging
from .project import find_project
from .stats import get_file_stats
from .packages import argparse from .packages import argparse
from .packages import simplejson as json from .packages import simplejson as json
from .packages import requests
from .packages.requests.exceptions import RequestException from .packages.requests.exceptions import RequestException
from .project import find_project
from .session_cache import SessionCache
from .stats import get_file_stats
try: try:
from .packages import tzlocal from .packages import tzlocal
except: except:
@ -147,10 +147,6 @@ def parseArguments(argv):
type=float, type=float,
help='optional floating-point unix epoch timestamp; '+ help='optional floating-point unix epoch timestamp; '+
'uses current time by default') 'uses current time by default')
parser.add_argument('--lineno', dest='lineno',
help='optional line number; current line being edited')
parser.add_argument('--cursorpos', dest='cursorpos',
help='optional cursor position in the current file')
parser.add_argument('--notfile', dest='notfile', action='store_true', parser.add_argument('--notfile', dest='notfile', action='store_true',
help='when set, will accept any value for the file. for example, '+ help='when set, will accept any value for the file. for example, '+
'a domain name or other item you want to log time towards.') 'a domain name or other item you want to log time towards.')
@ -326,10 +322,6 @@ def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=Non
data['language'] = stats['language'] data['language'] = stats['language']
if stats.get('dependencies'): if stats.get('dependencies'):
data['dependencies'] = stats['dependencies'] data['dependencies'] = stats['dependencies']
if stats.get('lineno'):
data['lineno'] = stats['lineno']
if stats.get('cursorpos'):
data['cursorpos'] = stats['cursorpos']
if isWrite: if isWrite:
data['is_write'] = isWrite data['is_write'] = isWrite
if project: if project:
@ -360,13 +352,10 @@ def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=Non
if tz: if tz:
headers['TimeZone'] = u(tz.zone) headers['TimeZone'] = u(tz.zone)
session_cache = SessionCache()
session = session_cache.get()
# log time to api # log time to api
response = None response = None
try: try:
response = session.post(api_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 = {
@ -388,7 +377,6 @@ def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=Non
log.debug({ log.debug({
'response_code': response_code, 'response_code': response_code,
}) })
session_cache.save(session)
return True return True
if offline: if offline:
if response_code != 400: if response_code != 400:
@ -414,7 +402,6 @@ def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=Non
'response_code': response_code, 'response_code': response_code,
'response_content': response_content, 'response_content': response_content,
}) })
session_cache.delete()
return False return False
@ -437,8 +424,7 @@ def main(argv=None):
if os.path.isfile(args.targetFile) or args.notfile: if os.path.isfile(args.targetFile) or args.notfile:
stats = get_file_stats(args.targetFile, notfile=args.notfile, stats = get_file_stats(args.targetFile, notfile=args.notfile)
lineno=args.lineno, cursorpos=args.cursorpos)
project = None project = None
if not args.notfile: if not args.notfile:
@ -447,6 +433,7 @@ def main(argv=None):
project_name = args.project_name project_name = args.project_name
if project: if project:
branch = project.branch() branch = project.branch()
if not project_name:
project_name = project.name() project_name = project.name()
if send_heartbeat( if send_heartbeat(