use embeddable python on Windows instead of installing python
This commit is contained in:
parent
c90a4863e9
commit
1fdda0d64a
1 changed files with 20 additions and 14 deletions
34
WakaTime.py
34
WakaTime.py
|
@ -22,6 +22,7 @@ import threading
|
||||||
import urllib
|
import urllib
|
||||||
import webbrowser
|
import webbrowser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from zipfile import ZipFile
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
try:
|
try:
|
||||||
import _winreg as winreg # py2
|
import _winreg as winreg # py2
|
||||||
|
@ -131,6 +132,7 @@ def python_binary():
|
||||||
|
|
||||||
# look for python in PATH and common install locations
|
# look for python in PATH and common install locations
|
||||||
paths = [
|
paths = [
|
||||||
|
os.path.join(os.path.expanduser('~'), '.wakatime', 'python'),
|
||||||
None,
|
None,
|
||||||
'/',
|
'/',
|
||||||
'/usr/local/bin/',
|
'/usr/local/bin/',
|
||||||
|
@ -395,22 +397,26 @@ class InstallPython(threading.Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
log(INFO, 'Downloading and installing python...')
|
log(INFO, 'Downloading and installing python...')
|
||||||
url = 'https://www.python.org/ftp/python/3.4.3/python-3.4.3.msi'
|
|
||||||
if platform.architecture()[0] == '64bit':
|
ver = '3.5.0'
|
||||||
url = 'https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64.msi'
|
arch = 'amd64' if platform.architecture()[0] == '64bit' else 'win32'
|
||||||
python_msi = os.path.join(os.path.expanduser('~'), 'python.msi')
|
url = 'https://www.python.org/ftp/python/{ver}/python-{ver}-embed-{arch}.zip'.format(
|
||||||
|
ver=ver,
|
||||||
|
arch=arch,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not os.path.exists(os.path.join(os.path.expanduser('~'), '.wakatime')):
|
||||||
|
os.makedirs(os.path.join(os.path.expanduser('~'), '.wakatime'))
|
||||||
|
|
||||||
|
zip_file = os.path.join(os.path.expanduser('~'), '.wakatime', 'python.zip')
|
||||||
try:
|
try:
|
||||||
urllib.urlretrieve(url, python_msi)
|
urllib.urlretrieve(url, zip_file)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
urllib.request.urlretrieve(url, python_msi)
|
urllib.request.urlretrieve(url, zip_file)
|
||||||
args = [
|
|
||||||
'msiexec',
|
with ZipFile(zip_file) as zf:
|
||||||
'/i',
|
path = os.path.join(os.path.expanduser('~'), '.wakatime', 'python')
|
||||||
python_msi,
|
zf.extractall(path)
|
||||||
'/norestart',
|
|
||||||
'/qb!',
|
|
||||||
]
|
|
||||||
Popen(args)
|
|
||||||
|
|
||||||
|
|
||||||
def plugin_loaded():
|
def plugin_loaded():
|
||||||
|
|
Loading…
Reference in a new issue