mirror of
https://github.com/wakatime/sublime-wakatime.git
synced 2023-08-10 21:13:02 +03:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
805e2fe222 | |||
bbcb39b2cf | |||
9f9b97c69f | |||
908ff98613 | |||
37f74b4b56 | |||
a1c0d7e489 | |||
3127f264b4 | |||
049bc57019 | |||
03ec38bb67 | |||
4fc1a55ff7 | |||
f60815b813 | |||
ca47c2308d | |||
146a959747 | |||
906184cd88 | |||
a13e11d24d |
43
HISTORY.rst
43
HISTORY.rst
@ -3,6 +3,49 @@ History
|
||||
-------
|
||||
|
||||
|
||||
1.5.2 (2013-12-03)
|
||||
++++++++++++++++++
|
||||
|
||||
- use non-localized datetime in log
|
||||
|
||||
|
||||
1.5.1 (2013-12-02)
|
||||
++++++++++++++++++
|
||||
|
||||
- decode file names with filesystem encoding, then encode as utf-8 for logging
|
||||
|
||||
|
||||
1.5.0 (2013-11-28)
|
||||
++++++++++++++++++
|
||||
|
||||
- increase "ping" frequency from every 5 minutes to every 2 minutes
|
||||
- prevent sending multiple api requests when saving the same file
|
||||
|
||||
|
||||
1.4.12 (2013-11-21)
|
||||
+++++++++++++++++++
|
||||
|
||||
- handle UnicodeDecodeError exceptions when json encoding log messages
|
||||
|
||||
|
||||
1.4.11 (2013-11-13)
|
||||
+++++++++++++++++++
|
||||
|
||||
- placing .wakatime-project file in a folder will read the project's name from that file
|
||||
|
||||
|
||||
1.4.10 (2013-10-31)
|
||||
++++++++++++++++++
|
||||
|
||||
- recognize jinja2 file extensions as HTML
|
||||
|
||||
|
||||
1.4.9 (2013-10-28)
|
||||
++++++++++++++++++
|
||||
|
||||
- handle case where ignore patterns not defined
|
||||
|
||||
|
||||
1.4.8 (2013-10-27)
|
||||
++++++++++++++++++
|
||||
|
||||
|
33
WakaTime.py
33
WakaTime.py
@ -5,7 +5,7 @@ Maintainer: WakaTi.me <support@wakatime.com>
|
||||
Website: https://www.wakati.me/
|
||||
==========================================================="""
|
||||
|
||||
__version__ = '1.4.8'
|
||||
__version__ = '1.5.2'
|
||||
|
||||
import sublime
|
||||
import sublime_plugin
|
||||
@ -21,14 +21,17 @@ from os.path import expanduser, dirname, realpath, isfile, join, exists
|
||||
|
||||
|
||||
# globals
|
||||
ACTION_FREQUENCY = 5
|
||||
ACTION_FREQUENCY = 2
|
||||
ST_VERSION = int(sublime.version())
|
||||
PLUGIN_DIR = dirname(realpath(__file__))
|
||||
API_CLIENT = '%s/packages/wakatime/wakatime-cli.py' % PLUGIN_DIR
|
||||
SETTINGS_FILE = 'WakaTime.sublime-settings'
|
||||
SETTINGS = {}
|
||||
LAST_ACTION = 0
|
||||
LAST_FILE = None
|
||||
LAST_ACTION = {
|
||||
'time': 0,
|
||||
'file': None,
|
||||
'is_write': False,
|
||||
}
|
||||
HAS_SSL = False
|
||||
LOCK = threading.RLock()
|
||||
|
||||
@ -76,20 +79,24 @@ def python_binary():
|
||||
return 'python'
|
||||
|
||||
|
||||
def enough_time_passed(now):
|
||||
if now - LAST_ACTION > ACTION_FREQUENCY * 60:
|
||||
def enough_time_passed(now, last_time):
|
||||
if now - last_time > ACTION_FREQUENCY * 60:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def handle_action(view, is_write=False):
|
||||
global LOCK, LAST_FILE, LAST_ACTION
|
||||
global LOCK, LAST_ACTION
|
||||
with LOCK:
|
||||
target_file = view.file_name()
|
||||
thread = SendActionThread(target_file, is_write=is_write)
|
||||
thread.start()
|
||||
LAST_FILE = target_file
|
||||
LAST_ACTION = time.time()
|
||||
if target_file:
|
||||
thread = SendActionThread(target_file, is_write=is_write)
|
||||
thread.start()
|
||||
LAST_ACTION = {
|
||||
'file': target_file,
|
||||
'time': time.time(),
|
||||
'is_write': is_write,
|
||||
}
|
||||
|
||||
|
||||
class SendActionThread(threading.Thread):
|
||||
@ -102,12 +109,12 @@ class SendActionThread(threading.Thread):
|
||||
self.debug = SETTINGS.get('debug')
|
||||
self.api_key = SETTINGS.get('api_key', '')
|
||||
self.ignore = SETTINGS.get('ignore', [])
|
||||
self.last_file = LAST_FILE
|
||||
self.last_action = LAST_ACTION
|
||||
|
||||
def run(self):
|
||||
if self.target_file:
|
||||
self.timestamp = time.time()
|
||||
if self.force or self.is_write or self.target_file != self.last_file or enough_time_passed(self.timestamp):
|
||||
if self.force or (self.is_write and not self.last_action['is_write']) or self.target_file != self.last_action['file'] or enough_time_passed(self.timestamp, self.last_action['time']):
|
||||
self.send()
|
||||
|
||||
def send(self):
|
||||
|
@ -3,6 +3,12 @@ History
|
||||
-------
|
||||
|
||||
|
||||
0.4.10 (2013-11-13)
|
||||
+++++++++++++++++++
|
||||
|
||||
- Placing .wakatime-project file in a folder will read the project's name from that file
|
||||
|
||||
|
||||
0.4.9 (2013-10-27)
|
||||
++++++++++++++++++
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
wakatime-cli
|
||||
|
@ -12,7 +12,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
__title__ = 'wakatime'
|
||||
__version__ = '0.4.9'
|
||||
__version__ = '0.4.10'
|
||||
__author__ = 'Alan Hamlett'
|
||||
__license__ = 'BSD'
|
||||
__copyright__ = 'Copyright 2013 Alan Hamlett'
|
||||
@ -63,6 +63,9 @@ def parseConfigFile(configFile):
|
||||
'verbose': False,
|
||||
}
|
||||
|
||||
if not os.path.isfile(configFile):
|
||||
return configs
|
||||
|
||||
try:
|
||||
with open(configFile) as fh:
|
||||
for line in fh:
|
||||
@ -140,13 +143,16 @@ def parseArguments(argv):
|
||||
|
||||
|
||||
def should_ignore(fileName, patterns):
|
||||
for pattern in patterns:
|
||||
try:
|
||||
compiled = re.compile(pattern, re.IGNORECASE)
|
||||
if compiled.search(fileName):
|
||||
return pattern
|
||||
except re.error as ex:
|
||||
log.warning('Regex error (%s) for ignore pattern: %s' % (str(ex), pattern))
|
||||
try:
|
||||
for pattern in patterns:
|
||||
try:
|
||||
compiled = re.compile(pattern, re.IGNORECASE)
|
||||
if compiled.search(fileName):
|
||||
return pattern
|
||||
except re.error as ex:
|
||||
log.warning('Regex error (%s) for ignore pattern: %s' % (str(ex), pattern))
|
||||
except TypeError:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from .packages import simplejson as json
|
||||
try:
|
||||
@ -25,7 +26,13 @@ class CustomEncoder(json.JSONEncoder):
|
||||
if isinstance(obj, bytes):
|
||||
obj = bytes.decode(obj)
|
||||
return json.dumps(obj)
|
||||
return super(CustomEncoder, self).default(obj)
|
||||
try:
|
||||
encoded = super(CustomEncoder, self).default(obj)
|
||||
except UnicodeDecodeError:
|
||||
encoding = sys.getfilesystemencoding()
|
||||
obj = obj.decode(encoding, 'ignore').encode('utf-8')
|
||||
encoded = super(CustomEncoder, self).default(obj)
|
||||
return encoded
|
||||
|
||||
|
||||
class JsonFormatter(logging.Formatter):
|
||||
@ -69,7 +76,7 @@ def setup_logging(args, version):
|
||||
logger = logging.getLogger()
|
||||
set_log_level(logger, args)
|
||||
if len(logger.handlers) > 0:
|
||||
formatter = JsonFormatter(datefmt='%a %b %d %H:%M:%S %Z %Y')
|
||||
formatter = JsonFormatter(datefmt='%Y/%m/%d %H:%M:%S %z')
|
||||
formatter.setup(
|
||||
timestamp=args.timestamp,
|
||||
isWrite=args.isWrite,
|
||||
@ -83,7 +90,7 @@ def setup_logging(args, version):
|
||||
if not logfile:
|
||||
logfile = '~/.wakatime.log'
|
||||
handler = logging.FileHandler(os.path.expanduser(logfile))
|
||||
formatter = JsonFormatter(datefmt='%a %b %d %H:%M:%S %Z %Y')
|
||||
formatter = JsonFormatter(datefmt='%Y/%m/%d %H:%M:%S %z')
|
||||
formatter.setup(
|
||||
timestamp=args.timestamp,
|
||||
isWrite=args.isWrite,
|
||||
|
@ -12,6 +12,7 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from .projects.wakatime import WakaTime
|
||||
from .projects.git import Git
|
||||
from .projects.mercurial import Mercurial
|
||||
from .projects.subversion import Subversion
|
||||
@ -20,6 +21,7 @@ from .projects.subversion import Subversion
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
PLUGINS = [
|
||||
WakaTime,
|
||||
Git,
|
||||
Mercurial,
|
||||
Subversion,
|
||||
|
51
packages/wakatime/wakatime/projects/wakatime.py
Normal file
51
packages/wakatime/wakatime/projects/wakatime.py
Normal file
@ -0,0 +1,51 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
wakatime.projects.wakatime
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Information from a .wakatime-project file about the project for
|
||||
a given file.
|
||||
|
||||
:copyright: (c) 2013 Alan Hamlett.
|
||||
:license: BSD, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from .base import BaseProject
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class WakaTime(BaseProject):
|
||||
|
||||
def process(self):
|
||||
self.config = self._find_config(self.path)
|
||||
if self.config:
|
||||
return True
|
||||
return False
|
||||
|
||||
def name(self):
|
||||
project_name = None
|
||||
try:
|
||||
with open(self.config) as fh:
|
||||
project_name = fh.readline().strip()
|
||||
except IOError as e:
|
||||
log.exception("Exception:")
|
||||
return project_name
|
||||
|
||||
def branch(self):
|
||||
return None
|
||||
|
||||
def _find_config(self, path):
|
||||
path = os.path.realpath(path)
|
||||
if os.path.isfile(path):
|
||||
path = os.path.split(path)[0]
|
||||
if os.path.isfile(os.path.join(path, '.wakatime-project')):
|
||||
return os.path.join(path, '.wakatime-project')
|
||||
split_path = os.path.split(path)
|
||||
if split_path[1] == '':
|
||||
return None
|
||||
return self._find_config(split_path[0])
|
@ -25,6 +25,8 @@ log = logging.getLogger(__name__)
|
||||
|
||||
# force file name extensions to be recognized as a certain language
|
||||
EXTENSIONS = {
|
||||
'j2': 'HTML',
|
||||
'markdown': 'Markdown',
|
||||
'md': 'Markdown',
|
||||
}
|
||||
TRANSLATIONS = {
|
||||
@ -35,6 +37,7 @@ TRANSLATIONS = {
|
||||
'JavaScript+Genshi Text': 'JavaScript',
|
||||
'JavaScript+Lasso': 'JavaScript',
|
||||
'Perl6': 'Perl',
|
||||
'RHTML': 'HTML',
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user