detect python binary by executing interpreter
This commit is contained in:
parent
60c8ea4454
commit
307029c37a
1 changed files with 25 additions and 9 deletions
30
WakaTime.py
30
WakaTime.py
|
@ -18,7 +18,7 @@ import sys
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
import webbrowser
|
import webbrowser
|
||||||
from os.path import expanduser, dirname, basename, realpath, join, exists
|
from os.path import expanduser, dirname, basename, realpath, join
|
||||||
|
|
||||||
# globals
|
# globals
|
||||||
ACTION_FREQUENCY = 2
|
ACTION_FREQUENCY = 2
|
||||||
|
@ -34,6 +34,7 @@ LAST_ACTION = {
|
||||||
}
|
}
|
||||||
HAS_SSL = False
|
HAS_SSL = False
|
||||||
LOCK = threading.RLock()
|
LOCK = threading.RLock()
|
||||||
|
PYTHON_LOCATION = None
|
||||||
|
|
||||||
# add wakatime package to path
|
# add wakatime package to path
|
||||||
sys.path.insert(0, join(PLUGIN_DIR, 'packages', 'wakatime'))
|
sys.path.insert(0, join(PLUGIN_DIR, 'packages', 'wakatime'))
|
||||||
|
@ -101,16 +102,31 @@ def prompt_api_key():
|
||||||
|
|
||||||
|
|
||||||
def python_binary():
|
def python_binary():
|
||||||
if platform.system() == 'Windows':
|
global PYTHON_LOCATION
|
||||||
|
if PYTHON_LOCATION is not None:
|
||||||
|
return PYTHON_LOCATION
|
||||||
|
paths = [
|
||||||
|
"pythonw",
|
||||||
|
"python",
|
||||||
|
"/usr/local/bin/python",
|
||||||
|
"/usr/bin/python",
|
||||||
|
]
|
||||||
|
for path in paths:
|
||||||
try:
|
try:
|
||||||
Popen(['pythonw', '--version'])
|
Popen([path, '--version'])
|
||||||
return 'pythonw'
|
PYTHON_LOCATION = path
|
||||||
|
return path
|
||||||
except:
|
except:
|
||||||
|
pass
|
||||||
for path in glob.iglob('/python*'):
|
for path in glob.iglob('/python*'):
|
||||||
if exists(realpath(join(path, 'pythonw.exe'))):
|
path = realpath(join(path, 'pythonw'))
|
||||||
return realpath(join(path, 'pythonw'))
|
try:
|
||||||
|
Popen([path, '--version'])
|
||||||
|
PYTHON_LOCATION = path
|
||||||
|
return path
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return None
|
return None
|
||||||
return 'python'
|
|
||||||
|
|
||||||
|
|
||||||
def enough_time_passed(now, last_time):
|
def enough_time_passed(now, last_time):
|
||||||
|
|
Loading…
Reference in a new issue