forked from checkbox/checkbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk-venv
executable file
·129 lines (111 loc) · 4.11 KB
/
mk-venv
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
# Create a virtualenv for working with plainbox.
#
# This ensures that 'plainbox' command exists and is in PATH and that the
# plainbox module is correctly located can be imported.
#
# This is how Zygmunt Krynicki works, feel free to use or adjust to your needs
CHECKBOX_VENV_PATH=
# Parse arguments:
while [ -n "$1" ]; do
case "$1" in
--help|-h)
echo "Usage: mk-venv.sh [LOCATION]"
echo ""
echo "Create a virtualenv for working with checkbox in LOCATION"
exit 0
;;
*)
if [ -z "$CHECKBOX_VENV_PATH" ]; then
CHECKBOX_VENV_PATH="$1"
shift
else
echo "Error: too many arguments: '$1'"
exit 1
fi
;;
esac
done
# Apply defaults to arguments without values
if [ -z "$CHECKBOX_VENV_PATH" ]; then
# Use sensible defaults for vagrant
if [ "$LOGNAME" = "vagrant" ]; then
CHECKBOX_VENV_PATH=/tmp/venv
else
CHECKBOX_VENV_PATH=/ramdisk/venv
fi
fi
# Check if we can create a virtualenv
if [ ! -d $(dirname $CHECKBOX_VENV_PATH) ]; then
echo "E: This script requires $(dirname $CHECKBOX_VENV_PATH) directory to exist"
echo "E: You can use different directory by passing it as argument"
echo "E: For a quick temporary location just pass /tmp/venv"
exit 1
fi
# Check if there's one already there
if [ -d $CHECKBOX_VENV_PATH ]; then
echo "E: $CHECKBOX_VENV_PATH seems to already exist"
exit 1
fi
# Do a sanity check on lsb_release that is missing on Fedora the last time I
# had a look at it.
if [ "x$(which lsb_release)" = "x" ]; then
echo "This script requires the 'lsb_release' command"
exit 1
fi
# The code below is a mixture of Debian/Ubuntu packages and pypi packages.
# It is designed to work on Ubuntu 12.04 or later.
# There are _some_ differences between how each release is handled.
#
# Non Ubuntu systems are not tested as they don't have the required checkbox
# package. Debian might be supported once we have JobBox and stuff like Fedora
# would need a whole new approach but patches are welcome [CLA required]
if [ "$(lsb_release --short --id)" != "Ubuntu" ] && [ $(lsb_release --short --id --upstream) != "Ubuntu" ]; then
echo "Only Ubuntu is supported by this script."
echo "If you are interested in using it with your distribution"
echo "then please join us in #ubuntu-quality on freenode"
echo
echo "Alternatively you can use vagrant to develop plainbox"
echo "on any operating system, even Windows ;-)"
echo
echo "See: http://www.vagrantup.com/ for details"
exit 1
fi
# From now on we can assume a Debian-like system
# Find the top of checkbox tree
if [ "$CHECKBOX_TOP" = "" ]; then
CHECKBOX_TOP="$(git rev-parse --show-toplevel 2>/dev/null)"
fi
if [ "$CHECKBOX_TOP" = "" ]; then
CHECKBOX_TOP="$(bzr root)"
fi
# Export it for all the sub-scripts
export CHECKBOX_TOP
# Add any necessary PPA repositories and run apt-get update if required
if $CHECKBOX_TOP/support/install-ppa-dependencies; then
# we need to update our dependencies
sudo apt-get update
fi
# Ensure that all Debian dependencies are installed
$CHECKBOX_TOP/support/install-deb-dependencies
# Create a virtualenv with python3
echo "I: creating virtualbox in $CHECKBOX_VENV_PATH"
virtualenv --quiet --system-site-packages --python=/usr/bin/python3 $CHECKBOX_VENV_PATH
# Activate the virtualenv
. $CHECKBOX_VENV_PATH/bin/activate
# Make sure that external-tarballs is ready
$CHECKBOX_TOP/support/get-external-tarballs
# Make sure that checkbox-packaging is ready
$CHECKBOX_TOP/support/get-checkbox-packaging
# Install all the python dependencies
$CHECKBOX_TOP/support/install-pip-dependencies
# Develop all the local projects
$CHECKBOX_TOP/support/develop-projects
# Enable tab-completion.
# NOTE: This might be totally useless but hey,
# if someone has sourced this script it will work.
. $CHECKBOX_TOP/support/enable-tab-completion
echo "To activate your virtualenv run:"
echo "$ . $CHECKBOX_VENV_PATH/bin/activate"
echo "To enable tab completion run:"
echo "$ . $CHECKBOX_TOP/support/enable-tab-completion"