From 78a7e5cbcbde6b816a8583a0559d4a09cea3477e Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Sat, 12 Oct 2013 21:52:40 -0700 Subject: [PATCH] only use pythonw.exe on Windows platform and display error in Sublime Console instead of using python.exe --- WakaTime.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/WakaTime.py b/WakaTime.py index 8d65578..e4a44b6 100644 --- a/WakaTime.py +++ b/WakaTime.py @@ -91,14 +91,14 @@ def prompt_api_key(): def python_binary(): python = 'python' if platform.system() == 'Windows': - python = 'pythonw' + for path in glob.iglob('/python*'): + if exists(realpath(join(path, 'pythonw.exe'))): + return realpath(join(path, 'pythonw')) try: + python = 'pythonw' Popen([python, '--version']) except: - for path in glob.iglob('/python*'): - if exists(realpath(join(path, 'pythonw.exe'))): - python = realpath(join(path, 'pythonw')) - break + python = None return python @@ -166,16 +166,20 @@ class SendActionThread(threading.Thread): print(cmd) code = wakatime.main(cmd) if code != 0: - print('Error: Response code %d from wakatime package' % code) + print('Error: Response code %d from wakatime package.' % code) else: - cmd.insert(0, python_binary()) - if self.debug: - print(cmd) - if platform.system() == 'Windows': - Popen(cmd, shell=False) + python = python_binary() + if not python: + print('Error: Could not find python binary.') else: - with open(join(expanduser('~'), '.wakatime.log'), 'a') as stderr: - Popen(cmd, stderr=stderr) + cmd.insert(0, python) + if self.debug: + print(cmd) + 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():