Merge pull request #72 from lektor/feature/install-windows
Same dialog as in unix install script and small fixes
This commit is contained in:
commit
3bcd146b44
|
@ -5,12 +5,13 @@ import json
|
|||
import urllib
|
||||
import tempfile
|
||||
import tarfile
|
||||
import shutil
|
||||
from subprocess import Popen
|
||||
from _winreg import OpenKey, CloseKey, QueryValueEx, SetValueEx, \
|
||||
HKEY_CURRENT_USER, KEY_ALL_ACCESS, REG_EXPAND_SZ
|
||||
import ctypes
|
||||
from ctypes.wintypes import HWND, UINT, WPARAM, LPARAM, LPVOID
|
||||
import shutil
|
||||
|
||||
|
||||
VENV_URL = 'https://pypi.python.org/pypi/virtualenv/json'
|
||||
APPDATA = os.environ['LocalAppData']
|
||||
|
@ -23,14 +24,18 @@ HWND_BROADCAST = 0xFFFF
|
|||
WM_SETTINGCHANGE = 0x1A
|
||||
|
||||
|
||||
def get_location():
|
||||
install_dir = os.path.join(APPDATA, APP)
|
||||
return install_dir
|
||||
def get_confirmation():
|
||||
while 1:
|
||||
input = raw_input('Continue? [Yn] ').lower().strip()
|
||||
if input in ('', 'y'):
|
||||
break
|
||||
elif input == 'n':
|
||||
print
|
||||
print 'Aborted!'
|
||||
sys.exit()
|
||||
|
||||
def find_location():
|
||||
install_dir = get_location()
|
||||
if os.path.exists(install_dir) and os.path.isdir(install_dir):
|
||||
return None, None
|
||||
install_dir = os.path.join(APPDATA, APP)
|
||||
return install_dir, os.path.join(install_dir, LIB)
|
||||
|
||||
def deletion_error(func, path, excinfo):
|
||||
|
@ -39,6 +44,19 @@ def deletion_error(func, path, excinfo):
|
|||
print 'Aborted!'
|
||||
sys.exit()
|
||||
|
||||
def wipe_installation(install_dir):
|
||||
shutil.rmtree(install_dir, onerror=deletion_error)
|
||||
|
||||
def check_installation(install_dir):
|
||||
if os.path.exists(install_dir):
|
||||
print ' Lektor seems to be installed already.'
|
||||
print ' Continuing will delete:'
|
||||
print ' %s' % install_dir
|
||||
print
|
||||
get_confirmation()
|
||||
print
|
||||
wipe_installation(install_dir)
|
||||
|
||||
def fail(message):
|
||||
print 'Error: %s' % message
|
||||
sys.exit(1)
|
||||
|
@ -74,10 +92,10 @@ def install(virtualenv_url, virtualenv_filename, install_dir, lib_dir):
|
|||
os.makedirs(install_dir)
|
||||
os.makedirs(lib_dir)
|
||||
|
||||
Popen(['python', 'virtualenv.py', lib_dir],
|
||||
Popen([sys.executable, 'virtualenv.py', lib_dir],
|
||||
cwd=os.path.join(t, virtualenv_filename)).wait()
|
||||
|
||||
scripts = os.path.join(lib_dir, 'Scripts')
|
||||
#just using pip.exe and cwd will still install globally
|
||||
Popen([os.path.join(scripts, 'pip.exe'),
|
||||
'install', '--upgrade', 'Lektor'],
|
||||
cwd=scripts).wait()
|
||||
|
@ -90,37 +108,20 @@ def install(virtualenv_url, virtualenv_filename, install_dir, lib_dir):
|
|||
|
||||
|
||||
def main():
|
||||
print
|
||||
print 'Welcome to Lektor'
|
||||
print
|
||||
print 'This script will install Lektor on your computer.'
|
||||
print
|
||||
|
||||
install_dir, lib_dir = find_location()
|
||||
if install_dir == None:
|
||||
print ' Lektor seems to be already installed at:'
|
||||
print ' {}'.format(get_location())
|
||||
while 1:
|
||||
input = raw_input(
|
||||
'Delete existing and reinstall? [Yn]'
|
||||
).lower().strip()
|
||||
|
||||
if input in ('', 'y'):
|
||||
shutil.rmtree(get_location(), onerror=deletion_error)
|
||||
break
|
||||
elif input == 'n':
|
||||
print 'Aborted!'
|
||||
sys.exit()
|
||||
check_installation(install_dir)
|
||||
|
||||
install_dir, lib_dir = find_location()
|
||||
|
||||
print ' Installing at: %s' % install_dir
|
||||
while 1:
|
||||
input = raw_input('Continue? [Yn] ').lower().strip()
|
||||
if input in ('', 'y'):
|
||||
break
|
||||
elif input == 'n':
|
||||
print 'Aborted!'
|
||||
sys.exit()
|
||||
print ' Installing at:'
|
||||
print ' %s' % install_dir
|
||||
print
|
||||
get_confirmation()
|
||||
|
||||
for url in json.load(urllib.urlopen(VENV_URL))['urls']:
|
||||
if url['python_version'] == 'source':
|
||||
|
|
Loading…
Reference in New Issue