forked from luna/vim-rana-local
upgrade wakatime-cli to v4.1.8
This commit is contained in:
parent
9fd813c489
commit
d6d31db5f0
6 changed files with 70 additions and 59 deletions
|
@ -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,
|
||||||
|
|
|
@ -412,59 +412,64 @@ def execute(argv=None):
|
||||||
|
|
||||||
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 0
|
||||||
|
|
||||||
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 0 # success
|
||||||
|
|
||||||
return 102 # api error
|
return 102 # 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 0
|
||||||
|
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
|
||||||
|
|
|
@ -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