From 8887dc5a9803969e23b24eb293711c1e32c374e5 Mon Sep 17 00:00:00 2001
From: Dat Nguyen 
Date: Wed, 20 Nov 2019 21:10:51 -0600
Subject: Web stuff semi working
---
 Web/PI/Results/results.txt | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 Web/PI/Results/results.txt
(limited to 'Web/PI/Results')
diff --git a/Web/PI/Results/results.txt b/Web/PI/Results/results.txt
new file mode 100644
index 0000000..ce8f671
--- /dev/null
+++ b/Web/PI/Results/results.txt
@@ -0,0 +1,2 @@
+THIS IS RESULTS TEXT
+Current Time = 21:07:34
\ No newline at end of file
-- 
cgit v1.2.3
From 20f9ea9141f77b3c21232efc30202408d535de18 Mon Sep 17 00:00:00 2001
From: Dat Nguyen 
Date: Thu, 21 Nov 2019 13:45:20 -0600
Subject: working web stuff with running page
---
 Web/PI/PI.py                     | 25 +++++++++++++----------
 Web/PI/Results/results.txt       |  2 --
 Web/PI/Uploads/upload.py         | 13 ------------
 Web/PI/test2.py                  |  6 +++++-
 Web/Server/Results/results.txt   |  2 +-
 Web/Server/Server.py             | 30 ++++++++++++++++------------
 Web/Server/static/Server.js      |  5 +++++
 Web/Server/templates/index.html  | 43 ++++++++++++++++++++++++++++++++++++++++
 Web/Server/templates/upload.html | 37 ----------------------------------
 Web/test.py                      |  8 ++++++--
 10 files changed, 91 insertions(+), 80 deletions(-)
 delete mode 100644 Web/PI/Results/results.txt
 delete mode 100644 Web/PI/Uploads/upload.py
 create mode 100644 Web/Server/templates/index.html
 delete mode 100644 Web/Server/templates/upload.html
(limited to 'Web/PI/Results')
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 @@
+
+    
+        
+        
+    
+    
+		ANDI'S PIE
+		
+			
Select a file to upload
+			
+				{% with messages = get_flashed_messages() %}
+				{% if messages %}
+					
+					{% for message in messages %}
+					- {{ message }}+					{% endfor %}
+
+				{% endif %}
+				{% endwith %}
+			
+		
+			
+		
Select a file to upload
-		
-			{% with messages = get_flashed_messages() %}
-			{% if messages %}
-				
-				{% for message in messages %}
-				- {{ message }}-				{% endfor %}
-
-			{% endif %}
-			{% endwith %}
-
-		
-
-		{% if results %}
-			
-		{% endif %}
-    
-
\ 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()
-- 
cgit v1.2.3
From ea4f2916605dc184b8eba1bc3bae0b0035a17451 Mon Sep 17 00:00:00 2001
From: Dat Nguyen 
Date: Thu, 21 Nov 2019 15:28:57 -0600
Subject: a bunch of placeholder files
---
 Web/PI/Results/PLACEHOLDER.txt | 0
 Web/PI/Uploads/PLACEHOLDER     | 0
 Web/Server/Results/PLACEHOLDER | 0
 Web/Server/Results/results.txt | 2 --
 4 files changed, 2 deletions(-)
 create mode 100644 Web/PI/Results/PLACEHOLDER.txt
 create mode 100644 Web/PI/Uploads/PLACEHOLDER
 create mode 100644 Web/Server/Results/PLACEHOLDER
 delete mode 100644 Web/Server/Results/results.txt
(limited to 'Web/PI/Results')
diff --git a/Web/PI/Results/PLACEHOLDER.txt b/Web/PI/Results/PLACEHOLDER.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Web/PI/Uploads/PLACEHOLDER b/Web/PI/Uploads/PLACEHOLDER
new file mode 100644
index 0000000..e69de29
diff --git a/Web/Server/Results/PLACEHOLDER b/Web/Server/Results/PLACEHOLDER
new file mode 100644
index 0000000..e69de29
diff --git a/Web/Server/Results/results.txt b/Web/Server/Results/results.txt
deleted file mode 100644
index f668b82..0000000
--- a/Web/Server/Results/results.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-THIS IS RESULTS TEXT
-Current Time = 13:41:59
\ No newline at end of file
-- 
cgit v1.2.3