From cc20b36550dbe95985bb57e6afd0181604f48a4e Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Thu, 14 Oct 2021 11:18:02 +0000 Subject: [PATCH] [CI] Format code --- src/yunohost/app.py | 4 +- src/yunohost/utils/config.py | 78 ++++++++++++++++++++++-------------- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 8d441c00d..6cd8eebf5 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -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 diff --git a/src/yunohost/utils/config.py b/src/yunohost/utils/config.py index c3e08c5c2..d29384bfe 100644 --- a/src/yunohost/utils/config.py +++ b/src/yunohost/utils/config.py @@ -200,9 +200,13 @@ class ConfigPanel: List available config panel """ try: - entities = [re.match("^" + cls.save_path_tpl.format(entity="(?p)") + "$", 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)") + "$", 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.