Debian 11 Проверка работы эмулятора Hasp + Web

#!/usr/bin/env python

import argparse, os, sys, socket, subprocess
from http.server import HTTPServer, BaseHTTPRequestHandler

lsusb = (os.popen("lsusb | grep Aladdin").read())
lsusb = lsusb.replace('Bus','<br />Bus')

hasplm = subprocess.Popen("systemctl status hasplm", shell=True, stdout=subprocess.PIPE).stdout.read()
hasplm = hasplm.replace(b"\n",b"<br />")
hasplm = hasplm.replace(b"\xe2\x97\x8f ",b"<br />")
hasplm = hasplm.replace(b"\xe2\x94\x94\xe2\x94\x80",b"")
hasplm = hasplm.replace(b"\xe2\x94\x9c\xe2\x94\x80",b"")
hasplm = hasplm.decode('utf-8')
haspd = subprocess.Popen("systemctl status haspd", shell=True, stdout=subprocess.PIPE).stdout.read()
haspd = haspd.replace(b"\n",b"<br />")
haspd = haspd.replace(b"\xe2\x97\x8f ",b"<br />")
haspd = haspd.replace(b"\xe2\x94\x94\xe2\x94\x80",b"")
haspd = haspd.replace(b"\xe2\x94\x9c\xe2\x94\x80",b"")
haspd = haspd.decode('utf-8')
usbhaspd = subprocess.Popen("systemctl status usbhaspd", shell=True, stdout=subprocess.PIPE).stdout.read()
usbhaspd = usbhaspd.replace(b"\n",b"<br />")
usbhaspd = usbhaspd.replace(b"\xe2\x97\x8f ",b"<br />")
usbhaspd = usbhaspd.replace(b"\xe2\x94\x94\xe2\x94\x80",b"")
usbhaspd = usbhaspd.replace(b"\xe2\x94\x9c\xe2\x94\x80",b"")
usbhaspd = usbhaspd.decode('utf-8')

class S(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()

def _html(self, message):
"""This just generates an HTML document that includes `message`
in the body. Override, or re-write this do do more interesting stuff.
"""
content = f"<html><body><h1>{message}</h1><p><b>lsusb | grep Aladdin</b>{lsusb}</p><p><b>systemctl status hasplm</b><br>{hasplm}</p><p><b>systemctl status haspd</b><br>{haspd}</p><p><b>systemctl status usbhaspd</b><br>{usbhaspd}</p></body></html>"
return content.encode("utf8") # NOTE: must return a bytes object!

def do_GET(self):
self._set_headers()
self.wfile.write(self._html("hi!"))

def do_HEAD(self):
self._set_headers()

def do_POST(self):
# Doesn't do anything with posted data
self._set_headers()
self.wfile.write(self._html("POST!"))


def run(server_class=HTTPServer, handler_class=S, addr="localhost", port=8000):
server_address = (addr, port)
httpd = server_class(server_address, handler_class)

print(f"Starting httpd server on {addr}:{port}")
httpd.serve_forever()


if __name__ == "__main__":

parser = argparse.ArgumentParser(description="Run a simple HTTP server")
parser.add_argument(
"-l",
"--listen",
default="localhost",
help="Specify the IP address on which the server listens",
)
parser.add_argument(
"-p",
"--port",
type=int,
default=8000,
help="Specify the port on which the server listens",
)
args = parser.parse_args()
run(addr=args.listen, port=args.port)