Chris Mutel avatar Chris Mutel committed 1a86ea6

Web UI script has options for port, starting browser automatically, debug, and outward facing server

Comments (0)

Files changed (1)

bw2ui/bin/bw2-web.py

 #!/usr/bin/env python
-# -*- coding: utf-8 -*
+# encoding: utf-8
+"""Brightway2 web user interface.
+
+Usage:
+  bw2-web.py [--port=<port>] [--nobrowser] [--debug|--insecure]
+  bw2-web.py -h | --help
+  bw2-web.py --version
+
+Options:
+  -h --help     Show this screen.
+  --version     Show version.
+  --nobrowser   Don't automatically open a browser tab.
+  --debug       Use Werkzeug debug mode (not recommended).
+  --insecure    Allow outside connections (insecure!). Not with --debug.
+
+"""
 from bw2ui.web import bw2webapp
+from docopt import docopt
+import random
+import threading
+import webbrowser
 
-bw2webapp.run(debug=True)
+
+if __name__ == "__main__":
+    args = docopt(__doc__, version='Brightway2 Web UI 0.1')
+
+    if args["--port"]:
+        port = int(args["--port"])
+    else:
+        port = 5000 + random.randint(0, 999)
+    url = "http://127.0.0.1:{}".format(port)
+
+    if not args["--nobrowser"]:
+        threading.Timer(1., lambda: webbrowser.open_new_tab(url)).start()
+
+    kwargs = {
+        "port": port,
+        "debug": args["--debug"]
+    }
+    if args["--insecure"]:
+        kwargs["host"] = '0.0.0.0'
+
+    bw2webapp.run(**kwargs)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.