using subprocess when Sublime Text embedded python does not support SSL.
This commit is contained in:
parent
b89356b3e7
commit
8a9b9d0c91
1 changed files with 30 additions and 5 deletions
33
WakaTime.py
33
WakaTime.py
|
@ -30,10 +30,15 @@ SETTINGS = {}
|
||||||
LAST_ACTION = 0
|
LAST_ACTION = 0
|
||||||
LAST_FILE = None
|
LAST_FILE = None
|
||||||
BUSY = False
|
BUSY = False
|
||||||
|
HAS_SSL = False
|
||||||
|
|
||||||
|
try:
|
||||||
sys.path.insert(0, join(PLUGIN_DIR, 'packages', 'wakatime'))
|
import ssl
|
||||||
import wakatime
|
HAS_SSL = True
|
||||||
|
sys.path.insert(0, join(PLUGIN_DIR, 'packages', 'wakatime'))
|
||||||
|
import wakatime
|
||||||
|
except ImportError:
|
||||||
|
from subprocess import Popen
|
||||||
|
|
||||||
|
|
||||||
def setup_settings_file():
|
def setup_settings_file():
|
||||||
|
@ -80,6 +85,18 @@ def get_api_key():
|
||||||
print('Error: Could not prompt for api key because no window found.')
|
print('Error: Could not prompt for api key because no window found.')
|
||||||
return api_key
|
return api_key
|
||||||
|
|
||||||
|
def python_binary():
|
||||||
|
python = 'python'
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
python = 'pythonw'
|
||||||
|
try:
|
||||||
|
Popen([python, '--version'])
|
||||||
|
except:
|
||||||
|
for path in glob.iglob('/python*'):
|
||||||
|
if exists(realpath(join(path, 'pythonw.exe'))):
|
||||||
|
python = realpath(join(path, 'pythonw'))
|
||||||
|
break
|
||||||
|
return python
|
||||||
|
|
||||||
def enough_time_passed(now):
|
def enough_time_passed(now):
|
||||||
if now - LAST_ACTION > ACTION_FREQUENCY * 60:
|
if now - LAST_ACTION > ACTION_FREQUENCY * 60:
|
||||||
|
@ -127,12 +144,20 @@ class SendActionThread(threading.Thread):
|
||||||
'--time', str('%f' % self.timestamp),
|
'--time', str('%f' % self.timestamp),
|
||||||
'--plugin', 'sublime-wakatime/%s' % __version__,
|
'--plugin', 'sublime-wakatime/%s' % __version__,
|
||||||
'--key', str(bytes.decode(api_key.encode('utf8'))),
|
'--key', str(bytes.decode(api_key.encode('utf8'))),
|
||||||
'--verbose',
|
#'--verbose',
|
||||||
]
|
]
|
||||||
if self.isWrite:
|
if self.isWrite:
|
||||||
cmd.append('--write')
|
cmd.append('--write')
|
||||||
#print(cmd)
|
#print(cmd)
|
||||||
|
if HAS_SSL:
|
||||||
wakatime.main(cmd)
|
wakatime.main(cmd)
|
||||||
|
else:
|
||||||
|
cmd.insert(0, python_binary())
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
Popen(cmd, shell=False)
|
||||||
|
else:
|
||||||
|
with open(join(expanduser('~'), '.wakatime.log'), 'a') as stderr:
|
||||||
|
Popen(cmd, stderr=stderr)
|
||||||
|
|
||||||
|
|
||||||
def plugin_loaded():
|
def plugin_loaded():
|
||||||
|
|
Loading…
Reference in a new issue