display error message when python binary not found

This commit is contained in:
Alan Hamlett 2013-10-13 08:26:31 -07:00
parent 78a7e5cbcb
commit a92ebad2f2

View File

@ -89,17 +89,16 @@ def prompt_api_key():
def python_binary(): def python_binary():
python = 'python'
if platform.system() == 'Windows': if platform.system() == 'Windows':
try:
Popen(['pythonw', '--version'])
return 'pythonw'
except:
for path in glob.iglob('/python*'): for path in glob.iglob('/python*'):
if exists(realpath(join(path, 'pythonw.exe'))): if exists(realpath(join(path, 'pythonw.exe'))):
return realpath(join(path, 'pythonw')) return realpath(join(path, 'pythonw'))
try: return None
python = 'pythonw' return 'python'
Popen([python, '--version'])
except:
python = None
return python
def enough_time_passed(now): def enough_time_passed(now):
@ -166,12 +165,10 @@ class SendActionThread(threading.Thread):
print(cmd) print(cmd)
code = wakatime.main(cmd) code = wakatime.main(cmd)
if code != 0: if code != 0:
print('Error: Response code %d from wakatime package.' % code) print('Error: Response code %d from wakatime package' % code)
else: else:
python = python_binary() python = python_binary()
if not python: if python:
print('Error: Could not find python binary.')
else:
cmd.insert(0, python) cmd.insert(0, python)
if self.debug: if self.debug:
print(cmd) print(cmd)
@ -180,6 +177,8 @@ class SendActionThread(threading.Thread):
else: else:
with open(join(expanduser('~'), '.wakatime.log'), 'a') as stderr: with open(join(expanduser('~'), '.wakatime.log'), 'a') as stderr:
Popen(cmd, stderr=stderr) Popen(cmd, stderr=stderr)
else:
print('Error: Unable to find python binary.')
def plugin_loaded(): def plugin_loaded():