mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
add yunohost-typer|fastapi new bins
This commit is contained in:
parent
a318e06e8d
commit
c016f4b510
2 changed files with 59 additions and 0 deletions
33
bin/yunohost-fastapi
Executable file
33
bin/yunohost-fastapi
Executable file
|
@ -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)
|
26
bin/yunohost-typer
Executable file
26
bin/yunohost-typer
Executable file
|
@ -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()
|
Loading…
Add table
Reference in a new issue