aboutsummaryrefslogtreecommitdiffstats
path: root/Web
diff options
context:
space:
mode:
Diffstat (limited to 'Web')
-rw-r--r--Web/PI/PI.py25
-rw-r--r--Web/PI/Results/results.txt2
-rw-r--r--Web/PI/Uploads/upload.py13
-rw-r--r--Web/PI/test2.py6
-rw-r--r--Web/Server/Results/results.txt2
-rw-r--r--Web/Server/Server.py30
-rw-r--r--Web/Server/static/Server.js5
-rw-r--r--Web/Server/templates/index.html43
-rw-r--r--Web/Server/templates/upload.html37
-rw-r--r--Web/test.py8
10 files changed, 91 insertions, 80 deletions
diff --git a/Web/PI/PI.py b/Web/PI/PI.py
index 5e75298..b607f76 100644
--- a/Web/PI/PI.py
+++ b/Web/PI/PI.py
@@ -4,9 +4,9 @@ import subprocess
import os
app = Flask(__name__)
-UPLOAD_DESTINATION = "Uploads/upload.py"
+UPLOAD_DESTINATION = "Uploads/"
-RESULTS_DESTINATION = "Results/results.txt"
+RESULTS_DESTINATION = "Results/"
@app.route('/')
def home():
@@ -18,25 +18,28 @@ def my_test_endpoint():
input_json = request.get_json(force=True)
# Put file content into a file caled upload.py
- file_content=input_json['file_content']
- upload = open(UPLOAD_DESTINATION, "w")
+ filename=input_json['filename'].encode("ascii")
+ file_content=input_json['file_content'].encode("ascii")
+ upload = open(UPLOAD_DESTINATION + filename, "w")
upload.write(file_content)
upload.close()
# Run python script
- subprocess.call(["python", UPLOAD_DESTINATION])
+ subprocess.call(["python", UPLOAD_DESTINATION + filename])
# Get results file
- with open(RESULTS_DESTINATION, 'r') as results:
+ results_filename = filename.split(".")[0]
+ results_filename = results_filename + "_results"
+ with open(RESULTS_DESTINATION + results_filename, 'r') as results:
results_content = results.read()
results.close()
-
- # subprocess.check_output(["echo", "Hello World!"])
- # os.remove(UPLOAD_DESTINATION)
- # os.remove(RESULTS_DESTINATION)
+
+ # Remove test file and results file now that were done with them
+ os.remove(UPLOAD_DESTINATION + filename)
+ os.remove(RESULTS_DESTINATION + results_filename)
# Return results file content
- dictToReturn = {'results_content':results_content}
+ dictToReturn = {'results_filename':results_filename, 'results_content':results_content}
return jsonify(dictToReturn)
if __name__ == '__main__':
diff --git a/Web/PI/Results/results.txt b/Web/PI/Results/results.txt
deleted file mode 100644
index ce8f671..0000000
--- a/Web/PI/Results/results.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-THIS IS RESULTS TEXT
-Current Time = 21:07:34 \ No newline at end of file
diff --git a/Web/PI/Uploads/upload.py b/Web/PI/Uploads/upload.py
deleted file mode 100644
index 9cbc73a..0000000
--- a/Web/PI/Uploads/upload.py
+++ /dev/null
@@ -1,13 +0,0 @@
-import time, os
-from datetime import datetime
-
-now = datetime.now()
-current_time = now.strftime("%H:%M:%S")
-print("Current Time = " + current_time)
-
-f = open("Results/results.txt", "w+")
-f.write("THIS IS RESULTS TEXT\n")
-f.write("Current Time = " + current_time)
-f.close()
-print("Running test.py for ~ 5 seconds.")
-time.sleep(5)
diff --git a/Web/PI/test2.py b/Web/PI/test2.py
index 40bbe9c..a5eb806 100644
--- a/Web/PI/test2.py
+++ b/Web/PI/test2.py
@@ -1,3 +1,7 @@
import subprocess
+import os
+
subprocess.call(["python", "Uploads/upload.py"])
-print("end of script") \ No newline at end of file
+print("end of script")
+
+os.remove("Uploads/upload.py") \ No newline at end of file
diff --git a/Web/Server/Results/results.txt b/Web/Server/Results/results.txt
index ce8f671..f668b82 100644
--- a/Web/Server/Results/results.txt
+++ b/Web/Server/Results/results.txt
@@ -1,2 +1,2 @@
THIS IS RESULTS TEXT
-Current Time = 21:07:34 \ No newline at end of file
+Current Time = 13:41:59 \ No newline at end of file
diff --git a/Web/Server/Server.py b/Web/Server/Server.py
index bab440a..0c3013b 100644
--- a/Web/Server/Server.py
+++ b/Web/Server/Server.py
@@ -9,10 +9,10 @@ import requests
import json
app = Flask(__name__)
-app.secret_key = "secret key"
+app.secret_key = "ski u mah"
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
-ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'py'])
+ALLOWED_EXTENSIONS = set(['py'])
PI_URL = 'http://localhost:8000'
@@ -22,8 +22,8 @@ def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
-def upload_form():
- return render_template('upload.html')
+def home():
+ return render_template('index.html')
@app.route('/upload', methods=['POST'])
def upload_file():
@@ -41,30 +41,34 @@ def upload_file():
# Send the file content as a post to the PI
if file and allowed_file(file.filename):
- dictToSend = {'file_content':file.read()}
+ dictToSend = {'filename':file.filename, 'file_content':file.read()}
file.close
print('Running test')
flash('Running test')
response = requests.post(PI_URL + '/tests/endpoint', json=dictToSend)
- contents = json.loads(response.text)[u'results_content']
- flash('Response from server:' + contents)
-
+
+ results_filename = json.loads(response.text)[u'results_filename'] .encode("ascii")
+ results_content = json.loads(response.text)[u'results_content'].encode("ascii")
+ flash('Results file:' + results_filename)
+ flash('Response from server:' + results_content)
+
results = open(RESULTS_DESTINATION, "w")
- results.write(contents)
+ results.write(results_content)
results.close()
- return render_template('upload.html', results = 'True')
+ return render_template('index.html', results = 'True')
else:
flash('Allowed file types are txt, pdf, png, jpg, jpeg, gif')
return redirect(request.url)
-@app.route('/results', methods=['GET'])# this is a job for GET, not POST
+@app.route('/results', methods=['GET'])
def download():
- print("in downlaods")
+ # Grab content from results file
with open(RESULTS_DESTINATION, 'r') as results:
results_content = results.read()
results.close()
- print("results_content")
+
+ # Put content as a download file
return Response(
results_content,
mimetype="text/csv",
diff --git a/Web/Server/static/Server.js b/Web/Server/static/Server.js
index 49f1f13..30274f2 100644
--- a/Web/Server/static/Server.js
+++ b/Web/Server/static/Server.js
@@ -2,4 +2,9 @@ function showLoad(){
var paragraph = document.getElementById("message");
var text = document.createTextNode("RUNNING TEST");
paragraph.appendChild(text);
+
+ var div = document.getElementById("upload");
+ if (div.style.display !== 'none') {
+ div.style.display = 'none';
+ }
} \ No newline at end of file
diff --git a/Web/Server/templates/index.html b/Web/Server/templates/index.html
new file mode 100644
index 0000000..70a282b
--- /dev/null
+++ b/Web/Server/templates/index.html
@@ -0,0 +1,43 @@
+<html>
+ <head>
+ <link rel="stylesheet" href="/static/Server.css">
+ <script type="text/javascript" src="/static/Server.js"></script>
+ </head>
+ <body>
+ <title>ANDI'S PIE</title>
+ <div id="upload">
+ <h2>Select a file to upload</h2>
+ <p>
+ {% with messages = get_flashed_messages() %}
+ {% if messages %}
+ <ul class=flashes>
+ {% for message in messages %}
+ <li>{{ message }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ {% endwith %}
+ </p>
+
+ <form method="post" action="/upload" enctype="multipart/form-data">
+ <dl>
+ <p>
+ <input type="file" name="file" autocomplete="off" required>
+ </p>
+ </dl>
+ <p>
+ <input type="submit" value="Submit" onclick="showLoad()">
+ </p>
+ </form>
+ </div>
+
+ <div id="message"></div>
+
+ {% if results %}
+ <form method="get" action="/results">
+ <button type="submit">Download!</button>
+ </form>
+ {% endif %}
+
+ </body>
+</html> \ No newline at end of file
diff --git a/Web/Server/templates/upload.html b/Web/Server/templates/upload.html
deleted file mode 100644
index 38c4a09..0000000
--- a/Web/Server/templates/upload.html
+++ /dev/null
@@ -1,37 +0,0 @@
-<html>
- <head>
- <link rel="stylesheet" href="/static/Server.css">
- <script type="text/javascript" src="/static/Server.js"></script>
- </head>
- <body>
- <title>Python Flask File Upload Example</title>
- <h2>Select a file to upload</h2>
- <p id = "message">
- {% with messages = get_flashed_messages() %}
- {% if messages %}
- <ul class=flashes>
- {% for message in messages %}
- <li>{{ message }}</li>
- {% endfor %}
- </ul>
- {% endif %}
- {% endwith %}
- </p>
- <form method="post" action="/upload" enctype="multipart/form-data">
- <dl>
- <p>
- <input type="file" name="file" autocomplete="off" required>
- </p>
- </dl>
- <p>
- <input type="submit" value="Submit" onclick="showLoad()">
- </p>
- </form>
-
- {% if results %}
- <form method="get" action="/results">
- <button type="submit">Download!</button>
- </form>
- {% endif %}
- </body>
-</html> \ No newline at end of file
diff --git a/Web/test.py b/Web/test.py
index c6f871c..634bc84 100644
--- a/Web/test.py
+++ b/Web/test.py
@@ -1,11 +1,15 @@
-import time, os
+import time, os, sys
from datetime import datetime
+file_name = os.path.basename(sys.argv[0])
+
+file_name = file_name.split(".")[0]
+
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("Current Time = " + current_time)
-f = open("Results/results.txt", "w+")
+f = open("Results/" + file_name + "_results", "w+")
f.write("THIS IS RESULTS TEXT\n")
f.write("Current Time = " + current_time)
f.close()