forked from cappuccino/cappuccino
/
capp_env
executable file
·120 lines (92 loc) · 2.93 KB
/
capp_env
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
#!/usr/bin/env python
import os
import argparse
ACTIVATE_SCRIPT = """
deactivate() {
if [ -n "$__OLD_PATH" ] ; then
PATH="$__OLD_PATH"
export PATH
unset __OLD_PATH
fi;
if [ -n "$__OLD_CAPP_BUILD" ] ; then
CAPP_BUILD="$__OLD_CAPP_BUILD"
export CAPP_BUILD
unset __OLD_CAPP_BUILD
fi;
if [ -n "$__OLD_PS1" ] ; then
PS1="$__OLD_PS1"
export PS1
unset __OLD_PS1
fi;
unset __VIRTUAL_ENV
if [ ! "$1" = "nondestructive" ] ; then
unset -f deactivate
fi
}
deactivate nondestructive
__VIRTUAL_ENV="%s"
__OLD_PATH="$PATH"
__OLD_CAPP_BUILD="$CAPP_BUILD"
__OLD_PS1="$PS1"
CAPP_BUILD="$__VIRTUAL_ENV/build"
export CAPP_BUILD
PATH="$CAPP_BUILD/Debug/CommonJS/cappuccino/bin:$CAPP_BUILD/Debug/CommonJS/objective-j/bin/:$__VIRTUAL_ENV/narwhal/bin:$PATH"
export PATH
PS1="(`basename \"$__VIRTUAL_ENV\"`)$PS1"
export PS1
"""
def exec_shell(command, error_message=None, expected=0):
"""
Execute a shell command
"""
ret = os.system(command)
if ret != expected:
if error_message:
raise Exception(error_message)
else:
raise Exception("Error during command %s. expected %d, got %d" % (command, expected, ret))
def create_environment(env_path):
"""
Create the base environement folder
"""
if os.path.exists(env_path):
print "Path already exists. abort"
return
os.makedirs(env_path)
os.makedirs("%s/sources" % env_path)
os.makedirs("%s/build" % env_path)
os.makedirs("%s/bin" % env_path)
def install_cappuccino_base(env_path):
"""
Install latest version of Cappuccino Base
"""
exec_shell("curl https://raw.githubusercontent.com/cappuccino/cappuccino/v0.9.7-1/bootstrap.sh >/tmp/cb.sh")
exec_shell("bash /tmp/cb.sh --directory '%s/narwhal' --noprompt" % (env_path))
exec_shell("rm /tmp/cb.sh")
def install_activate(env_path):
"""
Create the env/bin/activate script
"""
absolute_path = os.path.abspath(env_path)
f = open("%s/bin/activate" % env_path, 'w')
f.write(ACTIVATE_SCRIPT % absolute_path)
f.close()
exec_shell("chmod u+x %s/bin/activate" % env_path)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Virtual Env For Cappuccino.")
parser.add_argument('-p', "--path",
dest="env_path",
help="Path of the virtual environement",
required=True,
type=str)
parser.add_argument('-a', "--activate-only",
dest="activate_only",
help="Only reinstall the activate script",
action="store_true")
args = parser.parse_args()
if args.activate_only:
install_activate(args.env_path)
else:
create_environment(args.env_path)
install_cappuccino_base(args.env_path)
install_activate(args.env_path)