mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
- Try to mark class variables in component classes. - Leave typing hints generic, such as 'list' and 'dict' where content is usually not filled, too complex, or context is unimportant. - backups: Handle failure for tarfile extraction so that methods are not called on potentially None valued variables. - backups: Prevent potentially passing a keyword argument twice. - dynamicdns: Deal properly with outcome of urlparsing. - ejabberd: Deal with failed regex match - email: Fix a mypy compliant when iterating a filtered list. - tor: Don't reuse variables for different typed values. - tor: Don't reuse variables for different typed values. - operation: Return None explicitly. - operation: Ensure that keyword argument is not repeated. Tests: - Where only typing hints were modified and no syntax error came up, additional testing was not done. - `mypy --ignore-missing-imports .` run successfully. - Generate developer documentation. - Service runs without errors upon start up. - backups: Listing and restoring specific apps from a backup works. - backups: Mounting a remote backup repository works. - NOT TESTED: dynamicdns: Migrating from old style configuration works. - ejabberd: Verify that setting coturn configuration works. - email: Test that showing configuration from postfix works. - tor: Orport value is properly shown. - transmission: Configuration values are properly set. - users: Running unit tests as root works. - operation: Operation status messages are show properly during app install. - ./setup.py install runs Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
Configuration helper for Transmission daemon.
|
|
"""
|
|
|
|
import json
|
|
import pathlib
|
|
from typing import Union
|
|
|
|
from plinth import action_utils
|
|
from plinth.actions import privileged
|
|
|
|
_transmission_config = pathlib.Path('/etc/transmission-daemon/settings.json')
|
|
|
|
|
|
@privileged
|
|
def get_configuration() -> dict[str, str]:
|
|
"""Return the current configuration in JSON format."""
|
|
return json.loads(_transmission_config.read_text(encoding='utf-8'))
|
|
|
|
|
|
@privileged
|
|
def merge_configuration(configuration: dict[str, Union[str, bool]]):
|
|
"""Merge given JSON configuration with existing configuration."""
|
|
current_configuration_bytes = _transmission_config.read_bytes()
|
|
current_configuration = json.loads(current_configuration_bytes)
|
|
|
|
new_configuration = current_configuration
|
|
new_configuration.update(configuration)
|
|
new_configuration_bytes = json.dumps(new_configuration, indent=4,
|
|
sort_keys=True)
|
|
|
|
_transmission_config.write_text(new_configuration_bytes, encoding='utf-8')
|
|
action_utils.service_reload('transmission-daemon')
|