]> git.phdru.name Git - m_librarian.git/blob - scripts/ml-web.py
Feat: Web UI
[m_librarian.git] / scripts / ml-web.py
1 #! /usr/bin/env python
2
3 import argparse
4 import time
5 import webbrowser
6
7 from bottle import thread  # portable import
8
9 import m_librarian.web.app  # noqa: F401 imported but unused
10 from m_librarian.web.server import run_server
11 from m_librarian.web.utils import get_open_port
12
13
14 def start_browser(port):
15     time.sleep(1)  # A small timeout to allow the main thread to run the server
16     webbrowser.open_new('http://localhost:%d/' % port)
17
18
19 if __name__ == '__main__':
20     parser = argparse.ArgumentParser(description='Init')
21     parser.add_argument('-p', '--port', help='HTTP server port')
22     args = parser.parse_args()
23
24     if args.port:
25         port = args.port
26     else:
27         port = get_open_port()
28
29     thread.start_new_thread(start_browser, (port,))
30     run_server(port=port)