brightway2-ui / bw2ui / bin /

#!/usr/bin/env python
# encoding: utf-8
"""Brightway2 web user interface.

Usage: [--port=<port>] [--processes=<processes>] [--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 bw2ui.utils import clean_jobs_directory
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 = "" if args.get("--insecure", False) else "localhost"

    if not args["--nobrowser"]:
        url = "{}".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, use_evalex=True, **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
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.