2022-01-17 20:55:16 -07:00
|
|
|
#! /usr/bin/python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import http.server
|
|
|
|
import pathlib
|
|
|
|
|
2022-02-26 08:05:20 -07:00
|
|
|
import reader, encoder, statuser
|
2022-01-17 20:55:16 -07:00
|
|
|
|
|
|
|
class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
2022-02-26 08:05:20 -07:00
|
|
|
def __init__(self, r, a, s, directory, statuser):
|
|
|
|
self.statuser = statuser
|
|
|
|
super().__init__(r, a, s, directory=directory)
|
|
|
|
|
2022-01-17 20:55:16 -07:00
|
|
|
def do_GET(self):
|
|
|
|
if self.path == "/status.json":
|
|
|
|
return self.get_status()
|
|
|
|
return super().do_GET()
|
|
|
|
|
|
|
|
def get_status(self):
|
|
|
|
self.send_response(200)
|
|
|
|
self.end_headers()
|
2022-02-26 08:05:20 -07:00
|
|
|
buf = self.statuser.json().encode("utf-8")
|
2022-01-17 20:55:16 -07:00
|
|
|
self.wfile.write(buf)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="Rip/encode optical media")
|
|
|
|
parser.add_argument("-incoming", type=pathlib.Path, default="/incoming")
|
|
|
|
parser.add_argument("-www", type=pathlib.Path, default="/www")
|
|
|
|
parser.add_argument("-port", type=int, default=8080)
|
|
|
|
parser.add_argument("-drive", nargs="+", default=["/dev/sr0"])
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2022-02-26 08:05:20 -07:00
|
|
|
readers = []
|
|
|
|
for d in args.drive:
|
|
|
|
readers.append(reader.Reader(d, directory=args.incoming, daemon=True))
|
|
|
|
encoders = []
|
|
|
|
for i in range(1):
|
|
|
|
encoders.append(encoder.Encoder(directory=args.incoming, daemon=True))
|
|
|
|
st = statuser.Statuser(readers + encoders, directory=args.incoming, daemon=True)
|
|
|
|
|
|
|
|
[w.start() for w in readers + encoders]
|
|
|
|
st.start()
|
2022-01-17 20:55:16 -07:00
|
|
|
|
2022-02-26 08:05:20 -07:00
|
|
|
handler = lambda r, a, s: HTTPRequestHandler(r, a, s, directory=args.www, statuser=st)
|
2022-01-17 20:55:16 -07:00
|
|
|
httpd = http.server.ThreadingHTTPServer(('', args.port), handler)
|
|
|
|
httpd.serve_forever()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|
|
|
|
|
|
# vi: sw=4 ts=4 et ai
|