From 865b0bcee96b26af62a20994b270ea7d6336d8de Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Fri, 31 Jul 2015 15:19:56 -0700 Subject: [PATCH] install python on Windows if not already installed --- WakaTime.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/WakaTime.py b/WakaTime.py index 7aa1f32..9da55cb 100644 --- a/WakaTime.py +++ b/WakaTime.py @@ -19,6 +19,7 @@ import platform import sys import time import threading +import urllib import webbrowser from datetime import datetime from subprocess import Popen @@ -278,8 +279,12 @@ def plugin_loaded(): print('[WakaTime] Initializing WakaTime plugin v%s' % __version__) if not python_binary(): - sublime.error_message("Unable to find Python binary!\nWakaTime needs Python to work correctly.\n\nGo to https://www.python.org/downloads") - return + print('[WakaTime] Warning: Python binary not found.') + if platform.system() == 'Windows': + install_python() + else: + sublime.error_message("Unable to find Python binary!\nWakaTime needs Python to work correctly.\n\nGo to https://www.python.org/downloads") + return SETTINGS = sublime.load_settings(SETTINGS_FILE) after_loaded() @@ -290,6 +295,23 @@ def after_loaded(): sublime.set_timeout(after_loaded, 500) +def install_python(): + print('[WakaTime] Downloading and installing python...') + url = 'https://www.python.org/ftp/python/3.4.3/python-3.4.3.msi' + if platform.architecture()[0] == '64bit': + url = 'https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64.msi' + python_msi = os.path.join(os.path.expanduser('~'), 'python.msi') + urllib.urlretrieve(url, python_msi) + args = [ + 'msiexec', + '/i', + python_msi, + '/norestart', + '/qb!', + ] + Popen(args) + + # need to call plugin_loaded because only ST3 will auto-call it if ST_VERSION < 3000: plugin_loaded()