Support file:// mirrors

Spawns a simple HTTP server to host the mirror.
Useful for testing mirror support or CI in chroot or bwrap modes.
This commit is contained in:
fosslinux 2025-01-12 12:54:31 +11:00
parent ce1522db64
commit 7d50a224c6
4 changed files with 59 additions and 10 deletions

14
lib/simple_mirror.py Normal file
View file

@ -0,0 +1,14 @@
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)