download and install python in background thread to fix #53

This commit is contained in:
Alan Hamlett 2015-10-01 12:39:28 -07:00
parent c1da94bc18
commit c50100e675
1 changed files with 28 additions and 21 deletions

View File

@ -195,6 +195,8 @@ def handle_heartbeat(view, is_write=False):
class SendHeartbeatThread(threading.Thread):
"""Non-blocking thread for sending heartbeats to api.
"""
def __init__(self, target_file, view, is_write=False, project=None, folders=None, force=False):
threading.Thread.__init__(self)
@ -274,28 +276,11 @@ class SendHeartbeatThread(threading.Thread):
}
def plugin_loaded():
global SETTINGS
print('[WakaTime] Initializing WakaTime plugin v%s' % __version__)
class InstallPython(threading.Thread):
"""Non-blocking thread for installing Python on Windows machines.
"""
if not python_binary():
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()
def after_loaded():
if not prompt_api_key():
sublime.set_timeout(after_loaded, 500)
def install_python():
def run(self):
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':
@ -315,6 +300,28 @@ def install_python():
Popen(args)
def plugin_loaded():
global SETTINGS
print('[WakaTime] Initializing WakaTime plugin v%s' % __version__)
if not python_binary():
print('[WakaTime] Warning: Python binary not found.')
if platform.system() == 'Windows':
thread = InstallPython()
thread.start()
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()
def after_loaded():
if not prompt_api_key():
sublime.set_timeout(after_loaded, 500)
# need to call plugin_loaded because only ST3 will auto-call it
if ST_VERSION < 3000:
plugin_loaded()