-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatou
executable file
·98 lines (74 loc) · 2.71 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
#!/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', '')
develop = os.environ.get('BATOU_DEVELOP', 'hg+https://bitbucket.org/flyingcircus/batou#egg=batou')
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.
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>=1.2"')
base = os.path.dirname(__file__) or '.'
os.chdir(base)
# 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 version == BOOTSTRAP_VERSION_MARKER:
# we're bootstrapping a new project. just get whatever version.
# this will self-destruct this file later. :)
develop = ''
spec = '--egg batou'
if missing:
print('Pre-installing batou - this can take a while...')
if develop:
spec = '-e {}'.format(develop)
else:
spec = '--egg batou=={}'.format(version)
cmd('.batou/bin/pip install --ignore-installed {}'.format(spec))
if '--fast' 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)