forked from luna/vim-rana-local
upgrade wakatime cli to v4.1.1
This commit is contained in:
parent
a9e199f61c
commit
e7b61e0b29
11 changed files with 70 additions and 28 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', '0')
|
__version_info__ = ('4', '1', '1')
|
||||||
__version__ = '.'.join(__version_info__)
|
__version__ = '.'.join(__version_info__)
|
||||||
__author__ = 'Alan Hamlett'
|
__author__ = 'Alan Hamlett'
|
||||||
__author_email__ = 'alan@wakatime.com'
|
__author_email__ = 'alan@wakatime.com'
|
||||||
|
|
|
@ -22,7 +22,7 @@ sys.path.insert(0, package_folder)
|
||||||
# import local wakatime package
|
# import local wakatime package
|
||||||
try:
|
try:
|
||||||
import wakatime
|
import wakatime
|
||||||
except TypeError:
|
except (TypeError, ImportError):
|
||||||
# on Windows, non-ASCII characters in import path can be fixed using
|
# on Windows, non-ASCII characters in import path can be fixed using
|
||||||
# the script path from sys.argv[0].
|
# the script path from sys.argv[0].
|
||||||
# More info at https://github.com/wakatime/wakatime/issues/32
|
# More info at https://github.com/wakatime/wakatime/issues/32
|
||||||
|
|
|
@ -20,6 +20,8 @@ is_py3 = (sys.version_info[0] == 3)
|
||||||
if is_py2: # pragma: nocover
|
if is_py2: # pragma: nocover
|
||||||
|
|
||||||
def u(text):
|
def u(text):
|
||||||
|
if text is None:
|
||||||
|
return None
|
||||||
try:
|
try:
|
||||||
return text.decode('utf-8')
|
return text.decode('utf-8')
|
||||||
except:
|
except:
|
||||||
|
@ -34,6 +36,8 @@ if is_py2: # pragma: nocover
|
||||||
elif is_py3: # pragma: nocover
|
elif is_py3: # pragma: nocover
|
||||||
|
|
||||||
def u(text):
|
def u(text):
|
||||||
|
if text is None:
|
||||||
|
return None
|
||||||
if isinstance(text, bytes):
|
if isinstance(text, bytes):
|
||||||
return text.decode('utf-8')
|
return text.decode('utf-8')
|
||||||
return str(text)
|
return str(text)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from ..compat import u, open, import_module
|
from ..compat import u, open, import_module
|
||||||
|
@ -53,8 +54,16 @@ class TokenParser(object):
|
||||||
|
|
||||||
def _extract_tokens(self):
|
def _extract_tokens(self):
|
||||||
if self.lexer:
|
if self.lexer:
|
||||||
|
try:
|
||||||
with open(self.source_file, 'r', encoding='utf-8') as fh:
|
with open(self.source_file, 'r', encoding='utf-8') as fh:
|
||||||
return self.lexer.get_tokens_unprocessed(fh.read(512000))
|
return self.lexer.get_tokens_unprocessed(fh.read(512000))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
with open(self.source_file, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
|
return self.lexer.get_tokens_unprocessed(fh.read(512000))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def _save_dependency(self, dep, truncate=False, separator=None,
|
def _save_dependency(self, dep, truncate=False, separator=None,
|
||||||
|
|
|
@ -21,6 +21,8 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_SQL = False
|
HAS_SQL = False
|
||||||
|
|
||||||
|
from .compat import u
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger('WakaTime')
|
log = logging.getLogger('WakaTime')
|
||||||
|
|
||||||
|
@ -50,16 +52,16 @@ class Queue(object):
|
||||||
try:
|
try:
|
||||||
conn, c = self.connect()
|
conn, c = self.connect()
|
||||||
heartbeat = {
|
heartbeat = {
|
||||||
'file': data.get('entity'),
|
'file': u(data.get('entity')),
|
||||||
'time': data.get('time'),
|
'time': data.get('time'),
|
||||||
'project': data.get('project'),
|
'project': u(data.get('project')),
|
||||||
'branch': data.get('branch'),
|
'branch': u(data.get('branch')),
|
||||||
'is_write': 1 if data.get('is_write') else 0,
|
'is_write': 1 if data.get('is_write') else 0,
|
||||||
'stats': stats,
|
'stats': u(stats),
|
||||||
'misc': misc,
|
'misc': u(misc),
|
||||||
'plugin': plugin,
|
'plugin': u(plugin),
|
||||||
}
|
}
|
||||||
c.execute('INSERT INTO heartbeat VALUES (:file,:time,:project,:branch,:is_write,:stats,:misc,:plugin)', heartbeat)
|
c.execute(u('INSERT INTO heartbeat VALUES (:file,:time,:project,:branch,:is_write,:stats,:misc,:plugin)'), heartbeat)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
except sqlite3.Error:
|
except sqlite3.Error:
|
||||||
|
@ -90,14 +92,14 @@ class Queue(object):
|
||||||
for row_name in ['file', 'time', 'project', 'branch', 'is_write']:
|
for row_name in ['file', 'time', 'project', 'branch', 'is_write']:
|
||||||
if row[index] is not None:
|
if row[index] is not None:
|
||||||
clauses.append('{0}=?'.format(row_name))
|
clauses.append('{0}=?'.format(row_name))
|
||||||
values.append(row[index])
|
values.append(u(row[index]))
|
||||||
else:
|
else:
|
||||||
clauses.append('{0} IS NULL'.format(row_name))
|
clauses.append('{0} IS NULL'.format(row_name))
|
||||||
index += 1
|
index += 1
|
||||||
if len(values) > 0:
|
if len(values) > 0:
|
||||||
c.execute('DELETE FROM heartbeat WHERE {0}'.format(' AND '.join(clauses)), values)
|
c.execute(u('DELETE FROM heartbeat WHERE {0}').format(u(' AND ').join(clauses)), values)
|
||||||
else:
|
else:
|
||||||
c.execute('DELETE FROM heartbeat WHERE {0}'.format(' AND '.join(clauses)))
|
c.execute(u('DELETE FROM heartbeat WHERE {0}').format(u(' AND ').join(clauses)))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
if row is not None:
|
if row is not None:
|
||||||
heartbeat = {
|
heartbeat = {
|
||||||
|
|
|
@ -21,12 +21,8 @@ except ImportError:
|
||||||
"""Return the preferred certificate bundle."""
|
"""Return the preferred certificate bundle."""
|
||||||
# vendored bundle inside Requests
|
# vendored bundle inside Requests
|
||||||
is_py3 = (sys.version_info[0] == 3)
|
is_py3 = (sys.version_info[0] == 3)
|
||||||
certdir = os.path.dirname(
|
cacert = os.path.join(os.path.dirname(__file__), 'cacert.pem')
|
||||||
__file__
|
return cacert.encode('utf-8') if is_py3 else cacert
|
||||||
if is_py3 else
|
|
||||||
__file__.decode(sys.getfilesystemencoding())
|
|
||||||
)
|
|
||||||
return os.path.join(certdir, 'cacert.pem')
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(where())
|
print(where())
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from .base import BaseProject
|
from .base import BaseProject
|
||||||
from ..compat import u, open
|
from ..compat import u, open
|
||||||
|
@ -38,8 +39,14 @@ class Git(BaseProject):
|
||||||
try:
|
try:
|
||||||
with open(head, 'r', encoding='utf-8') as fh:
|
with open(head, 'r', encoding='utf-8') as fh:
|
||||||
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
with open(head, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
|
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
||||||
|
except:
|
||||||
|
log.exception("Exception:")
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
log.exception("Exception:")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _project_base(self):
|
def _project_base(self):
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from .base import BaseProject
|
from .base import BaseProject
|
||||||
from ..compat import u, open
|
from ..compat import u, open
|
||||||
|
@ -36,8 +37,14 @@ class Mercurial(BaseProject):
|
||||||
try:
|
try:
|
||||||
with open(branch_file, 'r', encoding='utf-8') as fh:
|
with open(branch_file, 'r', encoding='utf-8') as fh:
|
||||||
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
with open(branch_file, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
|
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
||||||
|
except:
|
||||||
|
log.exception("Exception:")
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
log.exception("Exception:")
|
||||||
return u('default')
|
return u('default')
|
||||||
|
|
||||||
def _find_hg_config_dir(self, path):
|
def _find_hg_config_dir(self, path):
|
||||||
|
|
|
@ -46,8 +46,8 @@ class Subversion(BaseProject):
|
||||||
'/usr/local/bin/svn',
|
'/usr/local/bin/svn',
|
||||||
]
|
]
|
||||||
for location in locations:
|
for location in locations:
|
||||||
with open(os.devnull, 'wb') as DEVNULL:
|
|
||||||
try:
|
try:
|
||||||
|
with open(os.devnull, 'wb') as DEVNULL:
|
||||||
Popen([location, '--version'], stdout=DEVNULL, stderr=DEVNULL)
|
Popen([location, '--version'], stdout=DEVNULL, stderr=DEVNULL)
|
||||||
self.binary_location = location
|
self.binary_location = location
|
||||||
return location
|
return location
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from .base import BaseProject
|
from .base import BaseProject
|
||||||
from ..compat import u, open
|
from ..compat import u, open
|
||||||
|
@ -34,6 +35,13 @@ class WakaTimeProjectFile(BaseProject):
|
||||||
with open(self.config, 'r', encoding='utf-8') as fh:
|
with open(self.config, 'r', encoding='utf-8') as fh:
|
||||||
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 UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
with open(self.config, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
|
self._project_name = u(fh.readline().strip())
|
||||||
|
self._project_branch = u(fh.readline().strip())
|
||||||
|
except:
|
||||||
|
log.exception("Exception:")
|
||||||
except IOError:
|
except IOError:
|
||||||
log.exception("Exception:")
|
log.exception("Exception:")
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,11 @@ def number_lines_in_file(file_name):
|
||||||
with open(file_name, 'r', encoding='utf-8') as fh:
|
with open(file_name, 'r', encoding='utf-8') as fh:
|
||||||
for line in fh:
|
for line in fh:
|
||||||
lines += 1
|
lines += 1
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
with open(file_name, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
|
for line in fh:
|
||||||
|
lines += 1
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
return lines
|
return lines
|
||||||
|
@ -180,5 +185,9 @@ def get_file_contents(file_name):
|
||||||
with open(file_name, 'r', encoding='utf-8') as fh:
|
with open(file_name, 'r', encoding='utf-8') as fh:
|
||||||
text = fh.read(512000)
|
text = fh.read(512000)
|
||||||
except:
|
except:
|
||||||
pass
|
try:
|
||||||
|
with open(file_name, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||||
|
text = fh.read(512000)
|
||||||
|
except:
|
||||||
|
log.exception("Exception:")
|
||||||
return text
|
return text
|
||||||
|
|
Loading…
Reference in a new issue