From 0610a1808b12b218651cf9e1b7faf3431882d568 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 2 Sep 2022 00:20:44 +0200 Subject: [PATCH] =?UTF-8?q?manifestv2:=20attempt=20to=20fix=20mypy=20error?= =?UTF-8?q?s=20=C3=A9=5F=C3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/resources.py | 14 ++++++++++++-- src/utils/system.py | 5 +++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/utils/resources.py b/src/utils/resources.py index f93543cb2..9edad2970 100644 --- a/src/utils/resources.py +++ b/src/utils/resources.py @@ -22,7 +22,8 @@ import os import copy import shutil import random -from typing import Dict, Any +from typing import Optional, Dict, List, Union, Any, Mapping, Callable, no_type_check + from moulinette.utils.process import check_output from moulinette.utils.log import getActionLogger @@ -123,6 +124,8 @@ class AppResourceManager: class AppResource: + default_properties: Dict[str, Any] = None + def __init__(self, properties: Dict[str, Any], app: str, manager=None): self.app = app @@ -199,7 +202,7 @@ class PermissionsResource(AppResource): default_properties = { } - default_perm_properties = { + default_perm_properties: Dict[str, Any] = { "url": None, "additional_urls": [], "auth_header": True, @@ -208,6 +211,8 @@ class PermissionsResource(AppResource): "protected": False, } + permissions: Dict[str, Dict[str, Any]] = {} + def __init__(self, properties: Dict[str, Any], *args, **kwargs): # FIXME : if url != None, we should check that there's indeed a domain/path defined ? ie that app is a webapp @@ -362,6 +367,7 @@ class SystemuserAppResource(AppResource): # fi # +@no_type_check class InstalldirAppResource(AppResource): """ is_provisioned -> setting install_dir exists + /dir/ exists @@ -427,6 +433,7 @@ class InstalldirAppResource(AppResource): # FIXME : in fact we should delete settings to be consistent +@no_type_check class DatadirAppResource(AppResource): """ is_provisioned -> setting data_dir exists + /dir/ exists @@ -510,6 +517,7 @@ class DatadirAppResource(AppResource): # return # +@no_type_check class AptDependenciesAppResource(AppResource): """ is_provisioned -> package __APP__-ynh-deps exists (ideally should check the Depends: but hmgn) @@ -583,6 +591,8 @@ class PortsResource(AppResource): "fixed": False, # FIXME: implement logic. Corresponding to wether or not the port is "fixed" or any random port is ok } + ports: Dict[str, Dict[str, Any]] + def __init__(self, properties: Dict[str, Any], *args, **kwargs): if "main" not in properties: diff --git a/src/utils/system.py b/src/utils/system.py index 2aaf0fa35..fe6d2d01b 100644 --- a/src/utils/system.py +++ b/src/utils/system.py @@ -21,6 +21,7 @@ import re import os import logging +from typing import Union from moulinette.utils.process import check_output from yunohost.utils.error import YunohostError @@ -74,11 +75,11 @@ def human_to_binary(size: str) -> int: raise YunohostError(f"Invalid size suffix '{suffix}', expected one of {symbols}") try: - size = float(size) + size_ = float(size) except Exception: raise YunohostError(f"Failed to convert size {size} to float") - return size * factor[suffix] + return int(size_ * factor[suffix]) def binary_to_human(n: int) -> str: