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)


 #!/usr/bin/env python
-# -*- coding: utf-8 -*
+# encoding: utf-8
+"""Brightway2 web user interface.
+ [--port=<port>] [--nobrowser] [--debug|--insecure]
+ -h | --help
+ --version
+  -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
+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 = "{}".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"] = ''
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
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.