Пример #1
0
def main(argv):

    parser = _lab_parser(prog="lab")
    args = parser.parse_args(argv)

    # clean all projects
    if args.clean_all_projects:
        clean_all_project_tmp_files()
        return

    # clean project by project_id
    if args.clean_project is not None:
        clean_project_tmp_files(args.clean_project)
        return

    # shortcuts for host and port
    host = args.ip
    port = args.port

    def _internal_open_webbrowser():
        _open_browser(host, port)

    # open webbrowser if not in flask development mode
    if os.environ.get('FLASK_ENV', "") != "development":
        Timer(1, _internal_open_webbrowser).start()

    print("\n\n\n\nIf your browser doesn't open. "
          "Please navigate to '{url}'\n\n\n\n".format(url=_url(host, port)))

    app = create_app(embedding_fp=args.embedding_fp,
                     config_file=args.config_file,
                     seed=args.seed)
    app.config['PROPAGATE_EXCEPTIONS'] = False
    app.run(host=host, port=port)
Пример #2
0
def main(argv):

    parser = _lab_parser(prog="lab")
    kwargs = vars(parser.parse_args(argv))

    host = kwargs.pop("ip")
    port = kwargs.pop("port")

    def _internal_open_webbrowser():
        _open_browser(host, port)

    # open webbrowser if not in flask development mode
    if os.environ.get('FLASK_ENV', "") != "development":
        Timer(1, _internal_open_webbrowser).start()

    print("\n\n\n\nIf your browser doesn't open. "
          "Please navigate to '{url}'\n\n\n\n".format(url=_url(host, port)))

    app = create_app(**kwargs)
    app.run(host=host, port=port)
Пример #3
0
def main(argv):

    parser = _lab_parser(prog="lab")
    args = parser.parse_args(argv)

    app = create_app(
        embedding_fp=args.embedding_fp,
        config_file=args.config_file,
        seed=args.seed
    )
    app.config['PROPAGATE_EXCEPTIONS'] = False

    # ssl certificate, key and protocol
    certfile = args.certfile
    keyfile = args.keyfile
    ssl_context = None
    if certfile and keyfile:
        protocol = "https://"
        ssl_context = (certfile, keyfile)
    else:
        protocol = "http://"

    # clean all projects
    if args.clean_all_projects:
        print("Cleaning all project files.")
        clean_all_project_tmp_files()
        print("Done")
        return

    # clean project by project_id
    if args.clean_project is not None:
        print(f"Cleaning project file '{args.clean_project}'.")
        clean_project_tmp_files(args.clean_project)
        print("Done")
        return

    flask_dev = os.environ.get('FLASK_ENV', "") == "development"
    host = args.ip
    port = args.port
    port_retries = args.port_retries
    # if port is already taken find another one
    if not os.environ.get('FLASK_ENV', "") == "development":
        original_port = port
        while check_port_in_use(host, port) is True:
            old_port = port
            port = int(port) + 1
            if port - original_port >= port_retries:
                raise ConnectionError(
                    "Could not find an available port \n"
                    "to launch ASReview LAB. Last port \n"
                    f"was {str(port)}"
                )
            print(
                f"Port {old_port} is in use.\n* Trying to start at {port}"
            )

    # open webbrowser if not in flask development mode
    if flask_dev is False:
        _open_browser(host, port, protocol, args.no_browser)

    # run app in flask mode only if flask_env == development is True
    if flask_dev is True:
        app.run(host=host, port=port, ssl_context=ssl_context)
    else:
        ssl_args = {'keyfile': keyfile, 'certfile': certfile} if ssl_context else {}
        server = WSGIServer((host, port), app, **ssl_args)
        server.serve_forever()