From 7697b7463ea04613fa52fea70226b5eb00ff031d Mon Sep 17 00:00:00 2001 From: John Solntsev Date: Tue, 4 Jun 2024 17:25:11 +0300 Subject: [PATCH] Write log files to directory Move index file to parent directory, remove template directory --- config.py | 4 +--- static/index.html => index.html | 0 main.py | 6 ++++++ server/main.py | 10 ++++++++-- server/urlhandler.py | 19 +++++++++++++++---- template/index.html | 10 ---------- 6 files changed, 30 insertions(+), 19 deletions(-) rename static/index.html => index.html (100%) delete mode 100644 template/index.html diff --git a/config.py b/config.py index 1dcacd5..d32d64e 100644 --- a/config.py +++ b/config.py @@ -1,9 +1,7 @@ from logging import NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL - -import testmod - from server.urlhandler import path +import testmod SETUP = { "setup": { diff --git a/static/index.html b/index.html similarity index 100% rename from static/index.html rename to index.html diff --git a/main.py b/main.py index 0a5b796..68c9fcd 100755 --- a/main.py +++ b/main.py @@ -1,7 +1,13 @@ #!/usr/bin/python3 +import os from server.main import start if __name__ == "__main__": + try: + os.mkdir(os.path.join(os.getcwd(), "log")) + except OSError: + pass #print("dir is exists") + start() diff --git a/server/main.py b/server/main.py index b73909f..367248b 100644 --- a/server/main.py +++ b/server/main.py @@ -1,6 +1,7 @@ import threading import socket import logging +import os import config @@ -188,8 +189,13 @@ class HTTPHandler: def start(): - logging.basicConfig(filename="main.log", filemode="a", encoding="UTF-8", - level=config.SETUP["setup"]["log_level"], format="[%(asctime)s][%(levelname)s] %(message)s") + logging.basicConfig( + filename=os.path.join(os.getcwd(), "log", "main.log"), + filemode="a", + encoding="UTF-8", + level=config.SETUP["setup"]["log_level"], + format="[%(asctime)s][%(levelname)s] %(message)s" + ) project_logotype = """ ___________ _____ _____________ diff --git a/server/urlhandler.py b/server/urlhandler.py index 5d5f28f..068b223 100644 --- a/server/urlhandler.py +++ b/server/urlhandler.py @@ -1,7 +1,18 @@ +import os + + def path(path="/", _type="static-file", link="index.html", methods=("GET",)): if _type == "static-file": - return {path: (methods, _type, "static/{}".format(link))} - if _type == "redirect": - return {path: (methods, _type, link)} + return { + path: (methods, _type, os.path.join(os.getcwd(), link)) + } + + elif _type == "redirect": + return { + path: (methods, _type, link) + } + elif _type == "function": - return {path: (methods, _type, link)} + return { + path: (methods, _type, link) + } diff --git a/template/index.html b/template/index.html deleted file mode 100644 index 6f9937e..0000000 --- a/template/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - CatNet Template - - -

Template has been loaded

-

{template_data}

- -