update wakatime-cli

This commit is contained in:
Alan Hamlett 2016-01-03 02:22:32 -08:00
parent 6cf829f08d
commit c8a1ea1bb0
4 changed files with 103 additions and 11 deletions

View file

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
"""
wakatime.constants
~~~~~~~~~~~~~~~~~~
Constant variable definitions.
:copyright: (c) 2016 Alan Hamlett.
:license: BSD, see LICENSE for more details.
"""
SUCCESS = 0
API_ERROR = 102
CONFIG_FILE_PARSE_ERROR = 103

View file

@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
"""
wakatime.languages.go
~~~~~~~~~~~~~~~~~~~~~
Parse dependencies from Go code.
:copyright: (c) 2016 Alan Hamlett.
:license: BSD, see LICENSE for more details.
"""
from . import TokenParser
class GoParser(TokenParser):
state = None
parens = 0
aliases = 0
exclude = [
r'^"fmt"$',
]
def parse(self):
for index, token, content in self.tokens:
self._process_token(token, content)
return self.dependencies
def _process_token(self, token, content):
if self.partial(token) == 'Namespace':
self._process_namespace(token, content)
elif self.partial(token) == 'Punctuation':
self._process_punctuation(token, content)
elif self.partial(token) == 'String':
self._process_string(token, content)
elif self.partial(token) == 'Text':
self._process_text(token, content)
elif self.partial(token) == 'Other':
self._process_other(token, content)
else:
self._process_misc(token, content)
def _process_namespace(self, token, content):
self.state = content
self.parens = 0
self.aliases = 0
def _process_string(self, token, content):
if self.state == 'import':
self.append(content, truncate=False)
def _process_punctuation(self, token, content):
if content == '(':
self.parens += 1
elif content == ')':
self.parens -= 1
elif content == '.':
self.aliases += 1
else:
self.state = None
def _process_text(self, token, content):
if self.state == 'import':
if content == "\n" and self.parens <= 0:
self.state = None
self.parens = 0
self.aliases = 0
else:
self.state = None
def _process_other(self, token, content):
if self.state == 'import':
self.aliases += 1
else:
self.state = None
def _process_misc(self, token, content):
self.state = None

View file

@ -30,6 +30,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'pac
from .__about__ import __version__
from .compat import u, open, is_py3
from .constants import SUCCESS, API_ERROR, CONFIG_FILE_PARSE_ERROR
from .logger import setup_logging
from .offlinequeue import Queue
from .packages import argparse
@ -408,7 +409,7 @@ def execute(argv=None):
args, configs = parseArguments()
if configs is None:
return 103 # config file parsing error
return CONFIG_FILE_PARSE_ERROR
setup_logging(args, __version__)
@ -418,7 +419,7 @@ def execute(argv=None):
log.debug(u('Skipping because matches exclude pattern: {pattern}').format(
pattern=u(exclude),
))
return 0
return SUCCESS
if args.entity_type != 'file' or os.path.isfile(args.entity):
@ -464,12 +465,12 @@ def execute(argv=None):
)
if not sent:
break
return 0 # success
return SUCCESS
return 102 # api error
return API_ERROR
else:
log.debug('File does not exist; ignoring this heartbeat.')
return 0
return SUCCESS
except:
log.traceback()

View file

@ -14,7 +14,6 @@ import logging
import os
import pickle
import sys
import traceback
try:
import sqlite3
@ -58,7 +57,7 @@ class SessionCache(object):
conn.commit()
conn.close()
except: # pragma: nocover
log.error(traceback.format_exc())
log.traceback()
def get(self):
@ -73,7 +72,7 @@ class SessionCache(object):
try:
conn, c = self.connect()
except:
log.error(traceback.format_exc())
log.traceback()
return requests.session()
session = None
@ -84,12 +83,12 @@ class SessionCache(object):
if row is not None:
session = pickle.loads(row[0])
except: # pragma: nocover
log.error(traceback.format_exc())
log.traceback()
try:
conn.close()
except: # pragma: nocover
log.error(traceback.format_exc())
log.traceback()
return session if session is not None else requests.session()
@ -106,4 +105,4 @@ class SessionCache(object):
conn.commit()
conn.close()
except:
log.error(traceback.format_exc())
log.traceback()