live-bootstrap/lib/simple_mirror.py
fosslinux 7d50a224c6 Support file:// mirrors
Spawns a simple HTTP server to host the mirror.
Useful for testing mirror support or CI in chroot or bwrap modes.
2025-02-02 10:02:32 +11:00

14 lines
427 B
Python

import http.server
import socketserver
class SimpleMirror(socketserver.TCPServer):
def __init__(self, directory: str):
self.directory = directory
super().__init__(("localhost", 0), self._handler)
@property
def port(self):
return self.server_address[1]
def _handler(self, *args, **kwargs):
return http.server.SimpleHTTPRequestHandler(*args, directory=self.directory, **kwargs)