upgrade wakatime-cli core to v4.1.9
This commit is contained in:
parent
5ba5e6d21b
commit
297f65733f
10 changed files with 171 additions and 68 deletions
|
@ -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', '1', '8')
|
__version_info__ = ('4', '1', '9')
|
||||||
__version__ = '.'.join(__version_info__)
|
__version__ = '.'.join(__version_info__)
|
||||||
__author__ = 'Alan Hamlett'
|
__author__ = 'Alan Hamlett'
|
||||||
__author_email__ = 'alan@wakatime.com'
|
__author_email__ = 'alan@wakatime.com'
|
||||||
|
|
15
packages/wakatime/constants.py
Normal file
15
packages/wakatime/constants.py
Normal 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
|
77
packages/wakatime/dependencies/go.py
Normal file
77
packages/wakatime/dependencies/go.py
Normal 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
|
|
@ -11,9 +11,10 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import traceback
|
||||||
|
|
||||||
from .compat import u
|
from .compat import u
|
||||||
|
from .packages.requests.packages import urllib3
|
||||||
try:
|
try:
|
||||||
from collections import OrderedDict # pragma: nocover
|
from collections import OrderedDict # pragma: nocover
|
||||||
except ImportError: # pragma: nocover
|
except ImportError: # pragma: nocover
|
||||||
|
@ -70,8 +71,9 @@ class JsonFormatter(logging.Formatter):
|
||||||
del data['plugin']
|
del data['plugin']
|
||||||
return CustomEncoder().encode(data)
|
return CustomEncoder().encode(data)
|
||||||
|
|
||||||
def formatException(self, exc_info):
|
|
||||||
return sys.exec_info[2].format_exc()
|
def traceback_formatter(*args, **kwargs):
|
||||||
|
logging.getLogger('WakaTime').error(traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
def set_log_level(logger, args):
|
def set_log_level(logger, args):
|
||||||
|
@ -82,6 +84,7 @@ def set_log_level(logger, args):
|
||||||
|
|
||||||
|
|
||||||
def setup_logging(args, version):
|
def setup_logging(args, version):
|
||||||
|
urllib3.disable_warnings()
|
||||||
logger = logging.getLogger('WakaTime')
|
logger = logging.getLogger('WakaTime')
|
||||||
for handler in logger.handlers:
|
for handler in logger.handlers:
|
||||||
logger.removeHandler(handler)
|
logger.removeHandler(handler)
|
||||||
|
@ -102,6 +105,9 @@ def setup_logging(args, version):
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
# add custom traceback logging method
|
||||||
|
logger.traceback = traceback_formatter
|
||||||
|
|
||||||
warnings_formatter = JsonFormatter(datefmt='%Y/%m/%d %H:%M:%S %z')
|
warnings_formatter = JsonFormatter(datefmt='%Y/%m/%d %H:%M:%S %z')
|
||||||
warnings_formatter.setup(
|
warnings_formatter.setup(
|
||||||
timestamp=args.timestamp,
|
timestamp=args.timestamp,
|
||||||
|
|
|
@ -30,6 +30,7 @@ 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 .constants import SUCCESS, API_ERROR, CONFIG_FILE_PARSE_ERROR
|
||||||
from .logger import setup_logging
|
from .logger import setup_logging
|
||||||
from .offlinequeue import Queue
|
from .offlinequeue import Queue
|
||||||
from .packages import argparse
|
from .packages import argparse
|
||||||
|
@ -290,7 +291,7 @@ def send_heartbeat(project=None, branch=None, hostname=None, stats={}, key=None,
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not api_url:
|
if not api_url:
|
||||||
api_url = 'https://wakatime.com/api/v1/heartbeats'
|
api_url = 'https://api.wakatime.com/api/v1/heartbeats'
|
||||||
if not timeout:
|
if not timeout:
|
||||||
timeout = 30
|
timeout = 30
|
||||||
log.debug('Sending heartbeat to api at %s' % api_url)
|
log.debug('Sending heartbeat to api at %s' % api_url)
|
||||||
|
@ -408,63 +409,68 @@ def execute(argv=None):
|
||||||
|
|
||||||
args, configs = parseArguments()
|
args, configs = parseArguments()
|
||||||
if configs is None:
|
if configs is None:
|
||||||
return 103 # config file parsing error
|
return CONFIG_FILE_PARSE_ERROR
|
||||||
|
|
||||||
setup_logging(args, __version__)
|
setup_logging(args, __version__)
|
||||||
|
|
||||||
exclude = should_exclude(args.entity, args.include, args.exclude)
|
try:
|
||||||
if exclude is not False:
|
exclude = should_exclude(args.entity, args.include, args.exclude)
|
||||||
log.debug(u('Skipping because matches exclude pattern: {pattern}').format(
|
if exclude is not False:
|
||||||
pattern=u(exclude),
|
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):
|
if args.entity_type != 'file' or os.path.isfile(args.entity):
|
||||||
|
|
||||||
stats = get_file_stats(args.entity, entity_type=args.entity_type,
|
stats = get_file_stats(args.entity,
|
||||||
lineno=args.lineno, cursorpos=args.cursorpos)
|
entity_type=args.entity_type,
|
||||||
|
lineno=args.lineno,
|
||||||
|
cursorpos=args.cursorpos)
|
||||||
|
|
||||||
project = args.project or args.alternate_project
|
project = args.project or args.alternate_project
|
||||||
branch = None
|
branch = None
|
||||||
if args.entity_type == 'file':
|
if args.entity_type == 'file':
|
||||||
project, branch = get_project_info(configs, args)
|
project, branch = get_project_info(configs, args)
|
||||||
|
|
||||||
kwargs = vars(args)
|
kwargs = vars(args)
|
||||||
kwargs['project'] = project
|
kwargs['project'] = project
|
||||||
kwargs['branch'] = branch
|
kwargs['branch'] = branch
|
||||||
kwargs['stats'] = stats
|
kwargs['stats'] = stats
|
||||||
kwargs['hostname'] = args.hostname or socket.gethostname()
|
kwargs['hostname'] = args.hostname or socket.gethostname()
|
||||||
kwargs['timeout'] = args.timeout
|
kwargs['timeout'] = args.timeout
|
||||||
|
|
||||||
if send_heartbeat(**kwargs):
|
if send_heartbeat(**kwargs):
|
||||||
queue = Queue()
|
queue = Queue()
|
||||||
while True:
|
while True:
|
||||||
heartbeat = queue.pop()
|
heartbeat = queue.pop()
|
||||||
if heartbeat is None:
|
if heartbeat is None:
|
||||||
break
|
break
|
||||||
sent = send_heartbeat(
|
sent = send_heartbeat(
|
||||||
project=heartbeat['project'],
|
project=heartbeat['project'],
|
||||||
entity=heartbeat['entity'],
|
entity=heartbeat['entity'],
|
||||||
timestamp=heartbeat['time'],
|
timestamp=heartbeat['time'],
|
||||||
branch=heartbeat['branch'],
|
branch=heartbeat['branch'],
|
||||||
hostname=kwargs['hostname'],
|
hostname=kwargs['hostname'],
|
||||||
stats=json.loads(heartbeat['stats']),
|
stats=json.loads(heartbeat['stats']),
|
||||||
key=args.key,
|
key=args.key,
|
||||||
isWrite=heartbeat['is_write'],
|
isWrite=heartbeat['is_write'],
|
||||||
plugin=heartbeat['plugin'],
|
plugin=heartbeat['plugin'],
|
||||||
offline=args.offline,
|
offline=args.offline,
|
||||||
hidefilenames=args.hidefilenames,
|
hidefilenames=args.hidefilenames,
|
||||||
entity_type=heartbeat['type'],
|
entity_type=heartbeat['type'],
|
||||||
proxy=args.proxy,
|
proxy=args.proxy,
|
||||||
api_url=args.api_url,
|
api_url=args.api_url,
|
||||||
timeout=args.timeout,
|
timeout=args.timeout,
|
||||||
)
|
)
|
||||||
if not sent:
|
if not sent:
|
||||||
break
|
break
|
||||||
return 0 # success
|
return SUCCESS
|
||||||
|
|
||||||
return 102 # api error
|
return API_ERROR
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.debug('File does not exist; ignoring this heartbeat.')
|
log.debug('File does not exist; ignoring this heartbeat.')
|
||||||
return 0
|
return SUCCESS
|
||||||
|
except:
|
||||||
|
log.traceback()
|
||||||
|
|
|
@ -44,9 +44,9 @@ class Git(BaseProject):
|
||||||
with open(head, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
with open(head, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
||||||
except:
|
except:
|
||||||
log.exception("Exception:")
|
log.traceback()
|
||||||
except IOError: # pragma: nocover
|
except IOError: # pragma: nocover
|
||||||
log.exception("Exception:")
|
log.traceback()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _project_base(self):
|
def _project_base(self):
|
||||||
|
|
|
@ -42,9 +42,9 @@ class Mercurial(BaseProject):
|
||||||
with open(branch_file, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
with open(branch_file, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
||||||
except:
|
except:
|
||||||
log.exception("Exception:")
|
log.traceback()
|
||||||
except IOError: # pragma: nocover
|
except IOError: # pragma: nocover
|
||||||
log.exception("Exception:")
|
log.traceback()
|
||||||
return u('default')
|
return u('default')
|
||||||
|
|
||||||
def _find_hg_config_dir(self, path):
|
def _find_hg_config_dir(self, path):
|
||||||
|
|
|
@ -41,9 +41,9 @@ class WakaTimeProjectFile(BaseProject):
|
||||||
self._project_name = u(fh.readline().strip())
|
self._project_name = u(fh.readline().strip())
|
||||||
self._project_branch = u(fh.readline().strip())
|
self._project_branch = u(fh.readline().strip())
|
||||||
except:
|
except:
|
||||||
log.exception("Exception:")
|
log.traceback()
|
||||||
except IOError: # pragma: nocover
|
except IOError: # pragma: nocover
|
||||||
log.exception("Exception:")
|
log.traceback()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -14,7 +14,6 @@ import logging
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
@ -58,7 +57,7 @@ class SessionCache(object):
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
except: # pragma: nocover
|
except: # pragma: nocover
|
||||||
log.error(traceback.format_exc())
|
log.traceback()
|
||||||
|
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
|
@ -73,7 +72,7 @@ class SessionCache(object):
|
||||||
try:
|
try:
|
||||||
conn, c = self.connect()
|
conn, c = self.connect()
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
log.traceback()
|
||||||
return requests.session()
|
return requests.session()
|
||||||
|
|
||||||
session = None
|
session = None
|
||||||
|
@ -84,12 +83,12 @@ class SessionCache(object):
|
||||||
if row is not None:
|
if row is not None:
|
||||||
session = pickle.loads(row[0])
|
session = pickle.loads(row[0])
|
||||||
except: # pragma: nocover
|
except: # pragma: nocover
|
||||||
log.error(traceback.format_exc())
|
log.traceback()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn.close()
|
conn.close()
|
||||||
except: # pragma: nocover
|
except: # pragma: nocover
|
||||||
log.error(traceback.format_exc())
|
log.traceback()
|
||||||
|
|
||||||
return session if session is not None else requests.session()
|
return session if session is not None else requests.session()
|
||||||
|
|
||||||
|
@ -106,4 +105,4 @@ class SessionCache(object):
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
log.traceback()
|
||||||
|
|
|
@ -191,5 +191,5 @@ def get_file_contents(file_name):
|
||||||
with open(file_name, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
with open(file_name, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
text = fh.read(512000)
|
text = fh.read(512000)
|
||||||
except:
|
except:
|
||||||
log.exception("Exception:")
|
log.traceback()
|
||||||
return text
|
return text
|
||||||
|
|
Loading…
Reference in a new issue