Skip to content

Commit

Permalink
Fix incorrect path for Linux
Browse files Browse the repository at this point in the history
Fix path appending issue to make it able to cross platform.
Update readme and batch files.
  • Loading branch information
yat17006 committed Mar 22, 2021
1 parent e1fa3a5 commit b0d11b9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
7 changes: 4 additions & 3 deletions Python/filegenerator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from time import strftime as getTime
import csv
import json
import os

from . import connectionObject
import matplotlib.pyplot as plt
Expand All @@ -18,8 +19,8 @@ def __init__(self, make_log, make_summary,
self.makeSummary = make_summary
self.makeAnimation = make_animation
# File Name to be used
self.logFileName = "logs\\log-{0}.csv".format(str(sessionId))
self.summaryFileName = "summaries\\summary-{0}.csv".format(str(sessionId))
self.logFileName = os.path.join("logs", "log-{0}.csv".format(str(sessionId)))
self.summaryFileName = os.path.join("summaries", "summary-{0}.csv".format(str(sessionId)))
# names of the output files
self.logName = log_name
self.summaryName = summary_name
Expand Down Expand Up @@ -597,5 +598,5 @@ def genPlot(self, name, start):
plt.title("Packets " + name + " vs. Time")
plt.legend()

plt.savefig("plots\\"+name+"-{0}.svg".format(str(self.sessionId)))
plt.savefig(os.path.join("plots", name + "-{0}.svg".format(str(self.sessionId))))
plt.close()
3 changes: 2 additions & 1 deletion cleanup.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@echo off
del *.csv
del logs\log-*.csv
del summaries\summary-*.csv
del summaries\summary-*.csv
del plots\*.svg
9 changes: 5 additions & 4 deletions pserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import sys
import Python.main as main
import os

app = Flask(__name__)

Expand Down Expand Up @@ -66,9 +67,9 @@ def runSimulation(input1):
def download(fileName):
try:
if fileName.startswith("log"):
return send_file("logs\\" + fileName, as_attachment=True)
return send_file(os.path.join("logs", fileName), as_attachment=True)
elif fileName.startswith("summary"):
return send_file("summaries\\" + fileName, as_attachment=True)
return send_file(os.path.join("summaries", fileName), as_attachment=True)
else:
abort(400)
except FileNotFoundError:
Expand All @@ -84,9 +85,9 @@ def download2(statement):
if len(tmp)==2:
try:
if fileName.startswith("log"):
return send_file("logs\\" + fileName, as_attachment=True, attachment_filename=newName)
return send_file(os.path.join("logs", fileName), as_attachment=True, attachment_filename=newName)
elif fileName.startswith("summary"):
return send_file("summaries\\" + fileName, as_attachment=True, attachment_filename=newName)
return send_file(os.path.join("summaries", fileName), as_attachment=True, attachment_filename=newName)
else:
abort(400)
except FileNotFoundError:
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ Follow these steps to get started:
2. Execute the following command to install `flask`:
```bat
pip install flask
pip install matplotlib
```

3. If it is your first time to run the server, you should create some folders:
```bat
mkdir logs
mkdir summaries
mkdir plots
```

4. Execute the following commands to run flask:
Expand Down Expand Up @@ -61,6 +63,7 @@ export FLASK_ENV=development
```bat
mkdir summaries
mkdir logs
mkdir plots
```

3) Run the following
Expand Down
5 changes: 3 additions & 2 deletions run_server.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@echo off
set FLASK_APP=pserver
set FLASK_ENV=development
mkdir logs > NUL
mkdir summaries > NUL
mkdir logs
mkdir summaries
mkdir plots
python -m flask run
pause.

0 comments on commit b0d11b9

Please sign in to comment.