diff --git a/Python/filegenerator.py b/Python/filegenerator.py index f22c182..63ee4ca 100644 --- a/Python/filegenerator.py +++ b/Python/filegenerator.py @@ -1,6 +1,7 @@ from time import strftime as getTime import csv import json +import os from . import connectionObject import matplotlib.pyplot as plt @@ -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 @@ -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() diff --git a/cleanup.bat b/cleanup.bat index 3ef374d..b4a5735 100644 --- a/cleanup.bat +++ b/cleanup.bat @@ -1,4 +1,5 @@ @echo off del *.csv del logs\log-*.csv -del summaries\summary-*.csv \ No newline at end of file +del summaries\summary-*.csv +del plots\*.svg \ No newline at end of file diff --git a/pserver.py b/pserver.py index 3d884ee..231743c 100644 --- a/pserver.py +++ b/pserver.py @@ -4,6 +4,7 @@ import time import sys import Python.main as main +import os app = Flask(__name__) @@ -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: @@ -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: diff --git a/readme.md b/readme.md index dffa6c3..202ac48 100644 --- a/readme.md +++ b/readme.md @@ -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: @@ -61,6 +63,7 @@ export FLASK_ENV=development ```bat mkdir summaries mkdir logs +mkdir plots ``` 3) Run the following diff --git a/run_server.bat b/run_server.bat index 8afd09a..1f69c73 100644 --- a/run_server.bat +++ b/run_server.bat @@ -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. \ No newline at end of file