Fix Python 3 import problems in install scripts

This commit is contained in:
David Baumgold 2017-06-16 10:50:54 -04:00
parent 63551fca17
commit ca22f06a5b
2 changed files with 11 additions and 5 deletions

View File

@ -2,11 +2,14 @@ $InstallScript = @"
import os import os
import sys import sys
import json import json
import urllib
import tempfile import tempfile
import tarfile import tarfile
import shutil import shutil
from subprocess import Popen from subprocess import Popen
try:
from urllib.request import urlopen
except ImportError:
from urllib import urlopen
from _winreg import OpenKey, CloseKey, QueryValueEx, SetValueEx, \ from _winreg import OpenKey, CloseKey, QueryValueEx, SetValueEx, \
HKEY_CURRENT_USER, KEY_ALL_ACCESS, REG_EXPAND_SZ HKEY_CURRENT_USER, KEY_ALL_ACCESS, REG_EXPAND_SZ
import ctypes import ctypes
@ -87,7 +90,7 @@ def add_to_path(location):
def install(virtualenv_url, virtualenv_filename, install_dir, lib_dir): def install(virtualenv_url, virtualenv_filename, install_dir, lib_dir):
t = tempfile.mkdtemp() t = tempfile.mkdtemp()
with open(os.path.join(t, 'virtualenv.tar.gz'), 'wb') as f: with open(os.path.join(t, 'virtualenv.tar.gz'), 'wb') as f:
download = urllib.urlopen(virtualenv_url) download = urlopen(virtualenv_url)
f.write(download.read()) f.write(download.read())
download.close() download.close()
with tarfile.open(os.path.join(t, 'virtualenv.tar.gz'), 'r:gz') as tar: with tarfile.open(os.path.join(t, 'virtualenv.tar.gz'), 'r:gz') as tar:
@ -127,7 +130,7 @@ def main():
print() print()
get_confirmation() get_confirmation()
for url in json.load(urllib.urlopen(VENV_URL))['urls']: for url in json.load(urlopen(VENV_URL))['urls']:
if url['python_version'] == 'source': if url['python_version'] == 'source':
virtualenv_url = url['url'] virtualenv_url = url['url']
#stripping '.tar.gz' #stripping '.tar.gz'

View File

@ -22,10 +22,13 @@ if 1:
import os import os
import sys import sys
import json import json
import urllib
import tempfile import tempfile
import shutil import shutil
from subprocess import Popen from subprocess import Popen
try:
from urllib.request import urlopen
except ImportError:
from urllib import urlopen
PY2 = sys.version_info[0] == 2 PY2 = sys.version_info[0] == 2
if PY2: if PY2:
@ -143,7 +146,7 @@ if 1:
get_confirmation() get_confirmation()
for url in json.load(urllib.urlopen(VENV_URL))['urls']: for url in json.load(urlopen(VENV_URL))['urls']:
if url['python_version'] == 'source': if url['python_version'] == 'source':
virtualenv = url['url'] virtualenv = url['url']
break break