changeset 2206:85840f06e1ac

quickinstall: Rewrite * Rewrite in Python * Remove not longer needed special handling of Babel and translations * Move default output into parent directory * Only support one parameter: the destination
author Bastian Blank <bblank@thinkmo.de>
date Wed, 16 Oct 2013 05:35:04 +0200
parents 90ef29715d9e
children 88ec5e5d18aa
files quickinstall quickinstall.bat quickinstall.py
diffstat 3 files changed, 52 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/quickinstall	Tue Oct 15 21:04:06 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-#!/bin/bash
-# create a virtual environment in directory $DIR/
-#
-# set PYTHON environment variable to change the python version
-# set DIR environment variable to change the virtual env directory
-# set VIRTUALENV environment variable to change the virtualenv command
-# for example: PYTHON=/usr/bin/pypy DIR=env-pypy ./quickinstall
-#
-# needs: virtualenv, pip
-
-DLC=dlc
-
-# if DIR is not given, use ./env
-if [ -z "$DIR" ]; then
-    DIR=env
-fi
-
-# find the right python version
-if [ -z "$PYTHON" ]; then
-    for PYTHON in python{2.7,2,}; do
-        hash $PYTHON 2>&- && break
-    done
-fi
-
-# find the right virtualenv version
-if [ -z "$VIRTUALENV" ]; then
-    for VIRTUALENV in virtualenv{2.7,2,}; do
-        hash $VIRTUALENV 2>&- && break
-    done
-fi
-
-$VIRTUALENV --no-site-packages --python $PYTHON $DIR || exit 1
-
-source $DIR/bin/activate || exit 1
-
-# first install babel, moin's setup.py will emit a warning if it is not there
-pip install --download-cache=$DLC babel || exit 1
-
-# "install" moin2 from repo to the env, this will also install required python
-# packages from pypi. we do this LAST, so that breakage is better visible.
-pip install --download-cache=$DLC -e . || exit 1
-
-# compile the translations
-python setup.py compile_catalog --statistics || exit 1
-
--- a/quickinstall.bat	Tue Oct 15 21:04:06 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-echo off
-echo.
-echo This is the windows version of the "quickinstall" file.
-echo.
-
-echo Creating a virtual environment in directory env/ ...
-virtualenv --no-site-packages env
-
-echo Activating virtual environment ...
-call env\Scripts\activate.bat
-
-echo Installing babel first ...
-pip install --download-cache=dlc babel
-
-echo Installing all required python packages from pypi ...
-pip install --download-cache=dlc -e .
-
-echo Compiling translations (not required if wiki is English only) ...
-python setup.py compile_catalog --statistics
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/quickinstall.py	Wed Oct 16 05:35:04 2013 +0200
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+import argparse
+import logging
+import os.path
+import subprocess
+import sys
+import virtualenv
+
+
+class QuickInstall(object):
+    def __init__(self, source, venv=None):
+        self.dir_source = source
+        if not venv:
+            base, source_name = os.path.split(source)
+            venv = os.path.join(base, 'venv-{}-{}'.format(source_name, os.path.basename(sys.executable)))
+        self.dir_venv = venv
+
+    def __call__(self):
+        self.do_venv()
+        self.do_install()
+
+        sys.stdout.write('''
+Succesfully created or updated venv
+  {0}
+You can run MoinMoin as
+  {0}/bin/moin
+'''.format(self.dir_venv))
+
+    def do_venv(self):
+        virtualenv.create_environment(self.dir_venv)
+
+    def do_install(self):
+        subprocess.check_call((
+            os.path.join(self.dir_venv, 'bin', 'pip'),
+            'install',
+            # XXX: move cache to XDG cache dir
+            '--download-cache',
+            os.path.join(os.path.dirname(self.dir_venv), '.pip-download-cache'),
+            '--editable',
+            self.dir_source
+        ))
+
+
+if __name__ == '__main__':
+    logging.basicConfig(level=logging.INFO)
+
+    parser = argparse.ArgumentParser()
+    parser.add_argument('venv', metavar='VENV', nargs='?', help='location of v(irtual)env')
+    args = parser.parse_args()
+
+    QuickInstall(os.path.dirname(os.path.realpath(sys.argv[0])), venv=args.venv)()