From c016f4b510a0459136917258875d8197fd1ff898 Mon Sep 17 00:00:00 2001 From: axolotle Date: Sat, 7 Jan 2023 14:08:06 +0100 Subject: [PATCH] add yunohost-typer|fastapi new bins --- bin/yunohost-fastapi | 33 +++++++++++++++++++++++++++++++++ bin/yunohost-typer | 26 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100755 bin/yunohost-fastapi create mode 100755 bin/yunohost-typer diff --git a/bin/yunohost-fastapi b/bin/yunohost-fastapi new file mode 100755 index 000000000..de7c41c14 --- /dev/null +++ b/bin/yunohost-fastapi @@ -0,0 +1,33 @@ +#! /usr/bin/python3 + +import os +import typer +import uvicorn + +os.environ["INTERFACE"] = "api" + + +def main( + host: str = typer.Option("127.0.0.1", "--host", "-h", help="Host to listen on", rich_help_panel="Server configuration"), + port: int = typer.Option(6787, "--port", "-p", help="Port to listen on", rich_help_panel="Server configuration"), + debug: bool = typer.Option(False, "--debug", help="Set log level to DEBUG"), + reload: bool = typer.Option(False, "--reload", hidden=True), + reload_dirs: list[str] = typer.Option([], hidden=True) +): + """ + Run the YunoHost API to manage your server. + """ + uvicorn.run( + "yunohost.__init_:create_interface", + factory=True, + host=host, + port=port, + log_level="info" if not debug else "debug", + reload=reload, + reload_dirs=reload_dirs, + root_path="/yunohost/api", + ) + + +if __name__ == "__main__": + typer.run(main) diff --git a/bin/yunohost-typer b/bin/yunohost-typer new file mode 100755 index 000000000..d6048d77d --- /dev/null +++ b/bin/yunohost-typer @@ -0,0 +1,26 @@ +#! /usr/bin/python3 + +import os +import sys + +os.environ["INTERFACE"] = "cli" + +# Stupid PATH management because sometimes (e.g. some cron job) PATH is only /usr/bin:/bin ... +default_path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" +if os.environ["PATH"] != default_path: + os.environ["PATH"] = default_path + ":" + os.environ["PATH"] + + +if __name__ == "__main__": + + from yunohost.__init_ import create_interface + + if os.geteuid() != 0: + sys.stderr.write( + "\033[1;31mError:\033[0m yunohost command must be " + "run as root or with sudo.\n" + ) + sys.exit(1) + + app = create_interface() + app()