forked from autopulated/yotta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_yotta.py
221 lines (196 loc) · 6.58 KB
/
get_yotta.py
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#
# This is a script to install yotta. Eventually I would like to add all OS's to this script
# but for now it just works on windows.
#
# There are some ganky hacks in place holding it together, such as opening
# IE to get certificates that windows doesnt have. Currently the script
# just downloads the dependencies and has the user run through the click
# throughs. Eventually I would like to hack together some silent installers
# which would involve some exe brute forcing and some registry hacking.
#
# copyright ARMmbed 2014
#
# Author: Austin Blackstone
# Date: December 17,2014
import math
import sys
import pip
import os
import subprocess
#
# Downloads to download
#
# Note that on windows the '.exe' extension is necessary to run with a subprocess
downloads = {
"all":{
"cmake.exe":"http://www.cmake.org/files/v3.2/cmake-3.2.1-win32-x86.exe",
"ninja.zip":"https://github.com/martine/ninja/releases/download/v1.5.3/ninja-win.zip",
"gcc.exe":"https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q3-update/+download/gcc-arm-none-eabi-4_8-2014q3-20140805-win32.exe"
},
"64bit":{
},
"32bit":{
}
}
#
# Prompt to re-install / download packages
#
def shouldInstall(binName):
import shutil
import shutilwhich
question = "\n\t"+binName+" already exists on your PATH, would you like to reinstall it? (y/n): "
choice = ""
if shutil.which(binName):
sys.stdout.write(question)
choice = raw_input().lower() # check for a y for yes, all others are no
dir(choice)
if choice =='y':
return True #re-install bin
else:
print("\n\tSkipping installation of "+binName)
return False #skip installation
else:
return True; #bin does not exist, install it
#
# Cygwin Install Script - TODO
#
def cygwin():
print("Cygwin is not currently supported. Please install for the windows command line. See http://docs.yottabuild.org/#installing-on-windows for details.");
return;
#
# Linux Install Script - TODO
#
def linux():
print("For Linux install instructions please see http://docs.yottabuild.org/#installing-on-linux");
return;
#
# OSX Install Script - TODO
#
def osx():
print("For OSX install instructions please see http://docs.yottabuild.org/#installing-on-osx");
return;
#
# Windows Install Script
#
def windows():
import wget
import shutil
import shutilwhich
print("\nOpening an Internet Explorer window to launchpad.net to grab security certificate to download GCC.");
w = subprocess.Popen(r'"C:\Program Files\Internet Explorer\iexplore.exe" https://launchpad.net/' ); #hack to get the security certificate in place so we can dowload the file.
print("\nDownloading dependencies...");
# Downloads for both 64bit / 32bit
for key in downloads['all']:
if os.path.isfile(key):
print("\n\t" +key +" already exists in this folder. [Skipped]");
else:
print("\n\tDownloading " +key);
wget.download(downloads['all'][key],key);
w.kill(); #close the internet explorer window hack
# 64bit Downloads
if sys.maxsize > math.pow(2,32):
print("\nWindows 64bit detected");
for key in downloads['64bit']:
if os.path.isfile(key):
print("\n\t" +key +" already exists in this folder.[Skipped]");
else:
print("\n\tDownloading " +key );
wget.download(downloads['64bit'][key],key);
# 32bit Downloads
elif sys.maxsize <= math.pow(2,32):
print("\nWindows 32bit detected");
for key in downloads['32bit']:
if os.path.isfile(key):
print("\n\t" +key +" already exists in this folder. [Skipped]");
else:
print("\n\tDownloading " +key);
wget.download(downloads['32bit'][key],key);
# Install the Packages
print("\nInstalling packages: Please Follow the Click Throughs ");
#Yotta
if shouldInstall("yotta"):
print("\n\tInstalling Yotta from pip ...");
x = subprocess.call(['pip','install','-qU','yotta']);
if x!= 0:
print("\t[**ERROR**]: Yotta install failed. Please run 'pip install yotta -U' from the command line");
else:
print("\t[Installed]");
#cmake
if shouldInstall("cmake"):
print("\n\tInstalling Cmake: Please allow admin permissions and check 'Add CMake to system PATH for all users' option");
x = subprocess.call(['cmake.exe'], shell=True);
if x!=0:
print("\t[**ERROR**]: Cmake install failed, Please re-run installer and give admin rights to installer");
else:
print("\t[Installed]");
#gcc-arm-none-eabi
if shouldInstall("arm-none-eabi-gcc"):
print("\n\tInstalling gcc-none-eabi-gcc : Please allow admin permissions and check 'Add path to enviroment variable' box");
x = subprocess.call(['gcc.exe'], shell=True);
if x!=0:
print("\t[**ERROR**]: gcc-none-eabi-gcc install failed, Please re-run installer and give admin rights to installer");
else:
print("\t[Installed]");
#ninja
if shouldInstall("ninja"):
import zipfile
import shutil
print("\n\tInstalling Ninja...");
zipfile.ZipFile('ninja.zip').extract('ninja.exe');
if not os.path.exists('c:/ninja'):
os.makedirs('c:/ninja');
shutil.copy2('ninja.exe','c:/ninja/ninja.exe')
print("\t**REQUIRED:** Add c:/ninja/ to your PATH to complete ninja install")
#
# install extra packages for python
#
def bootstrap():
# check for Pip
try:
import pip
except ImportError:
print("\n****ERROR: Pip is not installed on this system. Please update your python install and / or install Pip, then retry***");
sys.exit();
return;
#install wget if it doesnt already exist
try:
import wget
except ImportError:
print("\nWget package missing, installing now...");
x = subprocess.call(['pip', 'install', '-q','wget']);
if x!= 0:
print("\t**ERROR** wget did not install correctly!");
sys.exit();
else:
print("[Installed]");
#install shutil.which if it doesnt already exist.
#Python 3 has this already, python 2.7 does not so we need to install it.
try:
import shutilwhich
except ImportError:
print("\nshutilwhich package missing, installing now...");
x = subprocess.call(['pip', 'install', '-q','shutilwhich']);
if x!= 0:
print("\t**ERROR** shutilwhich did not install correctly!");
sys.exit();
else:
print("[Installed]");
return;
#
# The main function figures out what OS is running and calls appropriate handler
#
def main():
chooseOS = {
"win32" : windows, # Windows32 and 64bit
"cygwin": cygwin, # cygwin on windows
"darwin": osx, # Mac OSX
"linux" : linux # Linux
}
if sys.platform in chooseOS:
bootstrap();
chooseOS[sys.platform]();
else:
print("Your OS is not supported!");
return;
if __name__ == "__main__":
main()