find python binary on Windows even if not in system path
This commit is contained in:
parent
8d259a6c00
commit
998d0b2066
1 changed files with 24 additions and 6 deletions
|
@ -47,15 +47,30 @@ if not isfile(join(expanduser('~'), '.wakatime.conf')):
|
||||||
sublime.active_window().show_input_panel('Enter your WakaTi.me api key:', '', got_key, None, None)
|
sublime.active_window().show_input_panel('Enter your WakaTi.me api key:', '', got_key, None, None)
|
||||||
|
|
||||||
|
|
||||||
|
def python_binary():
|
||||||
|
python = 'python'
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
try:
|
||||||
|
Popen([python, '--version'])
|
||||||
|
except:
|
||||||
|
for path in glob.iglob('/python*'):
|
||||||
|
if exists(realpath(join(path, 'python.exe'))):
|
||||||
|
python = realpath(join(path, 'python'))
|
||||||
|
break
|
||||||
|
try:
|
||||||
|
Popen([python+'w', '--version'])
|
||||||
|
python = python+'w'
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return python
|
||||||
|
|
||||||
|
|
||||||
def api(targetFile, timestamp, isWrite=False, endtime=0):
|
def api(targetFile, timestamp, isWrite=False, endtime=0):
|
||||||
global LAST_ACTION, LAST_USAGE, LAST_FILE
|
global LAST_ACTION, LAST_USAGE, LAST_FILE
|
||||||
if not targetFile:
|
if not targetFile:
|
||||||
targetFile = LAST_FILE
|
targetFile = LAST_FILE
|
||||||
if targetFile:
|
if targetFile:
|
||||||
python = 'python'
|
cmd = [python_binary(), API_CLIENT,
|
||||||
if platform.system() == 'Windows' and exists(python+'w'):
|
|
||||||
python = python+'w'
|
|
||||||
cmd = [python, API_CLIENT,
|
|
||||||
'--file', targetFile,
|
'--file', targetFile,
|
||||||
'--time', str('%f' % timestamp),
|
'--time', str('%f' % timestamp),
|
||||||
'--plugin', 'sublime-wakatime/%s' % __version__,
|
'--plugin', 'sublime-wakatime/%s' % __version__,
|
||||||
|
@ -66,8 +81,11 @@ def api(targetFile, timestamp, isWrite=False, endtime=0):
|
||||||
if endtime:
|
if endtime:
|
||||||
cmd.extend(['--endtime', str('%f' % endtime)])
|
cmd.extend(['--endtime', str('%f' % endtime)])
|
||||||
#print(cmd)
|
#print(cmd)
|
||||||
with open(join(expanduser('~'), '.wakatime.log'), 'a') as stderr:
|
if platform.system() == 'Windows':
|
||||||
Popen(cmd, stderr=stderr)
|
Popen(cmd)
|
||||||
|
else:
|
||||||
|
with open(join(expanduser('~'), '.wakatime.log'), 'a') as stderr:
|
||||||
|
Popen(cmd, stderr=stderr)
|
||||||
LAST_ACTION = timestamp
|
LAST_ACTION = timestamp
|
||||||
if endtime and endtime > LAST_ACTION:
|
if endtime and endtime > LAST_ACTION:
|
||||||
LAST_ACTION = endtime
|
LAST_ACTION = endtime
|
||||||
|
|
Loading…
Reference in a new issue