52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
#! /usr/bin/python3
|
|
|
|
import argparse
|
|
import http.server
|
|
import pathlib
|
|
|
|
import reader, encoder, statuser
|
|
|
|
class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|
def __init__(self, r, a, s, directory, statuser):
|
|
self.statuser = statuser
|
|
super().__init__(r, a, s, directory=directory)
|
|
|
|
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()
|
|
buf = self.statuser.json().encode("utf-8")
|
|
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()
|
|
|
|
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()
|
|
|
|
handler = lambda r, a, s: HTTPRequestHandler(r, a, s, directory=args.www, statuser=st)
|
|
httpd = http.server.ThreadingHTTPServer(('', args.port), handler)
|
|
httpd.serve_forever()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# vi: sw=4 ts=4 et ai
|