]> git.phdru.name Git - m_librarian.git/blobdiff - scripts/ml-web.py
Feat: Web UI
[m_librarian.git] / scripts / ml-web.py
diff --git a/scripts/ml-web.py b/scripts/ml-web.py
new file mode 100755 (executable)
index 0000000..f5a579e
--- /dev/null
@@ -0,0 +1,30 @@
+#! /usr/bin/env python
+
+import argparse
+import time
+import webbrowser
+
+from bottle import thread  # portable import
+
+import m_librarian.web.app  # noqa: F401 imported but unused
+from m_librarian.web.server import run_server
+from m_librarian.web.utils import get_open_port
+
+
+def start_browser(port):
+    time.sleep(1)  # A small timeout to allow the main thread to run the server
+    webbrowser.open_new('http://localhost:%d/' % port)
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser(description='Init')
+    parser.add_argument('-p', '--port', help='HTTP server port')
+    args = parser.parse_args()
+
+    if args.port:
+        port = args.port
+    else:
+        port = get_open_port()
+
+    thread.start_new_thread(start_browser, (port,))
+    run_server(port=port)