mirror of
https://github.com/wakatime/sublime-wakatime.git
synced 2023-08-10 21:13:02 +03:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
4be40c7720 | |||
eeb7fd8219 | |||
11fbd2d2a6 | |||
3cecd0de5d | |||
c50100e675 | |||
c1da94bc18 |
12
HISTORY.rst
12
HISTORY.rst
@ -3,6 +3,18 @@ History
|
|||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
||||||
|
4.0.18 (2015-10-01)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- find python location from windows registry
|
||||||
|
|
||||||
|
|
||||||
|
4.0.17 (2015-10-01)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- download python in non blocking background thread for Windows machines
|
||||||
|
|
||||||
|
|
||||||
4.0.16 (2015-09-29)
|
4.0.16 (2015-09-29)
|
||||||
++++++++++++++++++
|
++++++++++++++++++
|
||||||
|
|
||||||
|
153
WakaTime.py
153
WakaTime.py
@ -7,15 +7,15 @@ Website: https://wakatime.com/
|
|||||||
==========================================================="""
|
==========================================================="""
|
||||||
|
|
||||||
|
|
||||||
__version__ = '4.0.16'
|
__version__ = '4.0.18'
|
||||||
|
|
||||||
|
|
||||||
import sublime
|
import sublime
|
||||||
import sublime_plugin
|
import sublime_plugin
|
||||||
|
|
||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
@ -23,6 +23,10 @@ import urllib
|
|||||||
import webbrowser
|
import webbrowser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
try:
|
||||||
|
import _winreg as winreg # py2
|
||||||
|
except ImportError:
|
||||||
|
import winreg # py3
|
||||||
|
|
||||||
|
|
||||||
# globals
|
# globals
|
||||||
@ -101,6 +105,8 @@ def python_binary():
|
|||||||
global PYTHON_LOCATION
|
global PYTHON_LOCATION
|
||||||
if PYTHON_LOCATION is not None:
|
if PYTHON_LOCATION is not None:
|
||||||
return PYTHON_LOCATION
|
return PYTHON_LOCATION
|
||||||
|
|
||||||
|
# look for python in PATH and common install locations
|
||||||
paths = [
|
paths = [
|
||||||
"pythonw",
|
"pythonw",
|
||||||
"python",
|
"python",
|
||||||
@ -108,20 +114,88 @@ def python_binary():
|
|||||||
"/usr/bin/python",
|
"/usr/bin/python",
|
||||||
]
|
]
|
||||||
for path in paths:
|
for path in paths:
|
||||||
try:
|
path = find_python_in_folder(path)
|
||||||
Popen([path, '--version'])
|
if path is not None:
|
||||||
PYTHON_LOCATION = path
|
PYTHON_LOCATION = path
|
||||||
return path
|
return path
|
||||||
except:
|
|
||||||
pass
|
# look for python in windows registry
|
||||||
for path in glob.iglob('/python*'):
|
path = find_python_from_registry(r'SOFTWARE\Python\PythonCore')
|
||||||
path = os.path.realpath(os.path.join(path, 'pythonw'))
|
if path is not None:
|
||||||
try:
|
PYTHON_LOCATION = path
|
||||||
Popen([path, '--version'])
|
return path
|
||||||
PYTHON_LOCATION = path
|
path = find_python_from_registry(r'SOFTWARE\Wow6432Node\Python\PythonCore')
|
||||||
return path
|
if path is not None:
|
||||||
except:
|
PYTHON_LOCATION = path
|
||||||
pass
|
return path
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def find_python_from_registry(location, reg=None):
|
||||||
|
if platform.system() != 'Windows':
|
||||||
|
return None
|
||||||
|
|
||||||
|
if reg is None:
|
||||||
|
path = find_python_from_registry(location, reg=winreg.HKEY_CURRENT_USER)
|
||||||
|
if path is None:
|
||||||
|
path = find_python_from_registry(location, reg=winreg.HKEY_LOCAL_MACHINE)
|
||||||
|
return path
|
||||||
|
|
||||||
|
val = None
|
||||||
|
sub_key = 'InstallPath'
|
||||||
|
compiled = re.compile(r'^\d+\.\d+$')
|
||||||
|
|
||||||
|
try:
|
||||||
|
with winreg.OpenKey(reg, location) as handle:
|
||||||
|
versions = []
|
||||||
|
try:
|
||||||
|
for index in range(1024):
|
||||||
|
version = winreg.EnumKey(handle, index)
|
||||||
|
try:
|
||||||
|
if compiled.search(version):
|
||||||
|
versions.append(version)
|
||||||
|
except re.error:
|
||||||
|
pass
|
||||||
|
except EnvironmentError:
|
||||||
|
pass
|
||||||
|
versions.sort(reverse=True)
|
||||||
|
for version in versions:
|
||||||
|
try:
|
||||||
|
path = winreg.QueryValue(handle, version + '\\' + sub_key)
|
||||||
|
if path is not None:
|
||||||
|
path = find_python_in_folder(path)
|
||||||
|
if path is not None:
|
||||||
|
return path
|
||||||
|
except WindowsError:
|
||||||
|
print('[WakaTime] Warning: Could not read registry value "{reg}\\{key}\\{version}\\{sub_key}".'.format(
|
||||||
|
reg='HKEY_CURRENT_USER',
|
||||||
|
key=location,
|
||||||
|
version=version,
|
||||||
|
sub_key=sub_key,
|
||||||
|
))
|
||||||
|
except WindowsError:
|
||||||
|
print('[WakaTime] Warning: Could not read registry value "{reg}\\{key}".'.format(
|
||||||
|
reg='HKEY_CURRENT_USER',
|
||||||
|
key=location,
|
||||||
|
))
|
||||||
|
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
def find_python_in_folder(folder):
|
||||||
|
path = os.path.realpath(os.path.join(folder, 'pythonw'))
|
||||||
|
try:
|
||||||
|
Popen([path, '--version'])
|
||||||
|
return path
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
path = os.path.realpath(os.path.join(folder, 'python'))
|
||||||
|
try:
|
||||||
|
Popen([path, '--version'])
|
||||||
|
return path
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -133,7 +207,7 @@ def obfuscate_apikey(command_list):
|
|||||||
apikey_index = num + 1
|
apikey_index = num + 1
|
||||||
break
|
break
|
||||||
if apikey_index is not None and apikey_index < len(cmd):
|
if apikey_index is not None and apikey_index < len(cmd):
|
||||||
cmd[apikey_index] = '********-****-****-****-********' + cmd[apikey_index][-4:]
|
cmd[apikey_index] = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX' + cmd[apikey_index][-4:]
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
@ -195,6 +269,8 @@ def handle_heartbeat(view, is_write=False):
|
|||||||
|
|
||||||
|
|
||||||
class SendHeartbeatThread(threading.Thread):
|
class SendHeartbeatThread(threading.Thread):
|
||||||
|
"""Non-blocking thread for sending heartbeats to api.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, target_file, view, is_write=False, project=None, folders=None, force=False):
|
def __init__(self, target_file, view, is_write=False, project=None, folders=None, force=False):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
@ -274,6 +350,30 @@ class SendHeartbeatThread(threading.Thread):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class InstallPython(threading.Thread):
|
||||||
|
"""Non-blocking thread for installing Python on Windows machines.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
print('[WakaTime] Downloading and installing python...')
|
||||||
|
url = 'https://www.python.org/ftp/python/3.4.3/python-3.4.3.msi'
|
||||||
|
if platform.architecture()[0] == '64bit':
|
||||||
|
url = 'https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64.msi'
|
||||||
|
python_msi = os.path.join(os.path.expanduser('~'), 'python.msi')
|
||||||
|
try:
|
||||||
|
urllib.urlretrieve(url, python_msi)
|
||||||
|
except AttributeError:
|
||||||
|
urllib.request.urlretrieve(url, python_msi)
|
||||||
|
args = [
|
||||||
|
'msiexec',
|
||||||
|
'/i',
|
||||||
|
python_msi,
|
||||||
|
'/norestart',
|
||||||
|
'/qb!',
|
||||||
|
]
|
||||||
|
Popen(args)
|
||||||
|
|
||||||
|
|
||||||
def plugin_loaded():
|
def plugin_loaded():
|
||||||
global SETTINGS
|
global SETTINGS
|
||||||
print('[WakaTime] Initializing WakaTime plugin v%s' % __version__)
|
print('[WakaTime] Initializing WakaTime plugin v%s' % __version__)
|
||||||
@ -281,7 +381,8 @@ def plugin_loaded():
|
|||||||
if not python_binary():
|
if not python_binary():
|
||||||
print('[WakaTime] Warning: Python binary not found.')
|
print('[WakaTime] Warning: Python binary not found.')
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
install_python()
|
thread = InstallPython()
|
||||||
|
thread.start()
|
||||||
else:
|
else:
|
||||||
sublime.error_message("Unable to find Python binary!\nWakaTime needs Python to work correctly.\n\nGo to https://www.python.org/downloads")
|
sublime.error_message("Unable to find Python binary!\nWakaTime needs Python to work correctly.\n\nGo to https://www.python.org/downloads")
|
||||||
return
|
return
|
||||||
@ -295,26 +396,6 @@ def after_loaded():
|
|||||||
sublime.set_timeout(after_loaded, 500)
|
sublime.set_timeout(after_loaded, 500)
|
||||||
|
|
||||||
|
|
||||||
def install_python():
|
|
||||||
print('[WakaTime] Downloading and installing python...')
|
|
||||||
url = 'https://www.python.org/ftp/python/3.4.3/python-3.4.3.msi'
|
|
||||||
if platform.architecture()[0] == '64bit':
|
|
||||||
url = 'https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64.msi'
|
|
||||||
python_msi = os.path.join(os.path.expanduser('~'), 'python.msi')
|
|
||||||
try:
|
|
||||||
urllib.urlretrieve(url, python_msi)
|
|
||||||
except AttributeError:
|
|
||||||
urllib.request.urlretrieve(url, python_msi)
|
|
||||||
args = [
|
|
||||||
'msiexec',
|
|
||||||
'/i',
|
|
||||||
python_msi,
|
|
||||||
'/norestart',
|
|
||||||
'/qb!',
|
|
||||||
]
|
|
||||||
Popen(args)
|
|
||||||
|
|
||||||
|
|
||||||
# need to call plugin_loaded because only ST3 will auto-call it
|
# need to call plugin_loaded because only ST3 will auto-call it
|
||||||
if ST_VERSION < 3000:
|
if ST_VERSION < 3000:
|
||||||
plugin_loaded()
|
plugin_loaded()
|
||||||
|
@ -10,9 +10,16 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from . import TokenParser
|
from . import TokenParser
|
||||||
|
from ..compat import u
|
||||||
|
|
||||||
|
|
||||||
class CSharpParser(TokenParser):
|
class CSharpParser(TokenParser):
|
||||||
|
exclude = [
|
||||||
|
r'^system$',
|
||||||
|
r'^microsoft$',
|
||||||
|
]
|
||||||
|
state = None
|
||||||
|
buffer = u('')
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
for index, token, content in self.tokens:
|
for index, token, content in self.tokens:
|
||||||
@ -20,14 +27,38 @@ class CSharpParser(TokenParser):
|
|||||||
return self.dependencies
|
return self.dependencies
|
||||||
|
|
||||||
def _process_token(self, token, content):
|
def _process_token(self, token, content):
|
||||||
if self.partial(token) == 'Namespace':
|
if self.partial(token) == 'Keyword':
|
||||||
|
self._process_keyword(token, content)
|
||||||
|
if self.partial(token) == 'Namespace' or self.partial(token) == 'Name':
|
||||||
self._process_namespace(token, content)
|
self._process_namespace(token, content)
|
||||||
|
elif self.partial(token) == 'Punctuation':
|
||||||
|
self._process_punctuation(token, content)
|
||||||
else:
|
else:
|
||||||
self._process_other(token, content)
|
self._process_other(token, content)
|
||||||
|
|
||||||
|
def _process_keyword(self, token, content):
|
||||||
|
if content == 'using':
|
||||||
|
self.state = 'import'
|
||||||
|
self.buffer = u('')
|
||||||
|
|
||||||
def _process_namespace(self, token, content):
|
def _process_namespace(self, token, content):
|
||||||
if content != 'import' and content != 'package' and content != 'namespace':
|
if self.state == 'import':
|
||||||
self.append(content, truncate=True)
|
if u(content) != u('import') and u(content) != u('package') and u(content) != u('namespace') and u(content) != u('static'):
|
||||||
|
if u(content) == u(';'): # pragma: nocover
|
||||||
|
self._process_punctuation(token, content)
|
||||||
|
else:
|
||||||
|
self.buffer += u(content)
|
||||||
|
|
||||||
|
def _process_punctuation(self, token, content):
|
||||||
|
if self.state == 'import':
|
||||||
|
if u(content) == u(';'):
|
||||||
|
self.append(self.buffer, truncate=True)
|
||||||
|
self.buffer = u('')
|
||||||
|
self.state = None
|
||||||
|
elif u(content) == u('='):
|
||||||
|
self.buffer = u('')
|
||||||
|
else:
|
||||||
|
self.buffer += u(content)
|
||||||
|
|
||||||
def _process_other(self, token, content):
|
def _process_other(self, token, content):
|
||||||
pass
|
pass
|
||||||
|
@ -61,10 +61,10 @@ class PhpParser(TokenParser):
|
|||||||
|
|
||||||
def _process_literal_string(self, token, content):
|
def _process_literal_string(self, token, content):
|
||||||
if self.state == 'include':
|
if self.state == 'include':
|
||||||
if content != '"':
|
if content != '"' and content != "'":
|
||||||
content = content.strip()
|
content = content.strip()
|
||||||
if u(token) == 'Token.Literal.String.Double':
|
if u(token) == 'Token.Literal.String.Double':
|
||||||
content = u('"{0}"').format(content)
|
content = u("'{0}'").format(content)
|
||||||
self.append(content)
|
self.append(content)
|
||||||
self.state = None
|
self.state = None
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user