Merge pull request #1360 from YunoHost/ci-format-dev

[CI] Format code
This commit is contained in:
Alexandre Aubin 2021-10-14 14:24:23 +02:00 committed by GitHub
commit 026f12dbb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 30 deletions

View file

@ -1634,7 +1634,9 @@ class AppConfigPanel(ConfigPanel):
from yunohost.hook import hook_exec from yunohost.hook import hook_exec
# Add default config script if needed # 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): if not os.path.exists(config_script):
logger.debug("Adding a default config script") logger.debug("Adding a default config script")
default_script = """#!/bin/bash default_script = """#!/bin/bash

View file

@ -200,9 +200,13 @@ class ConfigPanel:
List available config panel List available config panel
""" """
try: try:
entities = [re.match("^" + cls.save_path_tpl.format(entity="(?p<entity>)") + "$", f).group('entity') entities = [
for f in glob.glob(cls.save_path_tpl.format(entity="*")) re.match(
if os.path.isfile(f)] "^" + 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: except FileNotFoundError:
entities = [] entities = []
return entities return entities
@ -220,14 +224,21 @@ class ConfigPanel:
self.new_values = {} self.new_values = {}
if self.save_path and not creation and not os.path.exists(self.save_path): 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): 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 # Search for hooks in the config panel
self.hooks = {func: getattr(self, func) self.hooks = {
for func in dir(self) func: getattr(self, func)
if callable(getattr(self, func)) and re.match("^(validate|post_ask)__", func)} for func in dir(self)
if callable(getattr(self, func))
and re.match("^(validate|post_ask)__", func)
}
def get(self, key="", mode="classic"): def get(self, key="", mode="classic"):
self.filter_key = key or "" self.filter_key = key or ""
@ -555,7 +566,7 @@ class ConfigPanel:
section["options"], section["options"],
prefilled_answers=self.args, prefilled_answers=self.args,
current_values=self.values, current_values=self.values,
hooks=self.hooks hooks=self.hooks,
) )
self.new_values.update( self.new_values.update(
{ {
@ -575,7 +586,7 @@ class ConfigPanel:
} }
@property @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} return {**self.values, **self.new_values}
def __getattr__(self, name): def __getattr__(self, name):
@ -660,9 +671,12 @@ class Question(object):
hide_user_input_in_prompt = False hide_user_input_in_prompt = False
pattern: Optional[Dict] = None pattern: Optional[Dict] = None
def __init__(self, question: Dict[str, Any], def __init__(
context: Mapping[str, Any] = {}, self,
hooks: Dict[str, Callable] = {}): question: Dict[str, Any],
context: Mapping[str, Any] = {},
hooks: Dict[str, Callable] = {},
):
self.name = question["name"] self.name = question["name"]
self.context = context self.context = context
self.hooks = hooks self.hooks = hooks
@ -927,9 +941,9 @@ class PasswordQuestion(Question):
default_value = "" default_value = ""
forbidden_chars = "{}" forbidden_chars = "{}"
def __init__(self, question, def __init__(
context: Mapping[str, Any] = {}, self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
hooks: Dict[str, Callable] = {}): ):
super().__init__(question, context, hooks) super().__init__(question, context, hooks)
self.redact = True self.redact = True
if self.default is not None: if self.default is not None:
@ -1048,8 +1062,9 @@ class BooleanQuestion(Question):
choices="yes/no", choices="yes/no",
) )
def __init__(self, question, context: Mapping[str, Any] = {}, def __init__(
hooks: Dict[str, Callable] = {}): self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
):
super().__init__(question, context, hooks) super().__init__(question, context, hooks)
self.yes = question.get("yes", 1) self.yes = question.get("yes", 1)
self.no = question.get("no", 0) self.no = question.get("no", 0)
@ -1070,8 +1085,9 @@ class BooleanQuestion(Question):
class DomainQuestion(Question): class DomainQuestion(Question):
argument_type = "domain" argument_type = "domain"
def __init__(self, question, context: Mapping[str, Any] = {}, def __init__(
hooks: Dict[str, Callable] = {}): self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
):
from yunohost.domain import domain_list, _get_maindomain from yunohost.domain import domain_list, _get_maindomain
super().__init__(question, context, hooks) super().__init__(question, context, hooks)
@ -1097,8 +1113,9 @@ class DomainQuestion(Question):
class UserQuestion(Question): class UserQuestion(Question):
argument_type = "user" argument_type = "user"
def __init__(self, question, context: Mapping[str, Any] = {}, def __init__(
hooks: Dict[str, Callable] = {}): self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
):
from yunohost.user import user_list, user_info from yunohost.user import user_list, user_info
from yunohost.domain import _get_maindomain from yunohost.domain import _get_maindomain
@ -1124,8 +1141,9 @@ class NumberQuestion(Question):
argument_type = "number" argument_type = "number"
default_value = None default_value = None
def __init__(self, question, context: Mapping[str, Any] = {}, def __init__(
hooks: Dict[str, Callable] = {}): self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
):
super().__init__(question, context, hooks) super().__init__(question, context, hooks)
self.min = question.get("min", None) self.min = question.get("min", None)
self.max = question.get("max", None) self.max = question.get("max", None)
@ -1177,8 +1195,9 @@ class DisplayTextQuestion(Question):
argument_type = "display_text" argument_type = "display_text"
readonly = True readonly = True
def __init__(self, question, context: Mapping[str, Any] = {}, def __init__(
hooks: Dict[str, Callable] = {}): self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
):
super().__init__(question, context, hooks) super().__init__(question, context, hooks)
self.optional = True self.optional = True
@ -1213,8 +1232,9 @@ class FileQuestion(Question):
if os.path.exists(upload_dir): if os.path.exists(upload_dir):
shutil.rmtree(upload_dir) shutil.rmtree(upload_dir)
def __init__(self, question, context: Mapping[str, Any] = {}, def __init__(
hooks: Dict[str, Callable] = {}): self, question, context: Mapping[str, Any] = {}, hooks: Dict[str, Callable] = {}
):
super().__init__(question, context, hooks) super().__init__(question, context, hooks)
self.accept = question.get("accept", "") self.accept = question.get("accept", "")
@ -1288,7 +1308,7 @@ def ask_questions_and_parse_answers(
raw_questions: Dict, raw_questions: Dict,
prefilled_answers: Union[str, Mapping[str, Any]] = {}, prefilled_answers: Union[str, Mapping[str, Any]] = {},
current_values: Union[str, Mapping[str, Any]] = {}, current_values: Union[str, Mapping[str, Any]] = {},
hooks: Dict[str, Callable[[], None]] = {} hooks: Dict[str, Callable[[], None]] = {},
) -> List[Question]: ) -> List[Question]:
"""Parse arguments store in either manifest.json or actions.json or from a """Parse arguments store in either manifest.json or actions.json or from a
config panel against the user answers when they are present. config panel against the user answers when they are present.