X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=scripts%2Fml-web.py;h=c93b5fd88c2243a4d923d2a795065592e605b417;hb=9305df13fd2c3a935b2de82a28eea4cb6989e8e8;hp=f5a579e006718b3be33d1ea85ca3856a4e00851a;hpb=2d76928b93c208d27f942b9a9eb649df1d5b2192;p=m_librarian.git diff --git a/scripts/ml-web.py b/scripts/ml-web.py index f5a579e..c93b5fd 100755 --- a/scripts/ml-web.py +++ b/scripts/ml-web.py @@ -6,9 +6,10 @@ import webbrowser from bottle import thread # portable import -import m_librarian.web.app # noqa: F401 imported but unused +from m_librarian.db import open_db from m_librarian.web.server import run_server -from m_librarian.web.utils import get_open_port +from m_librarian.web.utils import get_lock, close_lock, get_open_port +import m_librarian.web.app # noqa: F401 imported but unused def start_browser(port): @@ -17,7 +18,7 @@ def start_browser(port): if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Init') + parser = argparse.ArgumentParser(description='m_Librarin web interface') parser.add_argument('-p', '--port', help='HTTP server port') args = parser.parse_args() @@ -26,5 +27,11 @@ if __name__ == '__main__': else: port = get_open_port() - thread.start_new_thread(start_browser, (port,)) - run_server(port=port) + lock_file, old_port = get_lock(port) + if lock_file: + open_db() + thread.start_new_thread(start_browser, (port,)) + run_server(port=port) + close_lock(lock_file) + else: # Another instance of the program is being run at a different port + start_browser(old_port)