From 9bf2b0b54673ca677f7cb6527b68dd6ba6b437aa Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Fri, 6 Jan 2023 06:00:05 +0000 Subject: [PATCH] [CI] Format code with Black --- src/app.py | 5 +++-- src/app_catalog.py | 17 +++++++++++++---- src/backup.py | 7 ++++--- src/firewall.py | 24 ++++++++++++++++++++---- src/tests/test_app_config.py | 2 +- src/user.py | 4 +++- src/utils/resources.py | 27 +++++++++++++++++++-------- 7 files changed, 63 insertions(+), 23 deletions(-) diff --git a/src/app.py b/src/app.py index 30e3a7be8..28323f4a9 100644 --- a/src/app.py +++ b/src/app.py @@ -862,7 +862,9 @@ def app_manifest(app, with_screenshot=False): if entry.is_file() and ext in ("png", "jpg", "jpeg", "webp", "gif"): with open(entry.path, "rb") as img_file: data = base64.b64encode(img_file.read()).decode("utf-8") - manifest["screenshot"] = f"data:image/{ext};charset=utf-8;base64,{data}" + manifest[ + "screenshot" + ] = f"data:image/{ext};charset=utf-8;base64,{data}" break shutil.rmtree(extracted_app_folder) @@ -2932,7 +2934,6 @@ def _notification_is_dismissed(name, settings): def _filter_and_hydrate_notifications(notifications, current_version=None, data={}): - def is_version_more_recent_than_current_version(name): # Boring code to handle the fact that "0.1 < 9999~ynh1" is False diff --git a/src/app_catalog.py b/src/app_catalog.py index 79d02e8f1..5d4378544 100644 --- a/src/app_catalog.py +++ b/src/app_catalog.py @@ -226,17 +226,26 @@ def _update_apps_catalog(): logos_to_download.append(logo_hash) if len(logos_to_download) > 20: - logger.info(f"(Will fetch {len(logos_to_download)} logos, this may take a couple minutes)") + logger.info( + f"(Will fetch {len(logos_to_download)} logos, this may take a couple minutes)" + ) import requests from multiprocessing.pool import ThreadPool def fetch_logo(logo_hash): try: - r = requests.get(f"{apps_catalog['url']}/v{APPS_CATALOG_API_VERSION}/logos/{logo_hash}.png", timeout=10) - assert r.status_code == 200, f"Got status code {r.status_code}, expected 200" + r = requests.get( + f"{apps_catalog['url']}/v{APPS_CATALOG_API_VERSION}/logos/{logo_hash}.png", + timeout=10, + ) + assert ( + r.status_code == 200 + ), f"Got status code {r.status_code}, expected 200" if hashlib.sha256(r.content).hexdigest() != logo_hash: - raise Exception(f"Found inconsistent hash while downloading logo {logo_hash}") + raise Exception( + f"Found inconsistent hash while downloading logo {logo_hash}" + ) open(f"{APPS_CATALOG_LOGOS}/{logo_hash}.png", "wb").write(r.content) return True except Exception as e: diff --git a/src/backup.py b/src/backup.py index 21d499eaf..c3e47bddc 100644 --- a/src/backup.py +++ b/src/backup.py @@ -1518,9 +1518,10 @@ class RestoreManager: if manifest["packaging_format"] >= 2: from yunohost.utils.resources import AppResourceManager - AppResourceManager( - app_instance_name, wanted=manifest, current={} - ).apply(rollback_and_raise_exception_if_failure=True, operation_logger=operation_logger) + AppResourceManager(app_instance_name, wanted=manifest, current={}).apply( + rollback_and_raise_exception_if_failure=True, + operation_logger=operation_logger, + ) # Execute the app install script restore_failed = True diff --git a/src/firewall.py b/src/firewall.py index eb3c9b009..6cf68f1f7 100644 --- a/src/firewall.py +++ b/src/firewall.py @@ -32,7 +32,13 @@ logger = getActionLogger("yunohost.firewall") def firewall_allow( - protocol, port, ipv4_only=False, ipv6_only=False, no_upnp=False, no_reload=False, reload_only_if_change=False + protocol, + port, + ipv4_only=False, + ipv6_only=False, + no_upnp=False, + no_reload=False, + reload_only_if_change=False, ): """ Allow connections on a port @@ -81,7 +87,9 @@ def firewall_allow( else: ipv = "IPv%s" % i[3] if not reload_only_if_change: - logger.warning(m18n.n("port_already_opened", port=port, ip_version=ipv)) + logger.warning( + m18n.n("port_already_opened", port=port, ip_version=ipv) + ) # Add port forwarding with UPnP if not no_upnp and port not in firewall["uPnP"][p]: firewall["uPnP"][p].append(port) @@ -98,7 +106,13 @@ def firewall_allow( def firewall_disallow( - protocol, port, ipv4_only=False, ipv6_only=False, upnp_only=False, no_reload=False, reload_only_if_change=False + protocol, + port, + ipv4_only=False, + ipv6_only=False, + upnp_only=False, + no_reload=False, + reload_only_if_change=False, ): """ Disallow connections on a port @@ -154,7 +168,9 @@ def firewall_disallow( else: ipv = "IPv%s" % i[3] if not reload_only_if_change: - logger.warning(m18n.n("port_already_closed", port=port, ip_version=ipv)) + logger.warning( + m18n.n("port_already_closed", port=port, ip_version=ipv) + ) # Remove port forwarding with UPnP if upnp and port in firewall["uPnP"][p]: firewall["uPnP"][p].remove(port) diff --git a/src/tests/test_app_config.py b/src/tests/test_app_config.py index 93df08c98..b524a7a51 100644 --- a/src/tests/test_app_config.py +++ b/src/tests/test_app_config.py @@ -173,7 +173,7 @@ def test_app_config_bind_on_file(config_app): assert app_setting(config_app, "arg5") == "Foo Bar" -#def test_app_config_custom_get(config_app): +# def test_app_config_custom_get(config_app): # # assert app_setting(config_app, "arg9") is None # assert ( diff --git a/src/user.py b/src/user.py index 8cf79c75f..deaebba5b 100644 --- a/src/user.py +++ b/src/user.py @@ -1246,7 +1246,9 @@ def user_group_update( new_attr_dict["objectClass"] = group["objectClass"] + ["mailGroup"] if not new_attr_dict["mail"] and "mailGroup" in group["objectClass"]: new_attr_dict["objectClass"] = [ - c for c in group["objectClass"] if c != "mailGroup" and c != "mailAccount" + c + for c in group["objectClass"] + if c != "mailGroup" and c != "mailAccount" ] if new_attr_dict: diff --git a/src/utils/resources.py b/src/utils/resources.py index f0e099eb1..7b500ad3f 100644 --- a/src/utils/resources.py +++ b/src/utils/resources.py @@ -36,7 +36,6 @@ logger = getActionLogger("yunohost.app_resources") class AppResourceManager: - def __init__(self, app: str, current: Dict, wanted: Dict): self.app = app @@ -48,7 +47,9 @@ class AppResourceManager: if "resources" not in self.wanted: self.wanted["resources"] = {} - def apply(self, rollback_and_raise_exception_if_failure, operation_logger=None, **context): + def apply( + self, rollback_and_raise_exception_if_failure, operation_logger=None, **context + ): todos = list(self.compute_todos()) completed = [] @@ -104,9 +105,13 @@ class AppResourceManager: if exception: if rollback_and_raise_exception_if_failure: - logger.error(m18n.n("app_resource_failed", app=self.app, error=exception)) + logger.error( + m18n.n("app_resource_failed", app=self.app, error=exception) + ) if operation_logger: - failure_message_with_debug_instructions = operation_logger.error(str(exception)) + failure_message_with_debug_instructions = operation_logger.error( + str(exception) + ) raise YunohostError( failure_message_with_debug_instructions, raw_msg=True ) @@ -859,7 +864,9 @@ class PortsResource(AppResource): if infos["fixed"]: if self._port_is_used(port_value): - raise YunohostValidationError(f"Port {port_value} is already used by another process or app.") + raise YunohostValidationError( + f"Port {port_value} is already used by another process or app." + ) else: while self._port_is_used(port_value): port_value += 1 @@ -869,7 +876,9 @@ class PortsResource(AppResource): if infos["exposed"]: firewall_allow(infos["exposed"], port_value, reload_only_if_change=True) else: - firewall_disallow(infos["exposed"], port_value, reload_only_if_change=True) + firewall_disallow( + infos["exposed"], port_value, reload_only_if_change=True + ) def deprovision(self, context: Dict = {}): @@ -880,7 +889,9 @@ class PortsResource(AppResource): value = self.get_setting(setting_name) self.delete_setting(setting_name) if value and str(value).strip(): - firewall_disallow(infos["exposed"], int(value), reload_only_if_change=True) + firewall_disallow( + infos["exposed"], int(value), reload_only_if_change=True + ) class DatabaseAppResource(AppResource): @@ -934,7 +945,7 @@ class DatabaseAppResource(AppResource): ]: raise YunohostError( "Specifying the type of db ('mysql' or 'postgresql') is mandatory for db resources", - raw_msg=True + raw_msg=True, ) # Hack so that people can write type = "mysql/postgresql" in toml but it's loaded as dbtype