mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-02 01:18:08 +01:00
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:
parent
ce1522db64
commit
7d50a224c6
4 changed files with 59 additions and 10 deletions
14
lib/simple_mirror.py
Normal file
14
lib/simple_mirror.py
Normal 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)
|
||||
|
|
@ -12,7 +12,7 @@ import shutil
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
def run(*args, **kwargs):
|
||||
def run(*args, cleanup=None, **kwargs):
|
||||
"""A small wrapper around subprocess.run"""
|
||||
arguments = [str(arg) for arg in args if arg is not None]
|
||||
|
||||
|
|
@ -23,6 +23,8 @@ def run(*args, **kwargs):
|
|||
return subprocess.run(arguments, check=True, **kwargs)
|
||||
except subprocess.CalledProcessError:
|
||||
print("Bootstrapping failed")
|
||||
if cleanup:
|
||||
cleanup()
|
||||
sys.exit(1)
|
||||
|
||||
def run_as_root(*args, **kwargs):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue