def http(reloader: bool, port: int, host: str, brain_name: str) -> None: "Run a server for mutliheaded (multiplex) pyborg" brain_path = resolve_brain(brain_name) bottle.install(BottledPyborg(brain_path=brain_path)) bottle.run(host=host, port=port, reloader=reloader) bottle.default_app().close()
"contexts": pyborg.settings.num_contexts, "lines": len(pyborg.lines) } @bottle.route("/commands.json") def commands_json(pyborg) -> Dict: return pyborg.commanddict @bottle.get("/meta/status.json") def save_lock_status(pyborg) -> Dict: return {"status": SAVE_LOCK.is_locked} @bottle.post("/meta/logging-level") def set_log_level() -> None: """levels = {"DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARNING": logging.WARNING, "ERROR": logging.ERROR, "CRITICAL": logging.CRITICAL} """ logger.setLevel(request.POST.get("level").upper()) if __name__ == '__main__': logging.basicConfig(level=logging.INFO) folder = click.get_app_dir("Pyborg") bottle.install( BottledPyborg( brain_path=os.path.join(folder, "brains", "current.pyborg.json"))) bottle.run(host="localhost", port=2001, reloader=True)
return "word not known" @bottle.route("/words.json") def words_json(pyborg): return {"words": pyborg.settings.num_words, "contexts": pyborg.settings.num_contexts, "lines": len(pyborg.lines)} @bottle.route("/commands.json") def commands_json(pyborg): return pyborg.commanddict @bottle.route("/logging-level", method="POST") def set_log_level(): # when we drop 2 support this can use strings instead of the enums levels = {"DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARNING": logging.WARNING, "ERROR": logging.ERROR, "CRITICAL": logging.CRITICAL} target = levels[request.POST.get("level").upper()] logger.setLevel(target) if __name__ == '__main__': logging.basicConfig(level=logging.INFO) folder = click.get_app_dir("Pyborg") brain_path = os.path.join(folder, "brains", "current.pyborg.json") bottle.install(BottledPyborg(brain_path=brain_path)) bottle.run(host="localhost", port=2001, reloader=True)
def http(reloader, port, host, brain): "Run a server for mutliheaded (multiplex) pyborg" brain_path = resolve_brain(brain) bottle.install(BottledPyborg(brain_path=brain_path)) bottle.run(host=host, port=port, reloader=reloader) bottle.default_app().close()