logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>

simple_mirror.py (727B)


  1. #!/usr/bin/env python3
  2. """
  3. This creates a simple "mirror" from a directory
  4. """
  5. # SPDX-License-Identifier: GPL-3.0-or-later
  6. # SPDX-FileCopyrightText: 2025 fosslinux <fosslinux@aussies.space>
  7. import http.server
  8. import socketserver
  9. class SimpleMirror(socketserver.TCPServer):
  10. """Simple HTTP mirror from a directory"""
  11. def __init__(self, directory: str):
  12. self.directory = directory
  13. super().__init__(("localhost", 0), self._handler)
  14. @property
  15. def port(self):
  16. """Port the HTTP server of the mirror is running on"""
  17. return self.server_address[1]
  18. def _handler(self, *args, **kwargs):
  19. return http.server.SimpleHTTPRequestHandler(*args, directory=self.directory, **kwargs)