Skip to content

Commit

Permalink
Merge pull request #14 from zfi/master
Browse files Browse the repository at this point in the history
Version 1.0.0
  • Loading branch information
zfi authored Jun 24, 2017
2 parents 525d5cb + a8d1448 commit 535a430
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,6 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg
/CloudCompiler-Pkg.tar.gz
/build
/deploy-test
39 changes: 36 additions & 3 deletions cloudcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

from SpinCompiler import SpinCompiler
from PropCCompiler import PropCCompiler
import base64

__author__ = 'Michel'

version = "1.0.0"
app = Flask(__name__)


Expand Down Expand Up @@ -110,10 +112,10 @@ def multiple_c(action):


def handle_c(action, source_files, app_filename):
# format data
# format to upper case to make string compares easier
action = action.upper()

# check data
# Verify that we have received a valid action (COMPILE, BIN, EEPROM)
if action not in actions:
failure_data = {
"success": False,
Expand All @@ -129,6 +131,8 @@ def handle_c(action, source_files, app_filename):
"message": "missing-main-filename"
}
return Response(json.dumps(failure_data), 200, mimetype="application/json")

# Is the application file name is in the list of files
if app_filename not in source_files:
failure_data = {
"success": False,
Expand All @@ -137,6 +141,24 @@ def handle_c(action, source_files, app_filename):
}
return Response(json.dumps(failure_data), 400, mimetype="application/json")

# --------------------------------------------------------------
# Custom hook to trap the S3 Scribbler demo/initialization block
# Look for a specific string in the source file (single.c)
# --------------------------------------------------------------
if '#pragma load_default_scribbler_binary' in source_files['single.c']:
out = "Loading S3 Demo App..."
data = {
"success": True,
"compiler-output": out,
"compiler-error": ''
}

if action != "COMPILE":
data['binary'] = s3_load_init_binary()
data['extension'] = 'elf'

return Response(json.dumps(data), 200, mimetype="application/json")

# call compiler and prepare return data
(success, base64binary, extension, out, err) = compilers["PROP-C"].compile(action, source_files, app_filename)

Expand All @@ -148,12 +170,22 @@ def handle_c(action, source_files, app_filename):
"compiler-output": out,
"compiler-error": err
}

if action != "COMPILE" and success:
data['binary'] = base64binary
data['extension'] = extension

return Response(json.dumps(data), 200, mimetype="application/json")


def s3_load_init_binary():
with open('scribbler_default.binary', 'rb') as f:
encoded = base64.b64encode(f.read())

f.close()
return encoded


# --------------------------------------- Defaults and compiler initialization --------------------------------
defaults = {
'c-compiler': '/opt/parallax/bin/propeller-elf-gcc',
Expand All @@ -163,6 +195,7 @@ def handle_c(action, source_files, app_filename):
}

configfile = expanduser("~/cloudcompiler.properties")

if isfile(configfile):
configs = ConfigParser(defaults)
configs.readfp(FakeSecHead(open(configfile)))
Expand Down Expand Up @@ -196,7 +229,7 @@ def handle_c(action, source_files, app_filename):

# ----------------------------------------------- Development server -------------------------------------------
if __name__ == '__main__':
app.debug = True
app.debug = False
app.run(host='0.0.0.0')


Binary file added scribbler_default.binary
Binary file not shown.

0 comments on commit 535a430

Please sign in to comment.