mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
mypy: Add support for version 2.1
Tests: - Unit tests pass. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
d2a959a277
commit
f2e898090c
@ -45,10 +45,10 @@ box_name = 'FreedomBox'
|
|||||||
# Other globals
|
# Other globals
|
||||||
develop = False
|
develop = False
|
||||||
|
|
||||||
config_files = []
|
config_files: list[str] = []
|
||||||
|
|
||||||
|
|
||||||
def expand_to_dot_d_paths(file_paths):
|
def expand_to_dot_d_paths(file_paths: list[str]) -> list[str]:
|
||||||
"""Expand a list of file paths to include file.d/* also."""
|
"""Expand a list of file paths to include file.d/* also."""
|
||||||
final_list = []
|
final_list = []
|
||||||
for file_path in file_paths:
|
for file_path in file_paths:
|
||||||
@ -65,7 +65,7 @@ def expand_to_dot_d_paths(file_paths):
|
|||||||
return final_list
|
return final_list
|
||||||
|
|
||||||
|
|
||||||
def get_develop_config_path():
|
def get_develop_config_path() -> str:
|
||||||
"""Return config path of current source folder for development mode."""
|
"""Return config path of current source folder for development mode."""
|
||||||
root_directory = os.path.dirname(os.path.realpath(__file__))
|
root_directory = os.path.dirname(os.path.realpath(__file__))
|
||||||
root_directory = os.path.realpath(root_directory)
|
root_directory = os.path.realpath(root_directory)
|
||||||
@ -73,7 +73,7 @@ def get_develop_config_path():
|
|||||||
return config_path
|
return config_path
|
||||||
|
|
||||||
|
|
||||||
def get_config_paths():
|
def get_config_paths() -> list[str]:
|
||||||
"""Get default config paths."""
|
"""Get default config paths."""
|
||||||
return [
|
return [
|
||||||
'/usr/share/freedombox/freedombox.config',
|
'/usr/share/freedombox/freedombox.config',
|
||||||
@ -82,14 +82,14 @@ def get_config_paths():
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def read():
|
def read() -> None:
|
||||||
"""Read all configuration files."""
|
"""Read all configuration files."""
|
||||||
config_paths = get_config_paths()
|
config_paths = get_config_paths()
|
||||||
for config_path in expand_to_dot_d_paths(config_paths):
|
for config_path in expand_to_dot_d_paths(config_paths):
|
||||||
read_file(config_path)
|
read_file(config_path)
|
||||||
|
|
||||||
|
|
||||||
def read_file(config_path):
|
def read_file(config_path: str):
|
||||||
"""Read and merge into defaults a single configuration file."""
|
"""Read and merge into defaults a single configuration file."""
|
||||||
if not os.path.isfile(config_path): # Does not throw exceptions
|
if not os.path.isfile(config_path): # Does not throw exceptions
|
||||||
# Ignore missing configuration files
|
# Ignore missing configuration files
|
||||||
@ -101,9 +101,9 @@ def read_file(config_path):
|
|||||||
parser = configparser.ConfigParser(
|
parser = configparser.ConfigParser(
|
||||||
defaults={
|
defaults={
|
||||||
'parent_dir':
|
'parent_dir':
|
||||||
pathlib.Path(config_path).parent.resolve(),
|
str(pathlib.Path(config_path).parent.resolve()),
|
||||||
'parent_parent_dir':
|
'parent_parent_dir':
|
||||||
pathlib.Path(config_path).parent.parent.resolve(),
|
str(pathlib.Path(config_path).parent.parent.resolve()),
|
||||||
})
|
})
|
||||||
parser.read(config_path) # Ignores all read errors
|
parser.read(config_path) # Ignores all read errors
|
||||||
|
|
||||||
@ -123,6 +123,7 @@ def read_file(config_path):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for section, name, datatype in config_items:
|
for section, name, datatype in config_items:
|
||||||
|
value: int | str | bool
|
||||||
try:
|
try:
|
||||||
value = parser.get(section, name)
|
value = parser.get(section, name)
|
||||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
except (configparser.NoSectionError, configparser.NoOptionError):
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import logging
|
|||||||
import pathlib
|
import pathlib
|
||||||
import threading
|
import threading
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
@ -40,7 +41,7 @@ _description = [
|
|||||||
|
|
||||||
logger = logging.Logger(__name__)
|
logger = logging.Logger(__name__)
|
||||||
|
|
||||||
current_results = {}
|
current_results: dict[str, Any] = {}
|
||||||
results_lock = threading.Lock()
|
results_lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth.utils import import_from_gi
|
from plinth.utils import import_from_gi
|
||||||
@ -40,7 +41,7 @@ _ERRORS: dict[str, str] = {
|
|||||||
'Failed': 'org.freedesktop.UDisks2.Error.Failed',
|
'Failed': 'org.freedesktop.UDisks2.Error.Failed',
|
||||||
}
|
}
|
||||||
|
|
||||||
_jobs = {}
|
_jobs: dict[str, Any] = {}
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user