-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatou
executable file
·110 lines (83 loc) · 2.98 KB
/
batou
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python2.7
#
# This file is managed by batou. Don't edit directly. Use the './batou update'
# command to adjust versions.
#
# This file is intended to be as small as possible getting batou working
# somehow and then use that code to continue.
import os
import shutil
import sys
import subprocess
# We use this to trick the simple templating so you can
# download and copy this file to bootstrap a new batou installation.
BOOTSTRAP_VERSION_MARKER = '{' + '{version}' + '}'
version = os.environ.get('BATOU_VERSION', '1.7.5')
develop = os.environ.get('BATOU_DEVELOP', '')
def cmd(c, quiet=False):
try:
subprocess.check_output([c], stderr=subprocess.PIPE, shell=True)
except subprocess.CalledProcessError as e:
if not quiet:
print("{} returned with exit code {}".format(c, e.returncode))
print(e.output)
raise
def install_venv():
print('Preparing virtualenv in .batou ...')
# Discover the right venv cmd. Or let batou figure that out later in a
# second phase?
# XXX Give advice if virtualenv isn't there.
for fast in ['-F', '--fast']:
while fast in sys.argv:
sys.argv.remove(fast)
cmd('virtualenv --python=python2.7 .batou')
def install_pip():
# XXX give advice if we can't get the right pip version
cmd('.batou/bin/pip install "pip>=8.0"')
base = os.path.dirname(__file__) or '.'
os.chdir(base)
# clear PYTHONPATH variable to get a defined environment
if 'PYTHONPATH' in os.environ:
del os.environ['PYTHONPATH']
if '--reset' in sys.argv:
print "Resetting batou env ..."
cmd('rm -rf .batou')
# Do we have a virtualenv?
if not os.path.exists(base + '/.batou'):
install_venv()
def prepare():
global version, develop
try:
install_pip()
except Exception:
# Hum. This venv is probably broken. Remove and restart."
shutil.rmtree('.batou')
install_venv()
install_pip()
try:
cmd('.batou/bin/python -c \'import batou.bootstrap\'', quiet=True)
except Exception:
missing = True
else:
missing = False
if missing or develop:
if missing:
print('Pre-installing batou - this can take a while...')
if version == BOOTSTRAP_VERSION_MARKER:
# we're bootstrapping a new project. just get whatever version.
# this will self-destruct this file later. :)
develop = ''
spec = 'batou --pre'
elif develop:
spec = '-e {}'.format(develop)
else:
spec = 'batou=={}'.format(version)
cmd('.batou/bin/pip install --ignore-installed {}'.format(spec))
if '--fast' not in sys.argv and '-F' not in sys.argv:
prepare()
os.environ['BATOU_VERSION'] = version
os.environ['BATOU_DEVELOP'] = develop
# Pass control over the bare-bone batou's bootstrapping code. Good luck!
os.execv('.batou/bin/python',
['.batou/bin/python', '-c',
'import batou.bootstrap; batou.bootstrap.bootstrap()'] + sys.argv)