From b972f97d01d7072aae53ac458a2642990ff90e83 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Thu, 16 Jun 2022 22:44:56 +0530 Subject: [PATCH 01/22] FRI added --- fri/example.py | 1 + fri/friApi.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ fri/test.py | 15 +++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 fri/example.py create mode 100644 fri/friApi.py create mode 100644 fri/test.py diff --git a/fri/example.py b/fri/example.py new file mode 100644 index 0000000..05e2ce0 --- /dev/null +++ b/fri/example.py @@ -0,0 +1 @@ +print('concore') \ No newline at end of file diff --git a/fri/friApi.py b/fri/friApi.py new file mode 100644 index 0000000..8f9a891 --- /dev/null +++ b/fri/friApi.py @@ -0,0 +1,48 @@ +from flask import Flask, request, jsonify +from werkzeug.utils import secure_filename +import os + +# location of folder to store received file +UPLOAD_FOLDER = "./received_files" + +if not os.path.exists(UPLOAD_FOLDER): + os.makedirs(UPLOAD_FOLDER) + +app = Flask(__name__) +app.secret_key = "secret key" +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +@app.route('/upload_files', methods=['POST']) +def upload_file(): + if 'files[]' not in request.files: + resp = jsonify({'message' : 'No file in the request'}) + resp.status_code = 400 + return resp + + files = request.files.getlist('files[]') + + errors = {} + success = False + + for file in files: + if file: + filename = secure_filename(file.filename) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + success = True + + if success and errors: + errors['message'] = 'File(s) successfully uploaded' + resp = jsonify(errors) + resp.status_code = 500 + return resp + if success: + resp = jsonify({'message' : 'Files successfully uploaded'}) + resp.status_code = 201 + return resp + else: + resp = jsonify(errors) + resp.status_code = 500 + return resp + +if __name__ == "__main__": + app.run(debug=True) diff --git a/fri/test.py b/fri/test.py new file mode 100644 index 0000000..af648f5 --- /dev/null +++ b/fri/test.py @@ -0,0 +1,15 @@ +#This file is just to check if friApi.py works perfectly. +import requests + +url = "http://127.0.0.1:5000/upload_files" + +payload={} +# replace as example.py with target file name and it must already exist in given Dir. +files=[ + ('files[]',('example.py',open('/Users/ASUS/concore/fri/example.py','rb'),'application/octet-stream')), + ] +headers = {} + +response = requests.request("POST", url, headers=headers, data=payload, files=files) + +print(response.text) From dd48dbce2fb3615e5d2102890b6eedca38f1efdf Mon Sep 17 00:00:00 2001 From: Amit Kumar <76881647+amit-62@users.noreply.github.com> Date: Thu, 16 Jun 2022 22:58:49 +0530 Subject: [PATCH 02/22] Delete fri directory --- fri/example.py | 1 - fri/friApi.py | 48 ------------------------------------------------ fri/test.py | 15 --------------- 3 files changed, 64 deletions(-) delete mode 100644 fri/example.py delete mode 100644 fri/friApi.py delete mode 100644 fri/test.py diff --git a/fri/example.py b/fri/example.py deleted file mode 100644 index 05e2ce0..0000000 --- a/fri/example.py +++ /dev/null @@ -1 +0,0 @@ -print('concore') \ No newline at end of file diff --git a/fri/friApi.py b/fri/friApi.py deleted file mode 100644 index 8f9a891..0000000 --- a/fri/friApi.py +++ /dev/null @@ -1,48 +0,0 @@ -from flask import Flask, request, jsonify -from werkzeug.utils import secure_filename -import os - -# location of folder to store received file -UPLOAD_FOLDER = "./received_files" - -if not os.path.exists(UPLOAD_FOLDER): - os.makedirs(UPLOAD_FOLDER) - -app = Flask(__name__) -app.secret_key = "secret key" -app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER - -@app.route('/upload_files', methods=['POST']) -def upload_file(): - if 'files[]' not in request.files: - resp = jsonify({'message' : 'No file in the request'}) - resp.status_code = 400 - return resp - - files = request.files.getlist('files[]') - - errors = {} - success = False - - for file in files: - if file: - filename = secure_filename(file.filename) - file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) - success = True - - if success and errors: - errors['message'] = 'File(s) successfully uploaded' - resp = jsonify(errors) - resp.status_code = 500 - return resp - if success: - resp = jsonify({'message' : 'Files successfully uploaded'}) - resp.status_code = 201 - return resp - else: - resp = jsonify(errors) - resp.status_code = 500 - return resp - -if __name__ == "__main__": - app.run(debug=True) diff --git a/fri/test.py b/fri/test.py deleted file mode 100644 index af648f5..0000000 --- a/fri/test.py +++ /dev/null @@ -1,15 +0,0 @@ -#This file is just to check if friApi.py works perfectly. -import requests - -url = "http://127.0.0.1:5000/upload_files" - -payload={} -# replace as example.py with target file name and it must already exist in given Dir. -files=[ - ('files[]',('example.py',open('/Users/ASUS/concore/fri/example.py','rb'),'application/octet-stream')), - ] -headers = {} - -response = requests.request("POST", url, headers=headers, data=payload, files=files) - -print(response.text) From cbe24cc64742b7eab1a0acef0d8228de38eeac1a Mon Sep 17 00:00:00 2001 From: amit-62 Date: Thu, 16 Jun 2022 23:17:46 +0530 Subject: [PATCH 03/22] FRI added --- fri/example.py | 1 + fri/friApi.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ fri/test.py | 15 +++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 fri/example.py create mode 100644 fri/friApi.py create mode 100644 fri/test.py diff --git a/fri/example.py b/fri/example.py new file mode 100644 index 0000000..05e2ce0 --- /dev/null +++ b/fri/example.py @@ -0,0 +1 @@ +print('concore') \ No newline at end of file diff --git a/fri/friApi.py b/fri/friApi.py new file mode 100644 index 0000000..8f9a891 --- /dev/null +++ b/fri/friApi.py @@ -0,0 +1,48 @@ +from flask import Flask, request, jsonify +from werkzeug.utils import secure_filename +import os + +# location of folder to store received file +UPLOAD_FOLDER = "./received_files" + +if not os.path.exists(UPLOAD_FOLDER): + os.makedirs(UPLOAD_FOLDER) + +app = Flask(__name__) +app.secret_key = "secret key" +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +@app.route('/upload_files', methods=['POST']) +def upload_file(): + if 'files[]' not in request.files: + resp = jsonify({'message' : 'No file in the request'}) + resp.status_code = 400 + return resp + + files = request.files.getlist('files[]') + + errors = {} + success = False + + for file in files: + if file: + filename = secure_filename(file.filename) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + success = True + + if success and errors: + errors['message'] = 'File(s) successfully uploaded' + resp = jsonify(errors) + resp.status_code = 500 + return resp + if success: + resp = jsonify({'message' : 'Files successfully uploaded'}) + resp.status_code = 201 + return resp + else: + resp = jsonify(errors) + resp.status_code = 500 + return resp + +if __name__ == "__main__": + app.run(debug=True) diff --git a/fri/test.py b/fri/test.py new file mode 100644 index 0000000..af648f5 --- /dev/null +++ b/fri/test.py @@ -0,0 +1,15 @@ +#This file is just to check if friApi.py works perfectly. +import requests + +url = "http://127.0.0.1:5000/upload_files" + +payload={} +# replace as example.py with target file name and it must already exist in given Dir. +files=[ + ('files[]',('example.py',open('/Users/ASUS/concore/fri/example.py','rb'),'application/octet-stream')), + ] +headers = {} + +response = requests.request("POST", url, headers=headers, data=payload, files=files) + +print(response.text) From 1bdb673fd3308896ac8731f961f34fb63e09e869 Mon Sep 17 00:00:00 2001 From: Amit Kumar <76881647+amit-62@users.noreply.github.com> Date: Wed, 22 Jun 2022 01:23:07 +0530 Subject: [PATCH 04/22] Delete fri directory --- fri/example.py | 1 - fri/friApi.py | 48 ------------------------------------------------ fri/test.py | 15 --------------- 3 files changed, 64 deletions(-) delete mode 100644 fri/example.py delete mode 100644 fri/friApi.py delete mode 100644 fri/test.py diff --git a/fri/example.py b/fri/example.py deleted file mode 100644 index 05e2ce0..0000000 --- a/fri/example.py +++ /dev/null @@ -1 +0,0 @@ -print('concore') \ No newline at end of file diff --git a/fri/friApi.py b/fri/friApi.py deleted file mode 100644 index 8f9a891..0000000 --- a/fri/friApi.py +++ /dev/null @@ -1,48 +0,0 @@ -from flask import Flask, request, jsonify -from werkzeug.utils import secure_filename -import os - -# location of folder to store received file -UPLOAD_FOLDER = "./received_files" - -if not os.path.exists(UPLOAD_FOLDER): - os.makedirs(UPLOAD_FOLDER) - -app = Flask(__name__) -app.secret_key = "secret key" -app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER - -@app.route('/upload_files', methods=['POST']) -def upload_file(): - if 'files[]' not in request.files: - resp = jsonify({'message' : 'No file in the request'}) - resp.status_code = 400 - return resp - - files = request.files.getlist('files[]') - - errors = {} - success = False - - for file in files: - if file: - filename = secure_filename(file.filename) - file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) - success = True - - if success and errors: - errors['message'] = 'File(s) successfully uploaded' - resp = jsonify(errors) - resp.status_code = 500 - return resp - if success: - resp = jsonify({'message' : 'Files successfully uploaded'}) - resp.status_code = 201 - return resp - else: - resp = jsonify(errors) - resp.status_code = 500 - return resp - -if __name__ == "__main__": - app.run(debug=True) diff --git a/fri/test.py b/fri/test.py deleted file mode 100644 index af648f5..0000000 --- a/fri/test.py +++ /dev/null @@ -1,15 +0,0 @@ -#This file is just to check if friApi.py works perfectly. -import requests - -url = "http://127.0.0.1:5000/upload_files" - -payload={} -# replace as example.py with target file name and it must already exist in given Dir. -files=[ - ('files[]',('example.py',open('/Users/ASUS/concore/fri/example.py','rb'),'application/octet-stream')), - ] -headers = {} - -response = requests.request("POST", url, headers=headers, data=payload, files=files) - -print(response.text) From a0b4ba83b8a8225bc1e4a219eee8e8f01d6a9138 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Wed, 22 Jun 2022 01:31:51 +0530 Subject: [PATCH 05/22] fri added --- fri/Dockerfile | 10 ++++++++ fri/example.py | 1 + fri/main.py | 52 +++++++++++++++++++++++++++++++++++++++++ fri/requirements.txt | 2 ++ fri/templates/home.html | 12 ++++++++++ fri/test.py | 13 +++++++++++ 6 files changed, 90 insertions(+) create mode 100644 fri/Dockerfile create mode 100644 fri/example.py create mode 100644 fri/main.py create mode 100644 fri/requirements.txt create mode 100644 fri/templates/home.html create mode 100644 fri/test.py diff --git a/fri/Dockerfile b/fri/Dockerfile new file mode 100644 index 0000000..02eedf7 --- /dev/null +++ b/fri/Dockerfile @@ -0,0 +1,10 @@ +FROM centos/python-36-centos7 + +WORKDIR /fri +COPY . /fri + +COPY requirements.txt /fri/requirements.txt +RUN pip install -r /fri/requirements.txt + + +CMD ["gunicorn", "-w", "4", "--bind", "0.0.0.0:8080", "main:app"] diff --git a/fri/example.py b/fri/example.py new file mode 100644 index 0000000..bff2a13 --- /dev/null +++ b/fri/example.py @@ -0,0 +1 @@ +print("amit") \ No newline at end of file diff --git a/fri/main.py b/fri/main.py new file mode 100644 index 0000000..0ac2108 --- /dev/null +++ b/fri/main.py @@ -0,0 +1,52 @@ +from flask import Flask, request, jsonify, render_template +from werkzeug.utils import secure_filename +import os + + +UPLOAD_FOLDER = "./uploaded_files" + +if not os.path.exists(UPLOAD_FOLDER): + os.makedirs(UPLOAD_FOLDER) + +app = Flask(__name__) +app.secret_key = "secret key" +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +@app.route('/') +def hello_world(): + return render_template('home.html') + +@app.route('/multiple-files-upload', methods=['POST']) +def upload_file(): + if 'files[]' not in request.files: + resp = jsonify({'message' : 'No file in the request'}) + resp.status_code = 400 + return resp + + files = request.files.getlist('files[]') + + errors = {} + success = False + + for file in files: + if file: + filename = secure_filename(file.filename) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + success = True + + if success and errors: + errors['message'] = 'File(s) successfully uploaded' + resp = jsonify(errors) + resp.status_code = 500 + return resp + if success: + resp = jsonify({'message' : 'Files successfully uploaded'}) + resp.status_code = 201 + return resp + else: + resp = jsonify(errors) + resp.status_code = 500 + return resp + +if __name__ == "__main__": + app.run(host="0.0.0.0") diff --git a/fri/requirements.txt b/fri/requirements.txt new file mode 100644 index 0000000..82d3ede --- /dev/null +++ b/fri/requirements.txt @@ -0,0 +1,2 @@ +Flask +gunicorn==20.1.0 \ No newline at end of file diff --git a/fri/templates/home.html b/fri/templates/home.html new file mode 100644 index 0000000..6b87469 --- /dev/null +++ b/fri/templates/home.html @@ -0,0 +1,12 @@ + + + + + + + Document + + +

Home page

+ + \ No newline at end of file diff --git a/fri/test.py b/fri/test.py new file mode 100644 index 0000000..6852bc1 --- /dev/null +++ b/fri/test.py @@ -0,0 +1,13 @@ +import requests + +url = "http://127.0.0.1:5000/multiple-files-upload" + +payload={} +files=[ + ('files[]',('example.py',open('/home/amit/Desktop/concore/flaskApi/example.py','rb'),'application/octet-stream')) +] +headers = {} + +response = requests.request("POST", url, headers=headers, data=payload, files=files) + +print(response.text) From 54d73c7fbb69beb676adc1f5b63873a1c2a844a0 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Thu, 23 Jun 2022 01:27:58 +0530 Subject: [PATCH 06/22] Dockerfile changed --- fri/Dockerfile | 17 ++++++++--------- fri/{ => server}/main.py | 3 --- fri/templates/home.html | 12 ------------ 3 files changed, 8 insertions(+), 24 deletions(-) rename fri/{ => server}/main.py (90%) delete mode 100644 fri/templates/home.html diff --git a/fri/Dockerfile b/fri/Dockerfile index 02eedf7..ad37113 100644 --- a/fri/Dockerfile +++ b/fri/Dockerfile @@ -1,10 +1,9 @@ FROM centos/python-36-centos7 - -WORKDIR /fri -COPY . /fri - -COPY requirements.txt /fri/requirements.txt -RUN pip install -r /fri/requirements.txt - - -CMD ["gunicorn", "-w", "4", "--bind", "0.0.0.0:8080", "main:app"] +COPY requirements.txt /tmp/requirements.txt +RUN pip install -r /tmp/requirements.txt +WORKDIR /fri +COPY server /fri +USER root +RUN useradd fri && chown -R fri /fri +USER fri +CMD ["gunicorn", "--timeout=180", "--workers=4", "--bind=0.0.0.0:8080", "--access-logfile=-", "main:app"] \ No newline at end of file diff --git a/fri/main.py b/fri/server/main.py similarity index 90% rename from fri/main.py rename to fri/server/main.py index 0ac2108..57e179d 100644 --- a/fri/main.py +++ b/fri/server/main.py @@ -12,9 +12,6 @@ app.secret_key = "secret key" app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER -@app.route('/') -def hello_world(): - return render_template('home.html') @app.route('/multiple-files-upload', methods=['POST']) def upload_file(): diff --git a/fri/templates/home.html b/fri/templates/home.html deleted file mode 100644 index 6b87469..0000000 --- a/fri/templates/home.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Document - - -

Home page

- - \ No newline at end of file From 55e97c7a1dcc2eca0df2514bf3c2562bcff56b3f Mon Sep 17 00:00:00 2001 From: amit-62 Date: Thu, 23 Jun 2022 23:38:28 +0530 Subject: [PATCH 07/22] FRI Updated --- fri/README.md | 133 ++++++++++++++++++++++++++++++++++++++++++ fri/service_config.sh | 22 +++++++ 2 files changed, 155 insertions(+) create mode 100644 fri/README.md create mode 100644 fri/service_config.sh diff --git a/fri/README.md b/fri/README.md new file mode 100644 index 0000000..e0bae61 --- /dev/null +++ b/fri/README.md @@ -0,0 +1,133 @@ +# The Control-Core FRI for Closed-Loop Neuromodulation Control Systems + +The Control-Core File Receiving Interface (FRI) is built with is Python-3.10. It is the core component that makes the distributed executions a reality in the Control-Core framework. + + +# Building FRI Container + +Connect to the Server VM, assuming x.x.x.x to be the IP address of your server. +```` +$ ssh -i "controlcore.pem" ubuntu@x.x.x.x +```` +Perform Git clone if this is the first time you are configuring the Server +```` +$ git clone git@github.com/ControlCore-Project/concore.git +```` + +First build the Docker Container of the FRI. +```` +$ git pull + +$ sudo docker build -t fri . +```` + +# Running Control-Core FRI with Kong as containers + +If you are already running FRI, make sure to stop and clear existing FRI container as it is likely conflict with the port. If there is Kong gateway running in default ports, stop and clear it too. +```` +$ docker stop fri +$ docker rm fri +$ docker stop kong +$ docker rm kong +```` + +Start and configure Cassandra container for Kong API. +```` +$ docker run -d --name kong-database \ + -p 9042:9042 \ + cassandra:3 + + +$ docker run --rm \ + --link kong-database:kong-database \ + -e "KONG_DATABASE=cassandra" \ + -e "KONG_PG_HOST=kong-database" \ + -e "KONG_PG_USER=kong" \ + -e "KONG_PG_PASSWORD=kong" \ + -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \ + kong kong migrations bootstrap +```` + +Start Kong +```` +$ docker run -d --name kong \ + --link kong-database:kong-database \ + -e "KONG_DATABASE=cassandra" \ + -e "KONG_PG_HOST=kong-database" \ + -e "KONG_PG_PASSWORD=kong" \ + -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \ + -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \ + -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \ + -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \ + -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \ + -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \ + -p 80:8000 \ + -p 8443:8443 \ + -p 8001:8001 \ + -p 8444:8444 \ + kong +```` + +Start FRI container +```` +$ nohup sudo docker run --name fri -p 8090:8081 fri > controlcore.out & +```` + +Delete if there is a previously configured Kong service. If not, skip this step. First you need to find the ID-VALUE for the route with a GET command before deleting the route and service. +```` +$ curl -X GET "http://localhost:8001/services/fri/routes" +```` +Use the ID output from above to issue the delete command as below (issue this only if you have a previous conflicting service definiton in kong. Otherwise, skip this step): +```` +$ curl -X DELETE "http://localhost:8001/services/fri/routes/ID-VALUE" + +$ curl -X DELETE "http://localhost:8001/services/fri/" +```` + +Define Kong Service and Route. + +First Configure a Kong service, replacing the variable "private-ip" with the private IP address of your server below. +```` +$ curl -i -X POST --url http://localhost:8001/services/ --data 'name=fri' --data 'url=http://private-ip:8090' +```` +Then configure route to the service +```` +$ curl -i -X POST --url http://localhost:8001/services/fri/routes --data 'paths=/' +```` + +Now, controlcore.org is routed through the Kong APIs. + + +# Troubleshooting the FRI + +Connect to the Server VM +```` +$ ssh -i "controlcore.pem" ubuntu@x.x.x.x +```` +Check the Server logs. +```` +$ tail -f controlcore.out +```` +or +```` +$ sudo docker logs fri -f +```` +Find the FRI docker container +```` +$ sudo docker ps +```` +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +dfdd3b3d3308 fri "python main.py" 38 minutes ago Up 38 minutes 0.0.0.0:80->80/tcp fri + +Access the container +```` +$ sudo docker exec -it dfdd /bin/bash +```` + + + +# Citing the CONTROL-CORE FRI + +If you use the CONTROL-CORE FRI in your research, please cite the below paper: + +* Kathiravelu, P., Arnold, M., Fleischer, J., Yao, Y., Awasthi, S., Goel, A. K., Branen, A., Sarikhani, P., Kumar, G., Kothare, M. V., and Mahmoudi, B. **CONTROL-CORE: A Framework for Simulation and Design of Closed-Loop Peripheral Neuromodulation Control Systems**. In IEEE Access. March 2022. https://doi.org/10.1109/ACCESS.2022.3161471 diff --git a/fri/service_config.sh b/fri/service_config.sh new file mode 100644 index 0000000..7301bd5 --- /dev/null +++ b/fri/service_config.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +SERVICES=('init' 'ctl' 'pm' 'cleanup') +for service in "${SERVICES[@]}" +do + name="name="$service + path="paths=/"$service + service_path="url=http://private-ip:8090/"$service + route_path="http://localhost:8001/services/"$service"/routes" + plugin_path="http://localhost:8001/services/"$service"/plugins" + echo "Name is, $name" + echo "Path is, $path" + echo "Service path is, $service_path" + echo "Route path is, $route_path" + echo "Plugin path is, $plugin_path" + echo "Creating Service, $service..." + curl -i -X POST --url http://localhost:8001/services/ --data $name --data $service_path + echo "Creating route for $service..." + curl -i -X POST --url $route_path --data $path + echo "Creating apikey-based authentication for $service..." + curl -X POST $plugin_path --data "name=key-auth" --data "config.key_names=apikey" +done \ No newline at end of file From 9c8e23a680dca8f8bc2393d88ad7f337c6e17a33 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Fri, 24 Jun 2022 00:20:08 +0530 Subject: [PATCH 08/22] FRI updated --- fri/service_config.sh | 2 +- fri/test.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fri/service_config.sh b/fri/service_config.sh index 7301bd5..c41f37e 100644 --- a/fri/service_config.sh +++ b/fri/service_config.sh @@ -1,6 +1,6 @@ #!/bin/bash -SERVICES=('init' 'ctl' 'pm' 'cleanup') +SERVICES=('upload_file' 'execute') for service in "${SERVICES[@]}" do name="name="$service diff --git a/fri/test.py b/fri/test.py index 6852bc1..aabc5ac 100644 --- a/fri/test.py +++ b/fri/test.py @@ -1,10 +1,13 @@ import requests +import os url = "http://127.0.0.1:5000/multiple-files-upload" +path = os.path.abspath("example.py") + payload={} files=[ - ('files[]',('example.py',open('/home/amit/Desktop/concore/flaskApi/example.py','rb'),'application/octet-stream')) + ('files[]',('example.py',open( path,'rb'),'application/octet-stream')) ] headers = {} From 737514cb7c629e8428c43f868f91140c7931e1ea Mon Sep 17 00:00:00 2001 From: amit-62 Date: Fri, 24 Jun 2022 22:38:13 +0530 Subject: [PATCH 09/22] fri udated --- fri/example.py | 2 +- fri/server/main.py | 4 ++-- fri/service_config.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fri/example.py b/fri/example.py index bff2a13..e78d17c 100644 --- a/fri/example.py +++ b/fri/example.py @@ -1 +1 @@ -print("amit") \ No newline at end of file +print("Concore/fri") \ No newline at end of file diff --git a/fri/server/main.py b/fri/server/main.py index 57e179d..6ee4624 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -13,8 +13,8 @@ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER -@app.route('/multiple-files-upload', methods=['POST']) -def upload_file(): +@app.route('/upload', methods=['POST']) +def upload(): if 'files[]' not in request.files: resp = jsonify({'message' : 'No file in the request'}) resp.status_code = 400 diff --git a/fri/service_config.sh b/fri/service_config.sh index c41f37e..c6530e3 100644 --- a/fri/service_config.sh +++ b/fri/service_config.sh @@ -1,6 +1,6 @@ #!/bin/bash -SERVICES=('upload_file' 'execute') +SERVICES=('upload' 'execute') for service in "${SERVICES[@]}" do name="name="$service From 5ef179b84a01eeef484aabf3b4e7589e47bbd5a2 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Thu, 30 Jun 2022 21:31:06 +0530 Subject: [PATCH 10/22] added execute and download method --- fri/server/main.py | 57 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/fri/server/main.py b/fri/server/main.py index 6ee4624..56355f2 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -1,8 +1,11 @@ -from flask import Flask, request, jsonify, render_template +from flask import Flask, request, jsonify, send_from_directory from werkzeug.utils import secure_filename import os +from subprocess import call +from pathlib import Path - +EXECUTABLE_FOLDER = "./executable_files" +DOWNLOAD_FOLDER = "./download_files" UPLOAD_FOLDER = "./uploaded_files" if not os.path.exists(UPLOAD_FOLDER): @@ -11,6 +14,8 @@ app = Flask(__name__) app.secret_key = "secret key" app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER +app.config['EXECUTABLE_FOLDER'] = EXECUTABLE_FOLDER +app.config['DOWNLOAD_FOLDER'] = DOWNLOAD_FOLDER @app.route('/upload', methods=['POST']) @@ -45,5 +50,53 @@ def upload(): resp.status_code = 500 return resp + +@app.route('/execute', methods=['POST']) +def execute(): + if 'file' not in request.files: + resp = jsonify({'message' : 'No file in the request'}) + resp.status_code = 400 + return resp + + + file = request.files['file'] + if file.filename == '': + resp = jsonify({'message' : 'No file selected for Executing'}) + resp.status_code = 400 + return resp + + errors = {} + success = False + + + if file: + filename = secure_filename(file.filename) + file.save(os.path.join(app.config['EXECUTABLE_FOLDER'], filename)) + output_file = filename + ".out" + path = app.config['EXECUTABLE_FOLDER']+"/"+filename + call(["python3", path, ">", output_file, "&"]) + success = True + + if success: + resp = jsonify({'message' : 'Files successfully executed'}) + resp.status_code = 201 + return resp + else: + resp = jsonify(errors) + resp.status_code = 500 + return resp + + + +@app.route('/download/', methods=['POST','GET']) +def download(file_name): + try: + return send_from_directory(app.config["DOWNLOAD_FOLDER"], file_name, as_attachment=True) + except: + resp = jsonify({'message' : 'file not found'}) + resp.status_code = 400 + return resp + + if __name__ == "__main__": app.run(host="0.0.0.0") From 47b631f5199d7c1cc3bfb6fb619492160396e691 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Mon, 4 Jul 2022 01:28:47 +0530 Subject: [PATCH 11/22] updated FRI --- fri/server/main.py | 194 ++++++++++++++++++++++-------------------- fri/service_config.sh | 2 +- 2 files changed, 105 insertions(+), 91 deletions(-) diff --git a/fri/server/main.py b/fri/server/main.py index 56355f2..348f57a 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -1,101 +1,115 @@ -from flask import Flask, request, jsonify, send_from_directory +from flask import Flask, request, jsonify, send_file, send_from_directory from werkzeug.utils import secure_filename import os from subprocess import call from pathlib import Path -EXECUTABLE_FOLDER = "./executable_files" -DOWNLOAD_FOLDER = "./download_files" -UPLOAD_FOLDER = "./uploaded_files" - -if not os.path.exists(UPLOAD_FOLDER): - os.makedirs(UPLOAD_FOLDER) app = Flask(__name__) app.secret_key = "secret key" -app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER -app.config['EXECUTABLE_FOLDER'] = EXECUTABLE_FOLDER -app.config['DOWNLOAD_FOLDER'] = DOWNLOAD_FOLDER - - -@app.route('/upload', methods=['POST']) -def upload(): - if 'files[]' not in request.files: - resp = jsonify({'message' : 'No file in the request'}) - resp.status_code = 400 - return resp - - files = request.files.getlist('files[]') - - errors = {} - success = False - - for file in files: - if file: - filename = secure_filename(file.filename) - file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) - success = True - - if success and errors: - errors['message'] = 'File(s) successfully uploaded' - resp = jsonify(errors) - resp.status_code = 500 - return resp - if success: - resp = jsonify({'message' : 'Files successfully uploaded'}) - resp.status_code = 201 - return resp - else: - resp = jsonify(errors) - resp.status_code = 500 - return resp - - -@app.route('/execute', methods=['POST']) -def execute(): - if 'file' not in request.files: - resp = jsonify({'message' : 'No file in the request'}) - resp.status_code = 400 - return resp - - - file = request.files['file'] - if file.filename == '': - resp = jsonify({'message' : 'No file selected for Executing'}) - resp.status_code = 400 - return resp - - errors = {} - success = False - - - if file: - filename = secure_filename(file.filename) - file.save(os.path.join(app.config['EXECUTABLE_FOLDER'], filename)) - output_file = filename + ".out" - path = app.config['EXECUTABLE_FOLDER']+"/"+filename - call(["python3", path, ">", output_file, "&"]) - success = True - - if success: - resp = jsonify({'message' : 'Files successfully executed'}) - resp.status_code = 201 - return resp - else: - resp = jsonify(errors) - resp.status_code = 500 - return resp - - - -@app.route('/download/', methods=['POST','GET']) -def download(file_name): - try: - return send_from_directory(app.config["DOWNLOAD_FOLDER"], file_name, as_attachment=True) - except: - resp = jsonify({'message' : 'file not found'}) - resp.status_code = 400 - return resp + +# To upload multiple file. For example, /upload/test?apikey=xyz +@app.route('/upload/', methods=['POST']) +def upload(dir): + apikey = request.args.get('apikey') + dirname = dir + "_" + apikey + + if 'files[]' not in request.files: + resp = jsonify({'message': 'No file in the request'}) + resp.status_code = 400 + return resp + + files = request.files.getlist('files[]') + + errors = {} + success = False + + if not os.path.exists(secure_filename(dirname)): + os.makedirs(secure_filename(dirname)) + + for file in files: + if file: + filename = secure_filename(file.filename) + file.save(secure_filename(dirname)+"/"+filename) + success = True + + if success and errors: + errors['message'] = 'File(s) successfully uploaded' + resp = jsonify(errors) + resp.status_code = 500 + return resp + if success: + resp = jsonify({'message': 'Files successfully uploaded'}) + resp.status_code = 201 + return resp + else: + resp = jsonify(errors) + resp.status_code = 500 + return resp + +# To execute any python file. For example, /execute/test?apikey=xyz +@app.route('/execute/', methods=['POST']) +def execute(dir): + apikey = request.args.get('apikey') + dirname = dir + "_" + apikey + + if 'file' not in request.files: + resp = jsonify({'message': 'No file in the request'}) + resp.status_code = 400 + return resp + + file = request.files['file'] + + if file.filename == '': + resp = jsonify({'message': 'No file selected for Executing'}) + resp.status_code = 400 + return resp + + errors = {} + success = False + + if not os.path.exists(secure_filename(dirname)): + os.makedirs(secure_filename(dirname)) + + if file: + filename = secure_filename(file.filename) + file.save(secure_filename(dirname)+"/"+filename) + output_filename = filename + ".out" + file_path = secure_filename(dirname) + "/"+filename + outputfile_path = secure_filename(dirname)+"/"+output_filename + f = open(outputfile_path, "w") + call(["nohup", "python3", file_path], stdout=f) + success = True + + if success: + resp = jsonify({'message': 'Files successfully executed'}) + resp.status_code = 201 + return resp + else: + resp = jsonify(errors) + resp.status_code = 500 + return resp + + + +# to download /download/?fetch=. For example, /download/test?fetch=example.py.out&apikey=xyz +@app.route('/download/', methods=['POST', 'GET']) +def download(dir): + download_file = request.args.get('fetch') + apikey = request.args.get('apikey') + dirname = dir + "_" + apikey + + if not os.path.exists(secure_filename(dirname)): + resp = jsonify({'message': 'Directory not found'}) + resp.status_code = 400 + return resp + + try: + return send_from_directory(secure_filename(dirname), download_file, as_attachment=True) + except: + resp = jsonify({'message': 'file not found'}) + resp.status_code = 400 + return resp if __name__ == "__main__": diff --git a/fri/service_config.sh b/fri/service_config.sh index c6530e3..7be2144 100644 --- a/fri/service_config.sh +++ b/fri/service_config.sh @@ -1,6 +1,6 @@ #!/bin/bash -SERVICES=('upload' 'execute') +SERVICES=('upload' 'execute' 'download') for service in "${SERVICES[@]}" do name="name="$service From 40e2e404db82fe163c4e6f6e5457fd375cb63b78 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Wed, 6 Jul 2022 22:10:41 +0530 Subject: [PATCH 12/22] updated test methods --- fri/test.py | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/fri/test.py b/fri/test.py index aabc5ac..aba9f95 100644 --- a/fri/test.py +++ b/fri/test.py @@ -1,16 +1,44 @@ import requests import os -url = "http://127.0.0.1:5000/multiple-files-upload" +# function to test upload() method. +def upload(): + url = "http://127.0.0.1:5000/upload/test?apikey=xyz" -path = os.path.abspath("example.py") + path = os.path.abspath("example.py") -payload={} -files=[ - ('files[]',('example.py',open( path,'rb'),'application/octet-stream')) -] -headers = {} + payload={} + files=[ + ('files[]',('example.py',open(path,'rb'),'application/octet-stream')) + ] + headers = {} -response = requests.request("POST", url, headers=headers, data=payload, files=files) + response = requests.request("POST", url, headers=headers, data=payload, files=files) + + return response.text + + +# # ******* + +# function to test execute() method. +def execute(): + url = "http://127.0.0.1:5000/execute/test?apikey=xyz" + + path = os.path.abspath("example.py") + + payload={} + files=[ + ('file',('example.py',open(path,'rb'),'application/octet-stream')) + ] + headers = {} + + response = requests.request("POST", url, headers=headers, data=payload, files=files) + + return response.text + + # ******** + # To Download call the url .../download/test?fetch=&apikey=xyz + +upload() +execute() -print(response.text) From d338de8887f421ff5c48fbd4ead36cfe0b1f98a4 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Wed, 6 Jul 2022 23:14:34 +0530 Subject: [PATCH 13/22] added download method --- fri/test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fri/test.py b/fri/test.py index aba9f95..f27af1a 100644 --- a/fri/test.py +++ b/fri/test.py @@ -1,5 +1,6 @@ import requests import os +import webbrowser # function to test upload() method. def upload(): @@ -36,9 +37,12 @@ def execute(): return response.text - # ******** - # To Download call the url .../download/test?fetch=&apikey=xyz +# or +def download(): + url = "http://127.0.0.1:5000/download/test?fetch=f1.txt&apikey=xyz" + webbrowser.open(url) upload() execute() +download() From 27804bb77065b8b76f9f71e91e9b604c8df555d6 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Thu, 7 Jul 2022 22:09:06 +0530 Subject: [PATCH 14/22] updated download test --- fri/test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fri/test.py b/fri/test.py index f27af1a..2d17159 100644 --- a/fri/test.py +++ b/fri/test.py @@ -1,6 +1,6 @@ import requests import os -import webbrowser +import urllib.request # function to test upload() method. def upload(): @@ -16,7 +16,7 @@ def upload(): response = requests.request("POST", url, headers=headers, data=payload, files=files) - return response.text + print(response.text) # # ******* @@ -35,12 +35,12 @@ def execute(): response = requests.request("POST", url, headers=headers, data=payload, files=files) - return response.text + print(response.text) # or def download(): url = "http://127.0.0.1:5000/download/test?fetch=f1.txt&apikey=xyz" - webbrowser.open(url) + urllib.request.urlretrieve(url, "f1.txt") upload() execute() From 598b23be1591e6064455094f9903f429b2517017 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Thu, 7 Jul 2022 22:14:47 +0530 Subject: [PATCH 15/22] updated download test --- fri/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fri/test.py b/fri/test.py index 2d17159..4717aea 100644 --- a/fri/test.py +++ b/fri/test.py @@ -37,7 +37,7 @@ def execute(): print(response.text) -# or +# function to test download() method. def download(): url = "http://127.0.0.1:5000/download/test?fetch=f1.txt&apikey=xyz" urllib.request.urlretrieve(url, "f1.txt") From c8619b7232acf928f1ca14dbfa0fdb897d50edb6 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Thu, 14 Jul 2022 21:52:56 +0530 Subject: [PATCH 16/22] Added new method --- fri/server/main.py | 56 +++++++++++- mkconcore.py | 222 +++++++++++++++++++++++---------------------- 2 files changed, 170 insertions(+), 108 deletions(-) diff --git a/fri/server/main.py b/fri/server/main.py index 348f57a..ce48e22 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -1,7 +1,8 @@ +from asyncio import subprocess from flask import Flask, request, jsonify, send_file, send_from_directory from werkzeug.utils import secure_filename import os -from subprocess import call +from subprocess import call, run, Popen from pathlib import Path @@ -47,6 +48,59 @@ def upload(dir): resp.status_code = 500 return resp +@app.route('/build/', methods=['POST']) +def build(dir): + makestudy_dir = "demo" + "/" + dir + cur_path = os.getcwd() + concore_path = os.path.abspath(os.path.join(cur_path, '../../')) + dir_path = os.path.abspath(os.path.join(concore_path, dir)) + if not os.path.exists(secure_filename(dir_path)): + p1 = call(["./makestudy", makestudy_dir], cwd=concore_path) + if(p1 == 0): + resp = jsonify({'message': 'Directory successfully created'}) + resp.status_code = 201 + return resp + else: + resp = jsonify({'message': 'There is an Error'}) + resp.status_code = 500 + return resp + call(["./build"], cwd=dir_path) + return resp + + +@app.route('/debug/', methods=['POST']) +def debug(dir): + cur_path = os.getcwd() + concore_path = os.path.abspath(os.path.join(cur_path, '../../')) + dir_path = os.path.abspath(os.path.join(concore_path, dir)) + p1 = call(["./debug"], cwd=dir_path) + if(p1 == 0): + resp = jsonify({'message': 'Close the pop window after obtaing result'}) + resp.status_code = 201 + return resp + else: + resp = jsonify({'message': 'There is an Error'}) + resp.status_code = 500 + return resp + + + +@app.route('/destroy/', methods=['POST']) +def destroy(dir): + cur_path = os.getcwd() + concore_path = os.path.abspath(os.path.join(cur_path, '../../')) + p1 = call(["./destroy", dir], cwd=concore_path) + if(p1 == 0): + resp = jsonify({'message': 'Successfuly deleted Dirctory'}) + resp.status_code = 201 + return resp + else: + resp = jsonify({'message': 'There is an Error'}) + resp.status_code = 500 + return resp + + + # To execute any python file. For example, /execute/test?apikey=xyz @app.route('/execute/', methods=['POST']) def execute(dir): diff --git a/mkconcore.py b/mkconcore.py index 40aa885..4cb6ed5 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -10,11 +10,11 @@ GRAPHML_FILE = sys.argv[1] TRIMMED_LOGS = True CONCOREPATH = "." -CPPWIN = "g++" #Windows C++ 6/22/21 -CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 -VWIN = "iverilog" #Windows verilog 6/25/21 -VEXE = "iverilog" #Ubuntu/macOS verilog 6/25/21 -CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 +CPPWIN = "g++" #Windows C++ 6/22/21 +CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 +VWIN = "iverilog" #Windows verilog 6/25/21 +VEXE = "iverilog" #Ubuntu/macOS verilog 6/25/21 +CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 PYTHONEXE = "python3" #Ubuntu/macOS python 3 PYTHONWIN = "python" #Windows python 3 MATLABEXE = "matlab" #Ubuntu/macOS matlab @@ -22,26 +22,26 @@ OCTAVEEXE = "octave" #Ubuntu/macOS octave OCTAVEWIN = "octave" #Windows octave M_IS_OCTAVE = False #treat .m as octave -MCRPATH = "~/MATLAB/R2021a" #path to local Ubunta Matlab Compiler Runtime +MCRPATH = "~/MATLAB/R2021a" #path to local Ubunta Matlab Compiler Runtime DOCKEREXE = "sudo docker"#assume simple docker install DOCKEREPO = "markgarnold"#where pulls come from 3/28/21 INDIRNAME = ":/in" OUTDIRNAME = ":/out" - -if os.path.exists(CONCOREPATH+"/concore.octave"): - M_IS_OCTAVE = True #treat .m as octave 9/27/21 - -if os.path.exists(CONCOREPATH+"/concore.mcr"): # 11/12/21 - MCRPATH = open(CONCOREPATH+"/concore.mcr", "r").readline().strip() #path to local Ubunta Matlab Compiler Runtime - -if os.path.exists(CONCOREPATH+"/concore.sudo"): # 12/04/21 - DOCKEREXE = open(CONCOREPATH+"/concore.sudo", "r").readline().strip() #to omit sudo in docker - -if os.path.exists(CONCOREPATH+"/concore.repo"): # 12/04/21 - DOCKEREPO = open(CONCOREPATH+"/concore.repo", "r").readline().strip() #docker id for repo - - + +if os.path.exists(CONCOREPATH+"/concore.octave"): + M_IS_OCTAVE = True #treat .m as octave 9/27/21 + +if os.path.exists(CONCOREPATH+"/concore.mcr"): # 11/12/21 + MCRPATH = open(CONCOREPATH+"/concore.mcr", "r").readline().strip() #path to local Ubunta Matlab Compiler Runtime + +if os.path.exists(CONCOREPATH+"/concore.sudo"): # 12/04/21 + DOCKEREXE = open(CONCOREPATH+"/concore.sudo", "r").readline().strip() #to omit sudo in docker + +if os.path.exists(CONCOREPATH+"/concore.repo"): # 12/04/21 + DOCKEREPO = open(CONCOREPATH+"/concore.repo", "r").readline().strip() #docker id for repo + + prefixedgenode = "" sourcedir = sys.argv[2] outdir = sys.argv[3] @@ -61,13 +61,13 @@ if not (concoretype in ["posix","windows","docker","macos","ubuntu"]): print(" type must be posix (macos or ubuntu), windows, or docker") quit() -ubuntu = False #6/24/21 -if concoretype == "ubuntu": - concoretype = "posix" - ubuntu = True -if concoretype == "macos": - concoretype = "posix" - +ubuntu = False #6/24/21 +if concoretype == "ubuntu": + concoretype = "posix" + ubuntu = True +if concoretype == "macos": + concoretype = "posix" + if os.path.exists(outdir): print(outdir+" already exists") print("if intended, remove or rename "+outdir+" first") @@ -82,16 +82,16 @@ fdebug = open("debug.bat", "w") fstop = open("stop.bat", "w") #3/27/21 fclear = open("clear.bat", "w") - fmaxtime = open("maxtime.bat", "w") # 9/12/21 - funlock = open("unlock.bat", "w") # 12/4/21 + fmaxtime = open("maxtime.bat", "w") # 9/12/21 + funlock = open("unlock.bat", "w") # 12/4/21 else: fbuild = open("build","w") frun = open("run", "w") fdebug = open("debug", "w") fstop = open("stop", "w") #3/27/21 fclear = open("clear", "w") - fmaxtime = open("maxtime", "w") # 9/12/21 - funlock = open("unlock", "w") # 12/4/21 + fmaxtime = open("maxtime", "w") # 9/12/21 + funlock = open("unlock", "w") # 12/4/21 os.mkdir("src") os.chdir("..") @@ -101,9 +101,9 @@ print("source directory: "+sourcedir) print("output directory: "+outdir) print("control core type: "+concoretype) -print("treat .m as octave:"+str(M_IS_OCTAVE)) -print("MCR path: "+MCRPATH) -print("Docker repository: "+DOCKEREPO) +print("treat .m as octave:"+str(M_IS_OCTAVE)) +print("MCR path: "+MCRPATH) +print("Docker repository: "+DOCKEREPO) # Output in a preferred format. if TRIMMED_LOGS: @@ -238,7 +238,7 @@ fcopy.write(fsource.read()) fsource.close() -#copy proper concore.hpp into /src 6/22/21 +#copy proper concore.hpp into /src 6/22/21 try: if concoretype=="docker": fsource = open(CONCOREPATH+"/concoredocker.hpp") @@ -251,7 +251,7 @@ fcopy.write(fsource.read()) fsource.close() -#copy proper concore.v into /src 6/25/21 +#copy proper concore.v into /src 6/25/21 try: if concoretype=="docker": fsource = open(CONCOREPATH+"/concoredocker.v") @@ -276,7 +276,7 @@ os.chmod(outdir+"/src/mkcompile",stat.S_IRWXU) #copy concore*.m into /src 4/2/21 -try: #maxtime in matlab 11/22/21 +try: #maxtime in matlab 11/22/21 fsource = open(CONCOREPATH+"/concore_default_maxtime.m") except: print(CONCOREPATH+" is not correct path to concore") @@ -493,85 +493,85 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: fclear.write(DOCKEREXE+' volume rm ' +writeedges.split(":")[0].split("-v")[1]+"\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fclear.close() - - fmaxtime.write('echo "$1" >concore.maxtime\n') - fmaxtime.write('echo "FROM alpine:3.8" > Dockerfile\n') - fmaxtime.write('sudo docker build -t docker-concore .\n') - fmaxtime.write('sudo docker run --name=concore') - # -v VCZ:/VCZ -v VPZ:/VPZ + + fmaxtime.write('echo "$1" >concore.maxtime\n') + fmaxtime.write('echo "FROM alpine:3.8" > Dockerfile\n') + fmaxtime.write('sudo docker build -t docker-concore .\n') + fmaxtime.write('sudo docker run --name=concore') + # -v VCZ:/VCZ -v VPZ:/VPZ i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - fmaxtime.write(' -v ') + writeedges = volswr[i] + while writeedges.find(":") != -1: + fmaxtime.write(' -v ') fmaxtime.write(writeedges.split(":")[0].split("-v ")[1]+":/") fmaxtime.write(writeedges.split(":")[0].split("-v ")[1]) - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - fmaxtime.write(' docker-concore >/dev/null &\n') - fmaxtime.write('sleep 3\n') # 12/6/21 - fmaxtime.write('echo "copying concore.maxtime=$1"\n') + fmaxtime.write(' docker-concore >/dev/null &\n') + fmaxtime.write('sleep 3\n') # 12/6/21 + fmaxtime.write('echo "copying concore.maxtime=$1"\n') i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - fmaxtime.write('sudo docker cp concore.maxtime concore:/') + writeedges = volswr[i] + while writeedges.find(":") != -1: + fmaxtime.write('sudo docker cp concore.maxtime concore:/') fmaxtime.write(writeedges.split(":")[0].split("-v ")[1]+"/concore.maxtime\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - fmaxtime.write('sudo docker stop concore \n') - fmaxtime.write('sudo docker rm concore\n') - fmaxtime.write('sudo docker rmi docker-concore\n') - fmaxtime.write('rm Dockerfile\n') - fmaxtime.write('rm concore.maxtime\n') + fmaxtime.write('sudo docker stop concore \n') + fmaxtime.write('sudo docker rm concore\n') + fmaxtime.write('sudo docker rmi docker-concore\n') + fmaxtime.write('rm Dockerfile\n') + fmaxtime.write('rm concore.maxtime\n') fmaxtime.close() - funlock.write('echo "FROM alpine:3.8" > Dockerfile\n') - funlock.write('sudo docker build -t docker-concore .\n') - funlock.write('sudo docker run --name=concore') - # -v VCZ:/VCZ -v VPZ:/VPZ + funlock.write('echo "FROM alpine:3.8" > Dockerfile\n') + funlock.write('sudo docker build -t docker-concore .\n') + funlock.write('sudo docker run --name=concore') + # -v VCZ:/VCZ -v VPZ:/VPZ i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - funlock.write(' -v ') + writeedges = volswr[i] + while writeedges.find(":") != -1: + funlock.write(' -v ') funlock.write(writeedges.split(":")[0].split("-v ")[1]+":/") funlock.write(writeedges.split(":")[0].split("-v ")[1]) - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - funlock.write(' docker-concore >/dev/null &\n') - funlock.write('sleep 1\n') - funlock.write('echo "copying concore.apikey"\n') + funlock.write(' docker-concore >/dev/null &\n') + funlock.write('sleep 1\n') + funlock.write('echo "copying concore.apikey"\n') i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - funlock.write('sudo docker cp ~/concore.apikey concore:/') + writeedges = volswr[i] + while writeedges.find(":") != -1: + funlock.write('sudo docker cp ~/concore.apikey concore:/') funlock.write(writeedges.split(":")[0].split("-v ")[1]+"/concore.apikey\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - funlock.write('sudo docker stop concore \n') - funlock.write('sudo docker rm concore\n') - funlock.write('sudo docker rmi docker-concore\n') - funlock.write('rm Dockerfile\n') + funlock.write('sudo docker stop concore \n') + funlock.write('sudo docker rm concore\n') + funlock.write('sudo docker rmi docker-concore\n') + funlock.write('rm Dockerfile\n') funlock.close() @@ -595,6 +595,10 @@ #remaining code deals only with posix or windows #copy sourcefiles from ./src into corresponding directories +#chnages by me +if concoretype == "posix": + fbuild.write('#!/bin/bash'+"\n") + for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: @@ -607,9 +611,11 @@ fbuild.write("copy .\\src\\"+sourcecode+" .\\"+containername+"\\"+sourcecode+"\n") if langext == "py": fbuild.write("copy .\\src\\concore.py .\\" + containername + "\\concore.py\n") - elif langext == "cpp": # 6/22/21 + elif langext == "cpp": + # 6/22/21 fbuild.write("copy .\\src\\concore.hpp .\\" + containername + "\\concore.hpp\n") - elif langext == "v": # 6/25/21 + elif langext == "v": + # 6/25/21 fbuild.write("copy .\\src\\concore.v .\\" + containername + "\\concore.v\n") elif langext == "m": # 4/2/21 fbuild.write("copy .\\src\\concore_*.m .\\" + containername + "\\\n") @@ -676,6 +682,8 @@ i=i+1 #start running source in associated dirs (run and debug scripts) +if concoretype=="posix": + fdebug.write('#!/bin/bash' + "\n") i=0 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') @@ -719,54 +727,54 @@ else: if langext=="py": frun.write('(cd '+containername+";"+PYTHONEXE+" "+sourcecode+" >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+PYTHONEXE+" "+sourcecode+';bash"&\n') - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+PYTHONEXE+" "+sourcecode+'\\""\n') elif langext=="cpp": # 6/22/21 frun.write('(cd '+containername+";"+CPPEXE+" "+sourcecode+";./a.out >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+CPPEXE+" "+sourcecode+';./a.out;bash"&\n') - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+CPPEXE+" "+sourcecode+';./a.out\\""\n') elif langext=="v": # 6/25/21 frun.write('(cd '+containername+";"+VEXE+" "+sourcecode+";./a.out >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+VEXE+" "+sourcecode+';./a.out;bash"&\n') - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+VEXE+" "+sourcecode+';vvp a.out\\""\n') elif langext=="sh": # 5/19/21 frun.write('(cd '+containername+";./"+sourcecode+" "+ MCRPATH + " >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";./"+sourcecode+' '+MCRPATH+';bash"&\n') - else: # 11/23/21 MCRPATH + else: # 11/23/21 MCRPATH fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";./"+sourcecode+' '+MCRPATH+'\\""\n') elif langext=="m": #3/23/21 if M_IS_OCTAVE: frun.write('(cd '+containername+";"+ OCTAVEEXE+' -qf --eval run\\(\\'+"'"+sourcecode+"\\'"+'\\)'+" >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+OCTAVEEXE+' -qf --eval run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&'+"\n") - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+OCTAVEEXE+' -qf --eval run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""'+"\n") else: # 4/2/21 - frun.write('(cd ' + frun.write('(cd ' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\)'+" >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') - fdebug.write('xterm -e bash -c "cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&\n' ) - else: + fdebug.write('xterm -e bash -c "cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&\n' ) + else: fdebug.write('concorewd=`pwd`\n') - fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""\n' ) + fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""\n' ) i=0 # 3/30/21 for node in nodes_dict: @@ -787,13 +795,13 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: if concoretype=="windows": fclear.write('del /Q' + writeedges.split(":")[0].split("-v")[1]+ "\\*\n") else: fclear.write('rm ' + writeedges.split(":")[0].split("-v")[1]+ "/*\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fclear.close() @@ -802,13 +810,13 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: if concoretype=="windows": fmaxtime.write('echo %1 >' + writeedges.split(":")[0].split("-v")[1]+ "\\concore.maxtime\n") else: fmaxtime.write('echo "$1" >' + writeedges.split(":")[0].split("-v")[1]+ "/concore.maxtime\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fmaxtime.close() @@ -817,13 +825,13 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: if concoretype=="windows": funlock.write('copy %HOMEDRIVE%%HOMEPATH%\concore.apikey' + writeedges.split(":")[0].split("-v")[1]+ "\\concore.apikey\n") else: funlock.write('cp ~/concore.apikey ' + writeedges.split(":")[0].split("-v")[1]+ "/concore.apikey\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 funlock.close() From 60c43c7362fb5a25b789c4855656ba77f30c3407 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Fri, 15 Jul 2022 00:19:19 +0530 Subject: [PATCH 17/22] Revert "Added new method" This reverts commit c8619b7232acf928f1ca14dbfa0fdb897d50edb6. --- fri/server/main.py | 56 +----------- mkconcore.py | 222 ++++++++++++++++++++++----------------------- 2 files changed, 108 insertions(+), 170 deletions(-) diff --git a/fri/server/main.py b/fri/server/main.py index ce48e22..348f57a 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -1,8 +1,7 @@ -from asyncio import subprocess from flask import Flask, request, jsonify, send_file, send_from_directory from werkzeug.utils import secure_filename import os -from subprocess import call, run, Popen +from subprocess import call from pathlib import Path @@ -48,59 +47,6 @@ def upload(dir): resp.status_code = 500 return resp -@app.route('/build/', methods=['POST']) -def build(dir): - makestudy_dir = "demo" + "/" + dir - cur_path = os.getcwd() - concore_path = os.path.abspath(os.path.join(cur_path, '../../')) - dir_path = os.path.abspath(os.path.join(concore_path, dir)) - if not os.path.exists(secure_filename(dir_path)): - p1 = call(["./makestudy", makestudy_dir], cwd=concore_path) - if(p1 == 0): - resp = jsonify({'message': 'Directory successfully created'}) - resp.status_code = 201 - return resp - else: - resp = jsonify({'message': 'There is an Error'}) - resp.status_code = 500 - return resp - call(["./build"], cwd=dir_path) - return resp - - -@app.route('/debug/', methods=['POST']) -def debug(dir): - cur_path = os.getcwd() - concore_path = os.path.abspath(os.path.join(cur_path, '../../')) - dir_path = os.path.abspath(os.path.join(concore_path, dir)) - p1 = call(["./debug"], cwd=dir_path) - if(p1 == 0): - resp = jsonify({'message': 'Close the pop window after obtaing result'}) - resp.status_code = 201 - return resp - else: - resp = jsonify({'message': 'There is an Error'}) - resp.status_code = 500 - return resp - - - -@app.route('/destroy/', methods=['POST']) -def destroy(dir): - cur_path = os.getcwd() - concore_path = os.path.abspath(os.path.join(cur_path, '../../')) - p1 = call(["./destroy", dir], cwd=concore_path) - if(p1 == 0): - resp = jsonify({'message': 'Successfuly deleted Dirctory'}) - resp.status_code = 201 - return resp - else: - resp = jsonify({'message': 'There is an Error'}) - resp.status_code = 500 - return resp - - - # To execute any python file. For example, /execute/test?apikey=xyz @app.route('/execute/', methods=['POST']) def execute(dir): diff --git a/mkconcore.py b/mkconcore.py index 4cb6ed5..40aa885 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -10,11 +10,11 @@ GRAPHML_FILE = sys.argv[1] TRIMMED_LOGS = True CONCOREPATH = "." -CPPWIN = "g++" #Windows C++ 6/22/21 -CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 -VWIN = "iverilog" #Windows verilog 6/25/21 -VEXE = "iverilog" #Ubuntu/macOS verilog 6/25/21 -CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 +CPPWIN = "g++" #Windows C++ 6/22/21 +CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 +VWIN = "iverilog" #Windows verilog 6/25/21 +VEXE = "iverilog" #Ubuntu/macOS verilog 6/25/21 +CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 PYTHONEXE = "python3" #Ubuntu/macOS python 3 PYTHONWIN = "python" #Windows python 3 MATLABEXE = "matlab" #Ubuntu/macOS matlab @@ -22,26 +22,26 @@ OCTAVEEXE = "octave" #Ubuntu/macOS octave OCTAVEWIN = "octave" #Windows octave M_IS_OCTAVE = False #treat .m as octave -MCRPATH = "~/MATLAB/R2021a" #path to local Ubunta Matlab Compiler Runtime +MCRPATH = "~/MATLAB/R2021a" #path to local Ubunta Matlab Compiler Runtime DOCKEREXE = "sudo docker"#assume simple docker install DOCKEREPO = "markgarnold"#where pulls come from 3/28/21 INDIRNAME = ":/in" OUTDIRNAME = ":/out" - -if os.path.exists(CONCOREPATH+"/concore.octave"): - M_IS_OCTAVE = True #treat .m as octave 9/27/21 - -if os.path.exists(CONCOREPATH+"/concore.mcr"): # 11/12/21 - MCRPATH = open(CONCOREPATH+"/concore.mcr", "r").readline().strip() #path to local Ubunta Matlab Compiler Runtime - -if os.path.exists(CONCOREPATH+"/concore.sudo"): # 12/04/21 - DOCKEREXE = open(CONCOREPATH+"/concore.sudo", "r").readline().strip() #to omit sudo in docker - -if os.path.exists(CONCOREPATH+"/concore.repo"): # 12/04/21 - DOCKEREPO = open(CONCOREPATH+"/concore.repo", "r").readline().strip() #docker id for repo - - + +if os.path.exists(CONCOREPATH+"/concore.octave"): + M_IS_OCTAVE = True #treat .m as octave 9/27/21 + +if os.path.exists(CONCOREPATH+"/concore.mcr"): # 11/12/21 + MCRPATH = open(CONCOREPATH+"/concore.mcr", "r").readline().strip() #path to local Ubunta Matlab Compiler Runtime + +if os.path.exists(CONCOREPATH+"/concore.sudo"): # 12/04/21 + DOCKEREXE = open(CONCOREPATH+"/concore.sudo", "r").readline().strip() #to omit sudo in docker + +if os.path.exists(CONCOREPATH+"/concore.repo"): # 12/04/21 + DOCKEREPO = open(CONCOREPATH+"/concore.repo", "r").readline().strip() #docker id for repo + + prefixedgenode = "" sourcedir = sys.argv[2] outdir = sys.argv[3] @@ -61,13 +61,13 @@ if not (concoretype in ["posix","windows","docker","macos","ubuntu"]): print(" type must be posix (macos or ubuntu), windows, or docker") quit() -ubuntu = False #6/24/21 -if concoretype == "ubuntu": - concoretype = "posix" - ubuntu = True -if concoretype == "macos": - concoretype = "posix" - +ubuntu = False #6/24/21 +if concoretype == "ubuntu": + concoretype = "posix" + ubuntu = True +if concoretype == "macos": + concoretype = "posix" + if os.path.exists(outdir): print(outdir+" already exists") print("if intended, remove or rename "+outdir+" first") @@ -82,16 +82,16 @@ fdebug = open("debug.bat", "w") fstop = open("stop.bat", "w") #3/27/21 fclear = open("clear.bat", "w") - fmaxtime = open("maxtime.bat", "w") # 9/12/21 - funlock = open("unlock.bat", "w") # 12/4/21 + fmaxtime = open("maxtime.bat", "w") # 9/12/21 + funlock = open("unlock.bat", "w") # 12/4/21 else: fbuild = open("build","w") frun = open("run", "w") fdebug = open("debug", "w") fstop = open("stop", "w") #3/27/21 fclear = open("clear", "w") - fmaxtime = open("maxtime", "w") # 9/12/21 - funlock = open("unlock", "w") # 12/4/21 + fmaxtime = open("maxtime", "w") # 9/12/21 + funlock = open("unlock", "w") # 12/4/21 os.mkdir("src") os.chdir("..") @@ -101,9 +101,9 @@ print("source directory: "+sourcedir) print("output directory: "+outdir) print("control core type: "+concoretype) -print("treat .m as octave:"+str(M_IS_OCTAVE)) -print("MCR path: "+MCRPATH) -print("Docker repository: "+DOCKEREPO) +print("treat .m as octave:"+str(M_IS_OCTAVE)) +print("MCR path: "+MCRPATH) +print("Docker repository: "+DOCKEREPO) # Output in a preferred format. if TRIMMED_LOGS: @@ -238,7 +238,7 @@ fcopy.write(fsource.read()) fsource.close() -#copy proper concore.hpp into /src 6/22/21 +#copy proper concore.hpp into /src 6/22/21 try: if concoretype=="docker": fsource = open(CONCOREPATH+"/concoredocker.hpp") @@ -251,7 +251,7 @@ fcopy.write(fsource.read()) fsource.close() -#copy proper concore.v into /src 6/25/21 +#copy proper concore.v into /src 6/25/21 try: if concoretype=="docker": fsource = open(CONCOREPATH+"/concoredocker.v") @@ -276,7 +276,7 @@ os.chmod(outdir+"/src/mkcompile",stat.S_IRWXU) #copy concore*.m into /src 4/2/21 -try: #maxtime in matlab 11/22/21 +try: #maxtime in matlab 11/22/21 fsource = open(CONCOREPATH+"/concore_default_maxtime.m") except: print(CONCOREPATH+" is not correct path to concore") @@ -493,85 +493,85 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: fclear.write(DOCKEREXE+' volume rm ' +writeedges.split(":")[0].split("-v")[1]+"\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fclear.close() - - fmaxtime.write('echo "$1" >concore.maxtime\n') - fmaxtime.write('echo "FROM alpine:3.8" > Dockerfile\n') - fmaxtime.write('sudo docker build -t docker-concore .\n') - fmaxtime.write('sudo docker run --name=concore') - # -v VCZ:/VCZ -v VPZ:/VPZ + + fmaxtime.write('echo "$1" >concore.maxtime\n') + fmaxtime.write('echo "FROM alpine:3.8" > Dockerfile\n') + fmaxtime.write('sudo docker build -t docker-concore .\n') + fmaxtime.write('sudo docker run --name=concore') + # -v VCZ:/VCZ -v VPZ:/VPZ i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - fmaxtime.write(' -v ') + writeedges = volswr[i] + while writeedges.find(":") != -1: + fmaxtime.write(' -v ') fmaxtime.write(writeedges.split(":")[0].split("-v ")[1]+":/") fmaxtime.write(writeedges.split(":")[0].split("-v ")[1]) - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - fmaxtime.write(' docker-concore >/dev/null &\n') - fmaxtime.write('sleep 3\n') # 12/6/21 - fmaxtime.write('echo "copying concore.maxtime=$1"\n') + fmaxtime.write(' docker-concore >/dev/null &\n') + fmaxtime.write('sleep 3\n') # 12/6/21 + fmaxtime.write('echo "copying concore.maxtime=$1"\n') i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - fmaxtime.write('sudo docker cp concore.maxtime concore:/') + writeedges = volswr[i] + while writeedges.find(":") != -1: + fmaxtime.write('sudo docker cp concore.maxtime concore:/') fmaxtime.write(writeedges.split(":")[0].split("-v ")[1]+"/concore.maxtime\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - fmaxtime.write('sudo docker stop concore \n') - fmaxtime.write('sudo docker rm concore\n') - fmaxtime.write('sudo docker rmi docker-concore\n') - fmaxtime.write('rm Dockerfile\n') - fmaxtime.write('rm concore.maxtime\n') + fmaxtime.write('sudo docker stop concore \n') + fmaxtime.write('sudo docker rm concore\n') + fmaxtime.write('sudo docker rmi docker-concore\n') + fmaxtime.write('rm Dockerfile\n') + fmaxtime.write('rm concore.maxtime\n') fmaxtime.close() - funlock.write('echo "FROM alpine:3.8" > Dockerfile\n') - funlock.write('sudo docker build -t docker-concore .\n') - funlock.write('sudo docker run --name=concore') - # -v VCZ:/VCZ -v VPZ:/VPZ + funlock.write('echo "FROM alpine:3.8" > Dockerfile\n') + funlock.write('sudo docker build -t docker-concore .\n') + funlock.write('sudo docker run --name=concore') + # -v VCZ:/VCZ -v VPZ:/VPZ i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - funlock.write(' -v ') + writeedges = volswr[i] + while writeedges.find(":") != -1: + funlock.write(' -v ') funlock.write(writeedges.split(":")[0].split("-v ")[1]+":/") funlock.write(writeedges.split(":")[0].split("-v ")[1]) - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - funlock.write(' docker-concore >/dev/null &\n') - funlock.write('sleep 1\n') - funlock.write('echo "copying concore.apikey"\n') + funlock.write(' docker-concore >/dev/null &\n') + funlock.write('sleep 1\n') + funlock.write('echo "copying concore.apikey"\n') i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - funlock.write('sudo docker cp ~/concore.apikey concore:/') + writeedges = volswr[i] + while writeedges.find(":") != -1: + funlock.write('sudo docker cp ~/concore.apikey concore:/') funlock.write(writeedges.split(":")[0].split("-v ")[1]+"/concore.apikey\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - funlock.write('sudo docker stop concore \n') - funlock.write('sudo docker rm concore\n') - funlock.write('sudo docker rmi docker-concore\n') - funlock.write('rm Dockerfile\n') + funlock.write('sudo docker stop concore \n') + funlock.write('sudo docker rm concore\n') + funlock.write('sudo docker rmi docker-concore\n') + funlock.write('rm Dockerfile\n') funlock.close() @@ -595,10 +595,6 @@ #remaining code deals only with posix or windows #copy sourcefiles from ./src into corresponding directories -#chnages by me -if concoretype == "posix": - fbuild.write('#!/bin/bash'+"\n") - for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: @@ -611,11 +607,9 @@ fbuild.write("copy .\\src\\"+sourcecode+" .\\"+containername+"\\"+sourcecode+"\n") if langext == "py": fbuild.write("copy .\\src\\concore.py .\\" + containername + "\\concore.py\n") - elif langext == "cpp": - # 6/22/21 + elif langext == "cpp": # 6/22/21 fbuild.write("copy .\\src\\concore.hpp .\\" + containername + "\\concore.hpp\n") - elif langext == "v": - # 6/25/21 + elif langext == "v": # 6/25/21 fbuild.write("copy .\\src\\concore.v .\\" + containername + "\\concore.v\n") elif langext == "m": # 4/2/21 fbuild.write("copy .\\src\\concore_*.m .\\" + containername + "\\\n") @@ -682,8 +676,6 @@ i=i+1 #start running source in associated dirs (run and debug scripts) -if concoretype=="posix": - fdebug.write('#!/bin/bash' + "\n") i=0 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') @@ -727,54 +719,54 @@ else: if langext=="py": frun.write('(cd '+containername+";"+PYTHONEXE+" "+sourcecode+" >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+PYTHONEXE+" "+sourcecode+';bash"&\n') - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+PYTHONEXE+" "+sourcecode+'\\""\n') elif langext=="cpp": # 6/22/21 frun.write('(cd '+containername+";"+CPPEXE+" "+sourcecode+";./a.out >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+CPPEXE+" "+sourcecode+';./a.out;bash"&\n') - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+CPPEXE+" "+sourcecode+';./a.out\\""\n') elif langext=="v": # 6/25/21 frun.write('(cd '+containername+";"+VEXE+" "+sourcecode+";./a.out >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+VEXE+" "+sourcecode+';./a.out;bash"&\n') - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+VEXE+" "+sourcecode+';vvp a.out\\""\n') elif langext=="sh": # 5/19/21 frun.write('(cd '+containername+";./"+sourcecode+" "+ MCRPATH + " >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";./"+sourcecode+' '+MCRPATH+';bash"&\n') - else: # 11/23/21 MCRPATH + else: # 11/23/21 MCRPATH fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";./"+sourcecode+' '+MCRPATH+'\\""\n') elif langext=="m": #3/23/21 if M_IS_OCTAVE: frun.write('(cd '+containername+";"+ OCTAVEEXE+' -qf --eval run\\(\\'+"'"+sourcecode+"\\'"+'\\)'+" >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+OCTAVEEXE+' -qf --eval run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&'+"\n") - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+OCTAVEEXE+' -qf --eval run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""'+"\n") else: # 4/2/21 - frun.write('(cd ' + frun.write('(cd ' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\)'+" >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') - fdebug.write('xterm -e bash -c "cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&\n' ) - else: + fdebug.write('xterm -e bash -c "cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&\n' ) + else: fdebug.write('concorewd=`pwd`\n') - fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""\n' ) + fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""\n' ) i=0 # 3/30/21 for node in nodes_dict: @@ -795,13 +787,13 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: if concoretype=="windows": fclear.write('del /Q' + writeedges.split(":")[0].split("-v")[1]+ "\\*\n") else: fclear.write('rm ' + writeedges.split(":")[0].split("-v")[1]+ "/*\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fclear.close() @@ -810,13 +802,13 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: if concoretype=="windows": fmaxtime.write('echo %1 >' + writeedges.split(":")[0].split("-v")[1]+ "\\concore.maxtime\n") else: fmaxtime.write('echo "$1" >' + writeedges.split(":")[0].split("-v")[1]+ "/concore.maxtime\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fmaxtime.close() @@ -825,13 +817,13 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: if concoretype=="windows": funlock.write('copy %HOMEDRIVE%%HOMEPATH%\concore.apikey' + writeedges.split(":")[0].split("-v")[1]+ "\\concore.apikey\n") else: funlock.write('cp ~/concore.apikey ' + writeedges.split(":")[0].split("-v")[1]+ "/concore.apikey\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 funlock.close() From 79942dd72d9fed902da45290cc1c9cdad2bfae80 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Fri, 15 Jul 2022 00:39:53 +0530 Subject: [PATCH 18/22] Added new methods --- fri/server/main.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/fri/server/main.py b/fri/server/main.py index 348f57a..e6bab74 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -90,6 +90,40 @@ def execute(dir): resp.status_code = 500 return resp +@app.route('/build/', methods=['POST']) +def build(dir): + makestudy_dir = "demo" + "/" + dir + cur_path = os.getcwd() + concore_path = os.path.abspath(os.path.join(cur_path, '../../')) + dir_path = os.path.abspath(os.path.join(concore_path, dir)) + if not os.path.exists(secure_filename(dir_path)): + p1 = call(["./makestudy", makestudy_dir], cwd=concore_path) + if(p1 == 0): + resp = jsonify({'message': 'Directory successfully created'}) + resp.status_code = 201 + return resp + else: + resp = jsonify({'message': 'There is an Error'}) + resp.status_code = 500 + return resp + call(["./build"], cwd=dir_path) + return resp + + +@app.route('/debug/', methods=['POST']) +def debug(dir): + cur_path = os.getcwd() + concore_path = os.path.abspath(os.path.join(cur_path, '../../')) + dir_path = os.path.abspath(os.path.join(concore_path, dir)) + p1 = call(["./debug"], cwd=dir_path) + if(p1 == 0): + resp = jsonify({'message': 'Close the pop window after obtaing result'}) + resp.status_code = 201 + return resp + else: + resp = jsonify({'message': 'There is an Error'}) + resp.status_code = 500 + return resp # to download /download/?fetch=. For example, /download/test?fetch=example.py.out&apikey=xyz @@ -112,5 +146,19 @@ def download(dir): return resp +@app.route('/destroy/', methods=['POST']) +def destroy(dir): + cur_path = os.getcwd() + concore_path = os.path.abspath(os.path.join(cur_path, '../../')) + p1 = call(["./destroy", dir], cwd=concore_path) + if(p1 == 0): + resp = jsonify({'message': 'Successfuly deleted Dirctory'}) + resp.status_code = 201 + return resp + else: + resp = jsonify({'message': 'There is an Error'}) + resp.status_code = 500 + return resp + if __name__ == "__main__": app.run(host="0.0.0.0") From d26f1b263a10f71bcfbedca99b7f84f3ce712ac5 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Mon, 18 Jul 2022 21:05:39 +0530 Subject: [PATCH 19/22] improved build method --- fri/server/main.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fri/server/main.py b/fri/server/main.py index e6bab74..ae2db1a 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -90,24 +90,26 @@ def execute(dir): resp.status_code = 500 return resp +# to download /build/?fetch=. For example, /build/test?fetch=sample1&apikey=xyz @app.route('/build/', methods=['POST']) def build(dir): - makestudy_dir = "demo" + "/" + dir + graphml_file = request.args.get('fetch') + apikey = request.args.get('apikey') + dirname = dir + "_" + apikey # Directory for debug + makestudy_dir = dirname+ "/" + graphml_file #for makestudy cur_path = os.getcwd() concore_path = os.path.abspath(os.path.join(cur_path, '../../')) - dir_path = os.path.abspath(os.path.join(concore_path, dir)) + dir_path = os.path.abspath(os.path.join(concore_path, graphml_file)) if not os.path.exists(secure_filename(dir_path)): p1 = call(["./makestudy", makestudy_dir], cwd=concore_path) if(p1 == 0): resp = jsonify({'message': 'Directory successfully created'}) resp.status_code = 201 - return resp else: resp = jsonify({'message': 'There is an Error'}) - resp.status_code = 500 - return resp + resp.status_code = 500 call(["./build"], cwd=dir_path) - return resp + return resp @app.route('/debug/', methods=['POST']) @@ -126,6 +128,7 @@ def debug(dir): return resp + # to download /download/?fetch=. For example, /download/test?fetch=example.py.out&apikey=xyz @app.route('/download/', methods=['POST', 'GET']) def download(dir): @@ -144,8 +147,7 @@ def download(dir): resp = jsonify({'message': 'file not found'}) resp.status_code = 400 return resp - - + @app.route('/destroy/', methods=['POST']) def destroy(dir): cur_path = os.getcwd() From 4ff133d5f12f0c1c05c18e73dc7677962080cac8 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Mon, 18 Jul 2022 21:27:08 +0530 Subject: [PATCH 20/22] improved build method --- fri/server/main.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fri/server/main.py b/fri/server/main.py index ae2db1a..27519da 100644 --- a/fri/server/main.py +++ b/fri/server/main.py @@ -90,16 +90,14 @@ def execute(dir): resp.status_code = 500 return resp -# to download /build/?fetch=. For example, /build/test?fetch=sample1&apikey=xyz +# to download /build/?fetch=. For example, /build/test?fetch=sample1 @app.route('/build/', methods=['POST']) def build(dir): - graphml_file = request.args.get('fetch') - apikey = request.args.get('apikey') - dirname = dir + "_" + apikey # Directory for debug - makestudy_dir = dirname+ "/" + graphml_file #for makestudy + graphml_file = request.args.get('fetch') + makestudy_dir = dir+ "/" + graphml_file #for makestudy cur_path = os.getcwd() concore_path = os.path.abspath(os.path.join(cur_path, '../../')) - dir_path = os.path.abspath(os.path.join(concore_path, graphml_file)) + dir_path = os.path.abspath(os.path.join(concore_path, graphml_file)) #path for ./build if not os.path.exists(secure_filename(dir_path)): p1 = call(["./makestudy", makestudy_dir], cwd=concore_path) if(p1 == 0): From 069bfb0c0afa68ca8d9f4c66ca21e090c5c746b9 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Mon, 18 Jul 2022 23:54:03 +0530 Subject: [PATCH 21/22] eol --- mkconcore.py | 216 ++++++++++++++++++++++++++------------------------- 1 file changed, 109 insertions(+), 107 deletions(-) diff --git a/mkconcore.py b/mkconcore.py index 40aa885..895e8e9 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -10,11 +10,11 @@ GRAPHML_FILE = sys.argv[1] TRIMMED_LOGS = True CONCOREPATH = "." -CPPWIN = "g++" #Windows C++ 6/22/21 -CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 -VWIN = "iverilog" #Windows verilog 6/25/21 -VEXE = "iverilog" #Ubuntu/macOS verilog 6/25/21 -CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 +CPPWIN = "g++" #Windows C++ 6/22/21 +CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 +VWIN = "iverilog" #Windows verilog 6/25/21 +VEXE = "iverilog" #Ubuntu/macOS verilog 6/25/21 +CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 PYTHONEXE = "python3" #Ubuntu/macOS python 3 PYTHONWIN = "python" #Windows python 3 MATLABEXE = "matlab" #Ubuntu/macOS matlab @@ -22,26 +22,26 @@ OCTAVEEXE = "octave" #Ubuntu/macOS octave OCTAVEWIN = "octave" #Windows octave M_IS_OCTAVE = False #treat .m as octave -MCRPATH = "~/MATLAB/R2021a" #path to local Ubunta Matlab Compiler Runtime +MCRPATH = "~/MATLAB/R2021a" #path to local Ubunta Matlab Compiler Runtime DOCKEREXE = "sudo docker"#assume simple docker install DOCKEREPO = "markgarnold"#where pulls come from 3/28/21 INDIRNAME = ":/in" OUTDIRNAME = ":/out" - -if os.path.exists(CONCOREPATH+"/concore.octave"): - M_IS_OCTAVE = True #treat .m as octave 9/27/21 - -if os.path.exists(CONCOREPATH+"/concore.mcr"): # 11/12/21 - MCRPATH = open(CONCOREPATH+"/concore.mcr", "r").readline().strip() #path to local Ubunta Matlab Compiler Runtime - -if os.path.exists(CONCOREPATH+"/concore.sudo"): # 12/04/21 - DOCKEREXE = open(CONCOREPATH+"/concore.sudo", "r").readline().strip() #to omit sudo in docker - -if os.path.exists(CONCOREPATH+"/concore.repo"): # 12/04/21 - DOCKEREPO = open(CONCOREPATH+"/concore.repo", "r").readline().strip() #docker id for repo - - + +if os.path.exists(CONCOREPATH+"/concore.octave"): + M_IS_OCTAVE = True #treat .m as octave 9/27/21 + +if os.path.exists(CONCOREPATH+"/concore.mcr"): # 11/12/21 + MCRPATH = open(CONCOREPATH+"/concore.mcr", "r").readline().strip() #path to local Ubunta Matlab Compiler Runtime + +if os.path.exists(CONCOREPATH+"/concore.sudo"): # 12/04/21 + DOCKEREXE = open(CONCOREPATH+"/concore.sudo", "r").readline().strip() #to omit sudo in docker + +if os.path.exists(CONCOREPATH+"/concore.repo"): # 12/04/21 + DOCKEREPO = open(CONCOREPATH+"/concore.repo", "r").readline().strip() #docker id for repo + + prefixedgenode = "" sourcedir = sys.argv[2] outdir = sys.argv[3] @@ -61,13 +61,13 @@ if not (concoretype in ["posix","windows","docker","macos","ubuntu"]): print(" type must be posix (macos or ubuntu), windows, or docker") quit() -ubuntu = False #6/24/21 -if concoretype == "ubuntu": - concoretype = "posix" - ubuntu = True -if concoretype == "macos": - concoretype = "posix" - +ubuntu = False #6/24/21 +if concoretype == "ubuntu": + concoretype = "posix" + ubuntu = True +if concoretype == "macos": + concoretype = "posix" + if os.path.exists(outdir): print(outdir+" already exists") print("if intended, remove or rename "+outdir+" first") @@ -82,16 +82,16 @@ fdebug = open("debug.bat", "w") fstop = open("stop.bat", "w") #3/27/21 fclear = open("clear.bat", "w") - fmaxtime = open("maxtime.bat", "w") # 9/12/21 - funlock = open("unlock.bat", "w") # 12/4/21 + fmaxtime = open("maxtime.bat", "w") # 9/12/21 + funlock = open("unlock.bat", "w") # 12/4/21 else: fbuild = open("build","w") frun = open("run", "w") fdebug = open("debug", "w") fstop = open("stop", "w") #3/27/21 fclear = open("clear", "w") - fmaxtime = open("maxtime", "w") # 9/12/21 - funlock = open("unlock", "w") # 12/4/21 + fmaxtime = open("maxtime", "w") # 9/12/21 + funlock = open("unlock", "w") # 12/4/21 os.mkdir("src") os.chdir("..") @@ -101,9 +101,9 @@ print("source directory: "+sourcedir) print("output directory: "+outdir) print("control core type: "+concoretype) -print("treat .m as octave:"+str(M_IS_OCTAVE)) -print("MCR path: "+MCRPATH) -print("Docker repository: "+DOCKEREPO) +print("treat .m as octave:"+str(M_IS_OCTAVE)) +print("MCR path: "+MCRPATH) +print("Docker repository: "+DOCKEREPO) # Output in a preferred format. if TRIMMED_LOGS: @@ -238,7 +238,7 @@ fcopy.write(fsource.read()) fsource.close() -#copy proper concore.hpp into /src 6/22/21 +#copy proper concore.hpp into /src 6/22/21 try: if concoretype=="docker": fsource = open(CONCOREPATH+"/concoredocker.hpp") @@ -251,7 +251,7 @@ fcopy.write(fsource.read()) fsource.close() -#copy proper concore.v into /src 6/25/21 +#copy proper concore.v into /src 6/25/21 try: if concoretype=="docker": fsource = open(CONCOREPATH+"/concoredocker.v") @@ -276,7 +276,7 @@ os.chmod(outdir+"/src/mkcompile",stat.S_IRWXU) #copy concore*.m into /src 4/2/21 -try: #maxtime in matlab 11/22/21 +try: #maxtime in matlab 11/22/21 fsource = open(CONCOREPATH+"/concore_default_maxtime.m") except: print(CONCOREPATH+" is not correct path to concore") @@ -493,85 +493,85 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: fclear.write(DOCKEREXE+' volume rm ' +writeedges.split(":")[0].split("-v")[1]+"\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fclear.close() - - fmaxtime.write('echo "$1" >concore.maxtime\n') - fmaxtime.write('echo "FROM alpine:3.8" > Dockerfile\n') - fmaxtime.write('sudo docker build -t docker-concore .\n') - fmaxtime.write('sudo docker run --name=concore') - # -v VCZ:/VCZ -v VPZ:/VPZ + + fmaxtime.write('echo "$1" >concore.maxtime\n') + fmaxtime.write('echo "FROM alpine:3.8" > Dockerfile\n') + fmaxtime.write('sudo docker build -t docker-concore .\n') + fmaxtime.write('sudo docker run --name=concore') + # -v VCZ:/VCZ -v VPZ:/VPZ i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - fmaxtime.write(' -v ') + writeedges = volswr[i] + while writeedges.find(":") != -1: + fmaxtime.write(' -v ') fmaxtime.write(writeedges.split(":")[0].split("-v ")[1]+":/") fmaxtime.write(writeedges.split(":")[0].split("-v ")[1]) - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - fmaxtime.write(' docker-concore >/dev/null &\n') - fmaxtime.write('sleep 3\n') # 12/6/21 - fmaxtime.write('echo "copying concore.maxtime=$1"\n') + fmaxtime.write(' docker-concore >/dev/null &\n') + fmaxtime.write('sleep 3\n') # 12/6/21 + fmaxtime.write('echo "copying concore.maxtime=$1"\n') i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - fmaxtime.write('sudo docker cp concore.maxtime concore:/') + writeedges = volswr[i] + while writeedges.find(":") != -1: + fmaxtime.write('sudo docker cp concore.maxtime concore:/') fmaxtime.write(writeedges.split(":")[0].split("-v ")[1]+"/concore.maxtime\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - fmaxtime.write('sudo docker stop concore \n') - fmaxtime.write('sudo docker rm concore\n') - fmaxtime.write('sudo docker rmi docker-concore\n') - fmaxtime.write('rm Dockerfile\n') - fmaxtime.write('rm concore.maxtime\n') + fmaxtime.write('sudo docker stop concore \n') + fmaxtime.write('sudo docker rm concore\n') + fmaxtime.write('sudo docker rmi docker-concore\n') + fmaxtime.write('rm Dockerfile\n') + fmaxtime.write('rm concore.maxtime\n') fmaxtime.close() - funlock.write('echo "FROM alpine:3.8" > Dockerfile\n') - funlock.write('sudo docker build -t docker-concore .\n') - funlock.write('sudo docker run --name=concore') - # -v VCZ:/VCZ -v VPZ:/VPZ + funlock.write('echo "FROM alpine:3.8" > Dockerfile\n') + funlock.write('sudo docker build -t docker-concore .\n') + funlock.write('sudo docker run --name=concore') + # -v VCZ:/VCZ -v VPZ:/VPZ i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - funlock.write(' -v ') + writeedges = volswr[i] + while writeedges.find(":") != -1: + funlock.write(' -v ') funlock.write(writeedges.split(":")[0].split("-v ")[1]+":/") funlock.write(writeedges.split(":")[0].split("-v ")[1]) - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - funlock.write(' docker-concore >/dev/null &\n') - funlock.write('sleep 1\n') - funlock.write('echo "copying concore.apikey"\n') + funlock.write(' docker-concore >/dev/null &\n') + funlock.write('sleep 1\n') + funlock.write('echo "copying concore.apikey"\n') i=0 # 9/12/21 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: - funlock.write('sudo docker cp ~/concore.apikey concore:/') + writeedges = volswr[i] + while writeedges.find(":") != -1: + funlock.write('sudo docker cp ~/concore.apikey concore:/') funlock.write(writeedges.split(":")[0].split("-v ")[1]+"/concore.apikey\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 - funlock.write('sudo docker stop concore \n') - funlock.write('sudo docker rm concore\n') - funlock.write('sudo docker rmi docker-concore\n') - funlock.write('rm Dockerfile\n') + funlock.write('sudo docker stop concore \n') + funlock.write('sudo docker rm concore\n') + funlock.write('sudo docker rmi docker-concore\n') + funlock.write('rm Dockerfile\n') funlock.close() @@ -607,9 +607,11 @@ fbuild.write("copy .\\src\\"+sourcecode+" .\\"+containername+"\\"+sourcecode+"\n") if langext == "py": fbuild.write("copy .\\src\\concore.py .\\" + containername + "\\concore.py\n") - elif langext == "cpp": # 6/22/21 + elif langext == "cpp": + # 6/22/21 fbuild.write("copy .\\src\\concore.hpp .\\" + containername + "\\concore.hpp\n") - elif langext == "v": # 6/25/21 + elif langext == "v": + # 6/25/21 fbuild.write("copy .\\src\\concore.v .\\" + containername + "\\concore.v\n") elif langext == "m": # 4/2/21 fbuild.write("copy .\\src\\concore_*.m .\\" + containername + "\\\n") @@ -719,54 +721,54 @@ else: if langext=="py": frun.write('(cd '+containername+";"+PYTHONEXE+" "+sourcecode+" >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+PYTHONEXE+" "+sourcecode+';bash"&\n') - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+PYTHONEXE+" "+sourcecode+'\\""\n') elif langext=="cpp": # 6/22/21 frun.write('(cd '+containername+";"+CPPEXE+" "+sourcecode+";./a.out >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+CPPEXE+" "+sourcecode+';./a.out;bash"&\n') - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+CPPEXE+" "+sourcecode+';./a.out\\""\n') elif langext=="v": # 6/25/21 frun.write('(cd '+containername+";"+VEXE+" "+sourcecode+";./a.out >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+VEXE+" "+sourcecode+';./a.out;bash"&\n') - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+VEXE+" "+sourcecode+';vvp a.out\\""\n') elif langext=="sh": # 5/19/21 frun.write('(cd '+containername+";./"+sourcecode+" "+ MCRPATH + " >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";./"+sourcecode+' '+MCRPATH+';bash"&\n') - else: # 11/23/21 MCRPATH + else: # 11/23/21 MCRPATH fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";./"+sourcecode+' '+MCRPATH+'\\""\n') elif langext=="m": #3/23/21 if M_IS_OCTAVE: frun.write('(cd '+containername+";"+ OCTAVEEXE+' -qf --eval run\\(\\'+"'"+sourcecode+"\\'"+'\\)'+" >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+OCTAVEEXE+' -qf --eval run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&'+"\n") - else: + else: fdebug.write('concorewd=`pwd`\n') fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+OCTAVEEXE+' -qf --eval run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""'+"\n") else: # 4/2/21 - frun.write('(cd ' + frun.write('(cd ' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\)'+" >concoreout.txt&echo $!>concorepid)&\n") - if ubuntu: + if ubuntu: fdebug.write('concorewd=`pwd`\n') - fdebug.write('xterm -e bash -c "cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&\n' ) - else: + fdebug.write('xterm -e bash -c "cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&\n' ) + else: fdebug.write('concorewd=`pwd`\n') - fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""\n' ) + fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""\n' ) i=0 # 3/30/21 for node in nodes_dict: @@ -787,13 +789,13 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: if concoretype=="windows": fclear.write('del /Q' + writeedges.split(":")[0].split("-v")[1]+ "\\*\n") else: fclear.write('rm ' + writeedges.split(":")[0].split("-v")[1]+ "/*\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fclear.close() @@ -802,13 +804,13 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: if concoretype=="windows": fmaxtime.write('echo %1 >' + writeedges.split(":")[0].split("-v")[1]+ "\\concore.maxtime\n") else: fmaxtime.write('echo "$1" >' + writeedges.split(":")[0].split("-v")[1]+ "/concore.maxtime\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fmaxtime.close() @@ -817,13 +819,13 @@ containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: dockername = sourcecode.split(".")[0] #3/28/21 - writeedges = volswr[i] - while writeedges.find(":") != -1: + writeedges = volswr[i] + while writeedges.find(":") != -1: if concoretype=="windows": funlock.write('copy %HOMEDRIVE%%HOMEPATH%\concore.apikey' + writeedges.split(":")[0].split("-v")[1]+ "\\concore.apikey\n") else: funlock.write('cp ~/concore.apikey ' + writeedges.split(":")[0].split("-v")[1]+ "/concore.apikey\n") - writeedges = writeedges[writeedges.find(":")+1:] + writeedges = writeedges[writeedges.find(":")+1:] i=i+1 funlock.close() From d033b4c4a07caa2c4593c7ef609070c0fadbccd7 Mon Sep 17 00:00:00 2001 From: amit-62 Date: Tue, 19 Jul 2022 00:20:06 +0530 Subject: [PATCH 22/22] added changes for debug and build --- mkconcore.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mkconcore.py b/mkconcore.py index 895e8e9..302e600 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -595,6 +595,9 @@ #remaining code deals only with posix or windows #copy sourcefiles from ./src into corresponding directories +if concoretype=="posix": + fbuild.write('#!/bin/bash' + "\n") + for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':') if len(sourcecode)!=0: @@ -678,6 +681,9 @@ i=i+1 #start running source in associated dirs (run and debug scripts) +if concoretype=="posix": + fdebug.write('#!/bin/bash' + "\n") + i=0 for node in nodes_dict: containername,sourcecode = nodes_dict[node].split(':')