live-bootstrap/lib/simple_mirror.py
2025-02-02 10:02:32 +11:00

23 lines
727 B
Python

#!/usr/bin/env python3
"""
This creates a simple "mirror" from a directory
"""
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2025 fosslinux <fosslinux@aussies.space>
import http.server
import socketserver
class SimpleMirror(socketserver.TCPServer):
"""Simple HTTP mirror from a directory"""
def __init__(self, directory: str):
self.directory = directory
super().__init__(("localhost", 0), self._handler)
@property
def port(self):
"""Port the HTTP server of the mirror is running on"""
return self.server_address[1]
def _handler(self, *args, **kwargs):
return http.server.SimpleHTTPRequestHandler(*args, directory=self.directory, **kwargs)