mirror of
https://github.com/wakatime/sublime-wakatime.git
synced 2023-08-10 21:13:02 +03:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
311a0b5309 | |||
b7602d89fb | |||
305de46e32 | |||
c574234927 | |||
a69c50f470 | |||
f4b40089f3 | |||
08394357b7 | |||
205d4eb163 |
14
HISTORY.rst
14
HISTORY.rst
@ -3,6 +3,20 @@ History
|
||||
-------
|
||||
|
||||
|
||||
7.0.14 (2017-02-08)
|
||||
++++++++++++++++++
|
||||
|
||||
- Upgrade wakatime-cli to v6.2.1.
|
||||
- Allow boolean or list of regex patterns for hidefilenames config setting.
|
||||
|
||||
|
||||
7.0.13 (2016-11-11)
|
||||
++++++++++++++++++
|
||||
|
||||
- Support old Sublime Text with Python 2.6.
|
||||
- Fix bug that prevented reading default api key from existing config file.
|
||||
|
||||
|
||||
7.0.12 (2016-10-24)
|
||||
++++++++++++++++++
|
||||
|
||||
|
26
WakaTime.py
26
WakaTime.py
@ -7,12 +7,13 @@ Website: https://wakatime.com/
|
||||
==========================================================="""
|
||||
|
||||
|
||||
__version__ = '7.0.12'
|
||||
__version__ = '7.0.14'
|
||||
|
||||
|
||||
import sublime
|
||||
import sublime_plugin
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
@ -20,11 +21,12 @@ import re
|
||||
import sys
|
||||
import time
|
||||
import threading
|
||||
import traceback
|
||||
import urllib
|
||||
import webbrowser
|
||||
from datetime import datetime
|
||||
from zipfile import ZipFile
|
||||
from subprocess import Popen, STDOUT, PIPE
|
||||
from zipfile import ZipFile
|
||||
try:
|
||||
import _winreg as winreg # py2
|
||||
except ImportError:
|
||||
@ -45,6 +47,8 @@ if is_py2:
|
||||
def u(text):
|
||||
if text is None:
|
||||
return None
|
||||
if isinstance(text, unicode):
|
||||
return text
|
||||
try:
|
||||
return text.decode('utf-8')
|
||||
except:
|
||||
@ -54,7 +58,13 @@ if is_py2:
|
||||
try:
|
||||
return unicode(text)
|
||||
except:
|
||||
return text.decode('utf-8', 'replace')
|
||||
try:
|
||||
return text.decode('utf-8', 'replace')
|
||||
except:
|
||||
try:
|
||||
return unicode(str(text))
|
||||
except:
|
||||
return unicode('')
|
||||
|
||||
elif is_py3:
|
||||
def u(text):
|
||||
@ -107,7 +117,7 @@ ERROR = 'ERROR'
|
||||
# add wakatime package to path
|
||||
sys.path.insert(0, os.path.join(PLUGIN_DIR, 'packages'))
|
||||
try:
|
||||
from wakatime.base import parseConfigFile
|
||||
from wakatime.main import parseConfigFile
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
@ -305,6 +315,12 @@ def find_python_from_registry(location, reg=None):
|
||||
reg=reg,
|
||||
key=location,
|
||||
))
|
||||
except:
|
||||
log(ERROR, 'Could not read registry value "{reg}\\{key}":\n{exc}'.format(
|
||||
reg=reg,
|
||||
key=location,
|
||||
exc=traceback.format_exc(),
|
||||
))
|
||||
|
||||
return val
|
||||
|
||||
@ -592,7 +608,7 @@ class DownloadPython(threading.Thread):
|
||||
urllib.request.urlretrieve(url, zip_file)
|
||||
|
||||
log(INFO, 'Extracting Python...')
|
||||
with ZipFile(zip_file) as zf:
|
||||
with contextlib.closing(ZipFile(zip_file)) as zf:
|
||||
path = os.path.join(resources_folder(), 'python')
|
||||
zf.extractall(path)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
__title__ = 'wakatime'
|
||||
__description__ = 'Common interface to the WakaTime api.'
|
||||
__url__ = 'https://github.com/wakatime/wakatime'
|
||||
__version_info__ = ('6', '2', '0')
|
||||
__version_info__ = ('6', '2', '1')
|
||||
__version__ = '.'.join(__version_info__)
|
||||
__author__ = 'Alan Hamlett'
|
||||
__author_email__ = 'alan@wakatime.com'
|
||||
|
@ -238,10 +238,23 @@ def parseArguments():
|
||||
args.include.append(pattern)
|
||||
except TypeError: # pragma: nocover
|
||||
pass
|
||||
if args.hidefilenames:
|
||||
args.hidefilenames = ['.*']
|
||||
else:
|
||||
args.hidefilenames = []
|
||||
if configs.has_option('settings', 'hidefilenames'):
|
||||
option = configs.get('settings', 'hidefilenames')
|
||||
if option.strip().lower() == 'true':
|
||||
args.hidefilenames = ['.*']
|
||||
elif option.strip().lower() != 'false':
|
||||
try:
|
||||
for pattern in option.split("\n"):
|
||||
if pattern.strip() != '':
|
||||
args.hidefilenames.append(pattern)
|
||||
except TypeError:
|
||||
pass
|
||||
if args.offline and configs.has_option('settings', 'offline'):
|
||||
args.offline = configs.getboolean('settings', 'offline')
|
||||
if not args.hidefilenames and configs.has_option('settings', 'hidefilenames'):
|
||||
args.hidefilenames = configs.getboolean('settings', 'hidefilenames')
|
||||
if not args.proxy and configs.has_option('settings', 'proxy'):
|
||||
args.proxy = configs.get('settings', 'proxy')
|
||||
if not args.verbose and configs.has_option('settings', 'verbose'):
|
||||
@ -266,32 +279,26 @@ def parseArguments():
|
||||
|
||||
def should_exclude(entity, include, exclude):
|
||||
if entity is not None and entity.strip() != '':
|
||||
try:
|
||||
for pattern in include:
|
||||
try:
|
||||
compiled = re.compile(pattern, re.IGNORECASE)
|
||||
if compiled.search(entity):
|
||||
return False
|
||||
except re.error as ex:
|
||||
log.warning(u('Regex error ({msg}) for include pattern: {pattern}').format(
|
||||
msg=u(ex),
|
||||
pattern=u(pattern),
|
||||
))
|
||||
except TypeError: # pragma: nocover
|
||||
pass
|
||||
try:
|
||||
for pattern in exclude:
|
||||
try:
|
||||
compiled = re.compile(pattern, re.IGNORECASE)
|
||||
if compiled.search(entity):
|
||||
return pattern
|
||||
except re.error as ex:
|
||||
log.warning(u('Regex error ({msg}) for exclude pattern: {pattern}').format(
|
||||
msg=u(ex),
|
||||
pattern=u(pattern),
|
||||
))
|
||||
except TypeError: # pragma: nocover
|
||||
pass
|
||||
for pattern in include:
|
||||
try:
|
||||
compiled = re.compile(pattern, re.IGNORECASE)
|
||||
if compiled.search(entity):
|
||||
return False
|
||||
except re.error as ex:
|
||||
log.warning(u('Regex error ({msg}) for include pattern: {pattern}').format(
|
||||
msg=u(ex),
|
||||
pattern=u(pattern),
|
||||
))
|
||||
for pattern in exclude:
|
||||
try:
|
||||
compiled = re.compile(pattern, re.IGNORECASE)
|
||||
if compiled.search(entity):
|
||||
return pattern
|
||||
except re.error as ex:
|
||||
log.warning(u('Regex error ({msg}) for exclude pattern: {pattern}').format(
|
||||
msg=u(ex),
|
||||
pattern=u(pattern),
|
||||
))
|
||||
return False
|
||||
|
||||
|
||||
@ -336,8 +343,18 @@ def send_heartbeat(project=None, branch=None, hostname=None, stats={}, key=None,
|
||||
'type': entity_type,
|
||||
}
|
||||
if hidefilenames and entity is not None and entity_type == 'file':
|
||||
extension = u(os.path.splitext(data['entity'])[1])
|
||||
data['entity'] = u('HIDDEN{0}').format(extension)
|
||||
for pattern in hidefilenames:
|
||||
try:
|
||||
compiled = re.compile(pattern, re.IGNORECASE)
|
||||
if compiled.search(entity):
|
||||
extension = u(os.path.splitext(data['entity'])[1])
|
||||
data['entity'] = u('HIDDEN{0}').format(extension)
|
||||
break
|
||||
except re.error as ex:
|
||||
log.warning(u('Regex error ({msg}) for include pattern: {pattern}').format(
|
||||
msg=u(ex),
|
||||
pattern=u(pattern),
|
||||
))
|
||||
if stats.get('lines'):
|
||||
data['lines'] = stats['lines']
|
||||
if stats.get('language'):
|
||||
|
Reference in New Issue
Block a user