6
6
7
7
from SpinCompiler import SpinCompiler
8
8
from PropCCompiler import PropCCompiler
9
+ import base64
9
10
10
11
__author__ = 'Michel'
11
12
13
+ version = "1.0.0"
12
14
app = Flask (__name__ )
13
15
14
16
@@ -110,10 +112,10 @@ def multiple_c(action):
110
112
111
113
112
114
def handle_c (action , source_files , app_filename ):
113
- # format data
115
+ # format to upper case to make string compares easier
114
116
action = action .upper ()
115
117
116
- # check data
118
+ # Verify that we have received a valid action (COMPILE, BIN, EEPROM)
117
119
if action not in actions :
118
120
failure_data = {
119
121
"success" : False ,
@@ -129,6 +131,8 @@ def handle_c(action, source_files, app_filename):
129
131
"message" : "missing-main-filename"
130
132
}
131
133
return Response (json .dumps (failure_data ), 200 , mimetype = "application/json" )
134
+
135
+ # Is the application file name is in the list of files
132
136
if app_filename not in source_files :
133
137
failure_data = {
134
138
"success" : False ,
@@ -137,6 +141,24 @@ def handle_c(action, source_files, app_filename):
137
141
}
138
142
return Response (json .dumps (failure_data ), 400 , mimetype = "application/json" )
139
143
144
+ # --------------------------------------------------------------
145
+ # Custom hook to trap the S3 Scribbler demo/initialization block
146
+ # Look for a specific string in the source file (single.c)
147
+ # --------------------------------------------------------------
148
+ if '#pragma load_default_scribbler_binary' in source_files ['single.c' ]:
149
+ out = "Loading S3 Demo App..."
150
+ data = {
151
+ "success" : True ,
152
+ "compiler-output" : out ,
153
+ "compiler-error" : ''
154
+ }
155
+
156
+ if action != "COMPILE" :
157
+ data ['binary' ] = s3_load_init_binary ()
158
+ data ['extension' ] = 'elf'
159
+
160
+ return Response (json .dumps (data ), 200 , mimetype = "application/json" )
161
+
140
162
# call compiler and prepare return data
141
163
(success , base64binary , extension , out , err ) = compilers ["PROP-C" ].compile (action , source_files , app_filename )
142
164
@@ -148,12 +170,22 @@ def handle_c(action, source_files, app_filename):
148
170
"compiler-output" : out ,
149
171
"compiler-error" : err
150
172
}
173
+
151
174
if action != "COMPILE" and success :
152
175
data ['binary' ] = base64binary
153
176
data ['extension' ] = extension
177
+
154
178
return Response (json .dumps (data ), 200 , mimetype = "application/json" )
155
179
156
180
181
+ def s3_load_init_binary ():
182
+ with open ('scribbler_default.binary' , 'rb' ) as f :
183
+ encoded = base64 .b64encode (f .read ())
184
+
185
+ f .close ()
186
+ return encoded
187
+
188
+
157
189
# --------------------------------------- Defaults and compiler initialization --------------------------------
158
190
defaults = {
159
191
'c-compiler' : '/opt/parallax/bin/propeller-elf-gcc' ,
@@ -163,6 +195,7 @@ def handle_c(action, source_files, app_filename):
163
195
}
164
196
165
197
configfile = expanduser ("~/cloudcompiler.properties" )
198
+
166
199
if isfile (configfile ):
167
200
configs = ConfigParser (defaults )
168
201
configs .readfp (FakeSecHead (open (configfile )))
@@ -196,7 +229,7 @@ def handle_c(action, source_files, app_filename):
196
229
197
230
# ----------------------------------------------- Development server -------------------------------------------
198
231
if __name__ == '__main__' :
199
- app .debug = True
232
+ app .debug = False
200
233
app .run (host = '0.0.0.0' )
201
234
202
235
0 commit comments