mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
remove no longer used function + fix uvicorn logging + fix Interface definition to work with moulinette
This commit is contained in:
parent
e9be533ec7
commit
a850a9caab
4 changed files with 19 additions and 62 deletions
|
@ -56,7 +56,7 @@ def init_logging(interface="cli", debug=False, quiet=False, logdir="/var/log/yun
|
||||||
|
|
||||||
logging_configuration = {
|
logging_configuration = {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"disable_existing_loggers": True,
|
"disable_existing_loggers": False,
|
||||||
"formatters": {
|
"formatters": {
|
||||||
"console": {
|
"console": {
|
||||||
"format": "%(relativeCreated)-5d %(levelname)-8s %(name)s %(funcName)s - %(message)s"
|
"format": "%(relativeCreated)-5d %(levelname)-8s %(name)s %(funcName)s - %(message)s"
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from yunohost.interface.base import InterfaceKind
|
from yunohost.interface.base import InterfaceKind, Field
|
||||||
|
|
||||||
if os.environ.get("INTERFACE", "cli") == "cli":
|
if os.environ.get("INTERFACE") == "cli":
|
||||||
from yunohost.interface.cli import Interface
|
from yunohost.interface.cli import Interface
|
||||||
else:
|
elif os.environ.get("INTERFACE") == "api":
|
||||||
from yunohost.interface.api import Interface
|
from yunohost.interface.api import Interface
|
||||||
|
else:
|
||||||
|
# FIXME for Moulinette to work
|
||||||
|
from yunohost.interface.base import BaseInterface as Interface
|
||||||
|
|
|
@ -30,35 +30,6 @@ def parse_api_route(route: str) -> list[str]:
|
||||||
return re.findall(r"{(\w+)}", route)
|
return re.findall(r"{(\w+)}", route)
|
||||||
|
|
||||||
|
|
||||||
def params_to_body(
|
|
||||||
params: list[inspect.Parameter],
|
|
||||||
data: dict[str, Any],
|
|
||||||
doc: dict[str, Any],
|
|
||||||
func_name: str,
|
|
||||||
) -> inspect.Parameter:
|
|
||||||
model = pydantic.create_model(
|
|
||||||
snake_to_camel_case(func_name),
|
|
||||||
**{
|
|
||||||
param.name: (
|
|
||||||
param.annotation,
|
|
||||||
pydantic.Field(
|
|
||||||
param.default if param.default != param.empty else ...,
|
|
||||||
description=doc.get(param.name, None),
|
|
||||||
**data.get(param.name, {}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
for param in params
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return inspect.Parameter(
|
|
||||||
func_name.split("_")[0],
|
|
||||||
inspect.Parameter.POSITIONAL_ONLY,
|
|
||||||
default=...,
|
|
||||||
annotation=model,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Interface(BaseInterface):
|
class Interface(BaseInterface):
|
||||||
kind = InterfaceKind.API
|
kind = InterfaceKind.API
|
||||||
|
|
||||||
|
@ -72,32 +43,11 @@ class Interface(BaseInterface):
|
||||||
def add(self, interface: Interface):
|
def add(self, interface: Interface):
|
||||||
assert isinstance(interface.instance, fastapi.APIRouter)
|
assert isinstance(interface.instance, fastapi.APIRouter)
|
||||||
self.instance.include_router(
|
self.instance.include_router(
|
||||||
interface.instance, prefix=interface.prefix, tags=[interface.name] if interface.name else []
|
interface.instance,
|
||||||
|
prefix=interface.prefix,
|
||||||
|
tags=[interface.name] if interface.name else [],
|
||||||
)
|
)
|
||||||
|
|
||||||
def prepare_params(
|
|
||||||
self,
|
|
||||||
params: list[inspect.Parameter],
|
|
||||||
as_body: bool,
|
|
||||||
as_body_except: Optional[list[str]] = None,
|
|
||||||
) -> list[Union[list[inspect.Parameter], inspect.Parameter]]:
|
|
||||||
params = self.filter_params(params)
|
|
||||||
|
|
||||||
if as_body_except:
|
|
||||||
body_params = []
|
|
||||||
rest = []
|
|
||||||
for param in params:
|
|
||||||
if param.name not in as_body_except:
|
|
||||||
body_params.append(param)
|
|
||||||
else:
|
|
||||||
rest.append(param)
|
|
||||||
return [body_params, *rest]
|
|
||||||
|
|
||||||
if as_body:
|
|
||||||
return [params]
|
|
||||||
|
|
||||||
return params
|
|
||||||
|
|
||||||
def api(
|
def api(
|
||||||
self,
|
self,
|
||||||
route: str,
|
route: str,
|
||||||
|
|
|
@ -25,7 +25,7 @@ from yunohost.interface.base import (
|
||||||
merge_dicts,
|
merge_dicts,
|
||||||
get_params_doc,
|
get_params_doc,
|
||||||
override_function,
|
override_function,
|
||||||
validate_pattern
|
validate_pattern,
|
||||||
)
|
)
|
||||||
from yunohost.utils.error import YunohostValidationError
|
from yunohost.utils.error import YunohostValidationError
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ def print_as_yaml(data: Any):
|
||||||
rprint(Syntax(data, "yaml", background_color="default"))
|
rprint(Syntax(data, "yaml", background_color="default"))
|
||||||
|
|
||||||
|
|
||||||
def pattern_validator(pattern: str, name: str):
|
def pattern_validator(pattern: str, name: Optional[str]):
|
||||||
def inner_validator(ctx: typer.Context, param_: typer.CallbackParam, value: str):
|
def inner_validator(ctx: typer.Context, param_: typer.CallbackParam, value: str):
|
||||||
if ctx.resilient_parsing:
|
if ctx.resilient_parsing:
|
||||||
return
|
return
|
||||||
|
@ -72,16 +72,21 @@ class Interface(BaseInterface):
|
||||||
rprint(content)
|
rprint(content)
|
||||||
else:
|
else:
|
||||||
from moulinette import Moulinette
|
from moulinette import Moulinette
|
||||||
|
|
||||||
Moulinette.display(content)
|
Moulinette.display(content)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def prompt(ask: str, is_password=False, confirm=False, **kwargs):
|
def prompt(ask: str, is_password=False, confirm=False, **kwargs):
|
||||||
if os.environ.get("INTERFACE") == "cli":
|
if os.environ.get("INTERFACE") == "cli":
|
||||||
return typer.prompt(ask, hide_input=is_password, confirmation_prompt=confirm)
|
return typer.prompt(
|
||||||
|
ask, hide_input=is_password, confirmation_prompt=confirm
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
from moulinette import Moulinette
|
from moulinette import Moulinette
|
||||||
return Moulinette.prompt(ask, is_password=is_password, confirm=confirm, **kwargs)
|
|
||||||
|
|
||||||
|
return Moulinette.prompt(
|
||||||
|
ask, is_password=is_password, confirm=confirm, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
def cli(self, command_def: str, **extra_data):
|
def cli(self, command_def: str, **extra_data):
|
||||||
def decorator(func: Callable):
|
def decorator(func: Callable):
|
||||||
|
|
Loading…
Add table
Reference in a new issue