mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
commit
026f12dbb7
2 changed files with 52 additions and 30 deletions
|
@ -1634,7 +1634,9 @@ class AppConfigPanel(ConfigPanel):
|
|||
from yunohost.hook import hook_exec
|
||||
|
||||
# Add default config script if needed
|
||||
config_script = os.path.join(APPS_SETTING_PATH, self.entity, "scripts", "config")
|
||||
config_script = os.path.join(
|
||||
APPS_SETTING_PATH, self.entity, "scripts", "config"
|
||||
)
|
||||
if not os.path.exists(config_script):
|
||||
logger.debug("Adding a default config script")
|
||||
default_script = """#!/bin/bash
|
||||
|
|
|
@ -200,9 +200,13 @@ class ConfigPanel:
|
|||
List available config panel
|
||||
"""
|
||||
try:
|
||||
entities = [re.match("^" + cls.save_path_tpl.format(entity="(?p<entity>)") + "$", f).group('entity')
|
||||
for f in glob.glob(cls.save_path_tpl.format(entity="*"))
|
||||
if os.path.isfile(f)]
|
||||
entities = [
|
||||
re.match(
|
||||
"^" + cls.save_path_tpl.format(entity="(?p<entity>)") + "$", f
|
||||
).group("entity")
|
||||
for f in glob.glob(cls.save_path_tpl.format(entity="*"))
|
||||
if os.path.isfile(f)
|
||||
]
|
||||
except FileNotFoundError:
|
||||
entities = []
|
||||
return entities
|
||||
|
@ -220,14 +224,21 @@ class ConfigPanel:
|
|||
self.new_values = {}
|
||||
|
||||
if self.save_path and not creation and not os.path.exists(self.save_path):
|
||||
raise YunohostError(f"{self.entity_type}_unknown", **{self.entity_type:entity})
|
||||
raise YunohostError(
|
||||
f"{self.entity_type}_unknown", **{self.entity_type: entity}
|
||||
)
|
||||
if self.save_path and creation and os.path.exists(self.save_path):
|
||||
raise YunohostError(f"{self.entity_type}_exists", **{self.entity_type:entity})
|
||||
raise YunohostError(
|
||||
f"{self.entity_type}_exists", **{self.entity_type: entity}
|
||||
)
|
||||
|
||||
# Search for hooks in the config panel
|
||||
self.hooks = {func: getattr(self, func)
|
||||
for func in dir(self)
|
||||
if callable(getattr(self, func)) and re.match("^(validate|post_ask)__", func)}
|
||||
self.hooks = {
|
||||
func: getattr(self, func)
|
||||
for func in dir(self)
|
||||
if callable(getattr(self, func))
|
||||
and re.match("^(validate|post_ask)__", func)
|
||||
}
|
||||
|
||||
def get(self, key="", mode="classic"):
|
||||
self.filter_key = key or ""
|
||||
|
@ -555,7 +566,7 @@ class ConfigPanel:
|
|||
section["options"],
|
||||
prefilled_answers=self.args,
|
||||
current_values=self.values,
|
||||
hooks=self.hooks
|
||||
hooks=self.hooks,
|
||||
)
|
||||
self.new_values.update(
|
||||
{
|
||||
|
@ -575,7 +586,7 @@ class ConfigPanel:
|
|||
}
|
||||
|
||||
@property
|
||||
def future_values(self): # TODO put this in ConfigPanel ?
|
||||
def future_values(self): # TODO put this in ConfigPanel ?
|
||||
return {**self.values, **self.new_values}
|
||||
|
||||
def __getattr__(self, name):
|
||||
|
@ -660,9 +671,12 @@ class Question(object):
|
|||
hide_user_input_in_prompt = False
|
||||
pattern: Optional[Dict] = None
|
||||
|
||||
def __init__(self, question: Dict[str, Any],
|
||||
context: Mapping[str, Any] = {},
|
||||
hooks: Dict[str, Callable] = {}):
|
||||
def __init__(
|
||||
self,
|
||||
question: Dict[str, Any],
|
||||
context: Mapping[str, Any] = {},
|
||||
hooks: Dict[str, Callable] = {},
|
||||
):
|
||||
self.name = question["name"]
|
||||
self.context = context
|
||||
self.hooks = hooks
|
||||
|
@ -927,9 +941,9 @@ class PasswordQuestion(Question):
|
|||
default_value = ""
|
||||
forbidden_chars = "{}"
|
||||
|
||||
def __init__(self, question,
|
||||
context: Mapping[str, Any] = {},
|
||||
hooks: Dict[str, Callable] = {}):
|
||||
def __init__(
|
||||
self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
|
||||
):
|
||||
super().__init__(question, context, hooks)
|
||||
self.redact = True
|
||||
if self.default is not None:
|
||||
|
@ -1048,8 +1062,9 @@ class BooleanQuestion(Question):
|
|||
choices="yes/no",
|
||||
)
|
||||
|
||||
def __init__(self, question, context: Mapping[str, Any] = {},
|
||||
hooks: Dict[str, Callable] = {}):
|
||||
def __init__(
|
||||
self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
|
||||
):
|
||||
super().__init__(question, context, hooks)
|
||||
self.yes = question.get("yes", 1)
|
||||
self.no = question.get("no", 0)
|
||||
|
@ -1070,8 +1085,9 @@ class BooleanQuestion(Question):
|
|||
class DomainQuestion(Question):
|
||||
argument_type = "domain"
|
||||
|
||||
def __init__(self, question, context: Mapping[str, Any] = {},
|
||||
hooks: Dict[str, Callable] = {}):
|
||||
def __init__(
|
||||
self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
|
||||
):
|
||||
from yunohost.domain import domain_list, _get_maindomain
|
||||
|
||||
super().__init__(question, context, hooks)
|
||||
|
@ -1097,8 +1113,9 @@ class DomainQuestion(Question):
|
|||
class UserQuestion(Question):
|
||||
argument_type = "user"
|
||||
|
||||
def __init__(self, question, context: Mapping[str, Any] = {},
|
||||
hooks: Dict[str, Callable] = {}):
|
||||
def __init__(
|
||||
self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
|
||||
):
|
||||
from yunohost.user import user_list, user_info
|
||||
from yunohost.domain import _get_maindomain
|
||||
|
||||
|
@ -1124,8 +1141,9 @@ class NumberQuestion(Question):
|
|||
argument_type = "number"
|
||||
default_value = None
|
||||
|
||||
def __init__(self, question, context: Mapping[str, Any] = {},
|
||||
hooks: Dict[str, Callable] = {}):
|
||||
def __init__(
|
||||
self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
|
||||
):
|
||||
super().__init__(question, context, hooks)
|
||||
self.min = question.get("min", None)
|
||||
self.max = question.get("max", None)
|
||||
|
@ -1177,8 +1195,9 @@ class DisplayTextQuestion(Question):
|
|||
argument_type = "display_text"
|
||||
readonly = True
|
||||
|
||||
def __init__(self, question, context: Mapping[str, Any] = {},
|
||||
hooks: Dict[str, Callable] = {}):
|
||||
def __init__(
|
||||
self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
|
||||
):
|
||||
super().__init__(question, context, hooks)
|
||||
|
||||
self.optional = True
|
||||
|
@ -1213,8 +1232,9 @@ class FileQuestion(Question):
|
|||
if os.path.exists(upload_dir):
|
||||
shutil.rmtree(upload_dir)
|
||||
|
||||
def __init__(self, question, context: Mapping[str, Any] = {},
|
||||
hooks: Dict[str, Callable] = {}):
|
||||
def __init__(
|
||||
self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
|
||||
):
|
||||
super().__init__(question, context, hooks)
|
||||
self.accept = question.get("accept", "")
|
||||
|
||||
|
@ -1288,7 +1308,7 @@ def ask_questions_and_parse_answers(
|
|||
raw_questions: Dict,
|
||||
prefilled_answers: Union[str, Mapping[str, Any]] = {},
|
||||
current_values: Union[str, Mapping[str, Any]] = {},
|
||||
hooks: Dict[str, Callable[[], None]] = {}
|
||||
hooks: Dict[str, Callable[[], None]] = {},
|
||||
) -> List[Question]:
|
||||
"""Parse arguments store in either manifest.json or actions.json or from a
|
||||
config panel against the user answers when they are present.
|
||||
|
|
Loading…
Add table
Reference in a new issue