Skip to content
Snippets Groups Projects
Verified Commit 495293e5 authored by Théo Pirkl's avatar Théo Pirkl :nail_care:
Browse files

Cleans out old semester project files

parent e4e3e500
Branches
No related tags found
No related merge requests found
......@@ -7,7 +7,6 @@ DB_PASSWORD=3
WORKERS_NUMBER=6
HTTPHANDLER_WEBSERVER_PORT=7070 # The management of the host worker pool
HTTPHANDLER_EVENTS_PORT=7071 # The port to the host's management interface
CLIENT_PORT=18965 # The client's management port
SERVER_PORT=18964 # The server's management port
......
......@@ -5,20 +5,18 @@ from os import getenv as env
from flask import Flask, request, send_from_directory
from loguru import logger
from common.networking.radio import Radio
from common.utils.LoguruHandler import FlaskToLoguruHandler
from common.utils.io import getFilesInFileFolder
app = Flask(__name__)
bridge = Radio("127.0.0.1", int(env("HTTPHANDLER_EVENTS_PORT")), False)
@app.route("/", methods=["GET"])
# Shows all web API usages
def showUsage():
routes = {
"/pageUpdate": "Notifies the crawler that the webpage has been refreshed by the server.",
"/pageChange": "Notifies the crawler that the webpage has changed its state.",
"/files/all": "Downloads all files from this host",
"/files/<filename>": "Downloads, if it exists, the file from this host.",
"/shutdown": "Shuts down the server. Do not use until all jobs are finished.",
"/": "Shows this web page."
}
......@@ -30,20 +28,6 @@ def showUsage():
return output
@app.route("/pageUpdate")
def noticeOfPageUpdate():
uuid = request.args["uuid"]
__notify__(uuid, True, False)
return "OK"
@app.route("/pageChange")
def noticeOfPageChange():
uuid = request.args["uuid"]
__notify__(uuid, False, True)
return "OK"
@app.route("/shutdown")
def shutdown():
func = request.environ.get('werkzeug.server.shutdown')
......@@ -76,12 +60,6 @@ def download(filename):
return send_from_directory(directory=env("FILE_LOCKER"), filename=filename)
# Notifies the observers that a change happened
def __notify__(observerID, hasPageUpdated: bool, hasPageChanged: bool):
logger.debug("Notifying...")
bridge.talk(observerID, {"updated": hasPageUpdated, "changed": hasPageChanged})
# Runs the web server
def start(port):
def actualStart():
......
class FileParser:
path: str = None
# Initializes the file parser
def __init__(self, path: str):
self.path = path
self.data = {}
def run(self, instructions: dict) -> dict:
for name, instruction in instructions.items():
if type(name) == str and name == "read" and instruction:
file = open(self.path, 'r')
self.data = [k.rstrip() for k in file.readlines()]
return {"fileParserOutput": self.data}
import time
from threading import Thread
from loguru import logger
from sqlalchemy import func
from sqlalchemy.orm import Session
from os import getenv as env
# Allows for client performance observation
from common.networking.intercom import Intercom
class PerformanceObserver:
shouldStop: bool = False # Should stop monitoring
clients: list = [] # Clients list
timing: int = 1 # Timing between every measure
def __init__(self, clients, timing):
self.folder = env("FILE_LOCKER")
self.clients = clients
self.timing = timing
def start(self, shouldMonitorTasksInDB, shouldMonitorFilesInFileLocker):
Thread(target=self.monitor, args=(shouldMonitorTasksInDB, shouldMonitorFilesInFileLocker)) \
.start()
# Monitors every N second the requested data
# Format : number of seconds passed,
def monitor(self, shouldMonitorTasksInDB, shouldMonitorFilesInFileLocker):
if not shouldMonitorTasksInDB and not shouldMonitorFilesInFileLocker:
logger.error("You have chosen not to monitor anything...")
exit(250)
logger.info("Starting performance observer : DB monitoring = {}, File monitoring = {}"
.format(shouldMonitorTasksInDB, shouldMonitorFilesInFileLocker))
secondsPassed = 0
lastFileCount = 0
with open('measures.csv', 'a') as fd:
while not self.shouldStop:
currentRun = [str(secondsPassed)]
if shouldMonitorFilesInFileLocker:
total = 0
# Reaching all clients to get statrep files number
for client in self.clients:
intercom = Intercom(client, env("CLIENT_PORT"), True)
intercom.talk({"type": "statrep"})
statrep = {}
try:
statrep = intercom.listen(750)
except:
total = lastFileCount # Safe
break
total += len(statrep.get("files") or [])
lastFileCount = total
currentRun.append(str(total))
fd.write(",".join(currentRun) + "\n")
fd.flush()
time.sleep(self.timing)
secondsPassed += 1
def stop(self):
self.shouldStop = True
logger.info("Stopped observer with success.")
import re
from loguru import logger
class RegexParser:
text: str = None
def __init__(self, text):
self.text = text
def run(self, regex: str):
data = None
if type(self.text) == str:
data = re.findall(regex, self.text)
elif type(self.text) == list:
data = [re.findall(regex, line) for line in self.text]
data = [k[0] for k in data if len(k) > 0] # Selective flatmap
else:
logger.error("Unsupported regex recognition format.")
return {"regexParserOutput": data}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment