Source

brightway2-ui / bw2ui / bin / bw2-web.py

#!/usr/bin/env python
# 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
from werkzeug.serving import run_simple
import random
import threading
import webbrowser


if __name__ == "__main__":
    args = docopt(__doc__, version='Brightway2 Web UI 0.1')
    port = int(args.get("--port", False) or 5000 + random.randint(0, 999))
    host = "0.0.0.0" if args.get("--insecure", False) else "localhost"

    if not args["--nobrowser"]:
        url = "http://127.0.0.1:{}".format(port)
        threading.Timer(1., lambda: webbrowser.open_new_tab(url)).start()

    kwargs = {
        "processes": args.get("--processes", 0) or 3,
        "use_debugger": args["--debug"]
    }

    run_simple(host, port, bw2webapp, **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.