Sunil Mohan Adapa 38ece87c6c
*: Utilize newer 3.10 syntax for type hints
Tests:

- mypy does not show any errors.

- Installing ejabberd app works. Privileged actions run fine.

- Unit tests work.

- No additional testing was done as type annotations don't have any effect at
runtime.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-09-25 20:03:34 -04:00

34 lines
1.1 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Configuration helper for Transmission daemon.
"""
import json
import pathlib
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, 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')