This commit is contained in:
Digital Studium 2023-07-23 11:44:15 +03:00
parent 0414cc9bdb
commit 7b3e66514a
1 changed files with 11 additions and 1 deletions

View File

@ -1,5 +1,8 @@
import os import os
import shutil import shutil
from functools import partial
from http.server import HTTPServer, SimpleHTTPRequestHandler
from pathlib import Path
def read_file(file_path): def read_file(file_path):
@ -16,3 +19,10 @@ def write_file(file_path, content):
def copy_file(src, dst): def copy_file(src, dst):
os.makedirs(os.path.dirname(dst), exist_ok=True) os.makedirs(os.path.dirname(dst), exist_ok=True)
shutil.copy2(src, dst) 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()