diff --git a/functions.py b/functions.py index c7f03d0..855b6bc 100644 --- a/functions.py +++ b/functions.py @@ -1,5 +1,8 @@ import os import shutil +from functools import partial +from http.server import HTTPServer, SimpleHTTPRequestHandler +from pathlib import Path def read_file(file_path): @@ -15,4 +18,11 @@ def write_file(file_path, content): def copy_file(src, dst): os.makedirs(os.path.dirname(dst), exist_ok=True) - shutil.copy2(src, dst) \ No newline at end of file + shutil.copy2(src, dst) + +# Функция для запуска веб-сервера +def start_httpd(directory: Path, port: int = 8000): + print(f"Listen on port {port}, serving from {directory}...") + handler = partial(SimpleHTTPRequestHandler, directory=directory) + httpd = HTTPServer(('localhost', port), handler) + httpd.serve_forever() \ No newline at end of file