Sunil Mohan Adapa 7f608cd570
*: Collect output for all privileged sub-processes
- Now that we have a mechanism for properly collecting, transmitting, and display
the stdout and stderr. There is no reason not to collect all of the stdin and
stderr.

- Also, the stdin/stderr=subprocess.PIPE is redundant and prevents the output
from getting collected for debugging. So, remove it.

Tests:

- Ran functional tests on backups, calibre, ejabberd, email, gitweb, ikiwiki,
infinoted, kiwix, mediawiki, mumble, nextcloud,, openvpn, samba, wireguard,
zoph. 2-3 issues were found but did not seem like new errors.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2025-09-29 16:58:57 +03:00

53 lines
1.4 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Configuration helper for calibre."""
import pathlib
import shutil
from plinth import action_utils
from plinth.actions import privileged
from plinth.modules import calibre
LIBRARIES_PATH = pathlib.Path('/var/lib/calibre-server-freedombox/libraries')
@privileged
def list_libraries() -> list[str]:
"""Return the list of libraries setup."""
libraries = []
for library in LIBRARIES_PATH.glob('*/metadata.db'):
libraries.append(str(library.parent.name))
return libraries
@privileged
def create_library(name: str):
"""Create an empty library."""
calibre.validate_library_name(name)
library = LIBRARIES_PATH / name
library.mkdir(mode=0o755) # Raise exception if already exists
action_utils.run(
['calibredb', '--with-library', library, 'list_categories'],
check=False)
# Force systemd StateDirectory= logic to assign proper ownership to the
# DynamicUser=
shutil.chown(LIBRARIES_PATH.parent, 'root', 'root')
action_utils.service_try_restart(calibre.CalibreApp.DAEMON)
@privileged
def delete_library(name: str):
"""Delete a library and its contents."""
calibre.validate_library_name(name)
library = LIBRARIES_PATH / name
shutil.rmtree(library)
action_utils.service_try_restart(calibre.CalibreApp.DAEMON)
@privileged
def uninstall():
"""Remove all libraries during uninstall."""
shutil.rmtree(LIBRARIES_PATH)