mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
*: Use action_utils.run instead of subprocess.call
- This is to capture stdout and stderr and transmit that from privileged daemon back to the service to be displayed in HTML. Tests: - Unit tests and code checks pass. - Some of the modified actions work as expected. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
parent
80e6d940a4
commit
bf9005ac48
@ -28,9 +28,9 @@ def create_library(name: str):
|
|||||||
calibre.validate_library_name(name)
|
calibre.validate_library_name(name)
|
||||||
library = LIBRARIES_PATH / name
|
library = LIBRARIES_PATH / name
|
||||||
library.mkdir(mode=0o755) # Raise exception if already exists
|
library.mkdir(mode=0o755) # Raise exception if already exists
|
||||||
subprocess.call(
|
action_utils.run(
|
||||||
['calibredb', '--with-library', library, 'list_categories'],
|
['calibredb', '--with-library', library, 'list_categories'],
|
||||||
stdout=subprocess.DEVNULL)
|
stdout=subprocess.DEVNULL, check=False)
|
||||||
|
|
||||||
# Force systemd StateDirectory= logic to assign proper ownership to the
|
# Force systemd StateDirectory= logic to assign proper ownership to the
|
||||||
# DynamicUser=
|
# DynamicUser=
|
||||||
|
|||||||
@ -29,9 +29,8 @@ def fixture_patch():
|
|||||||
path = pathlib.Path(args[0][2]) / 'metadata.db'
|
path = pathlib.Path(args[0][2]) / 'metadata.db'
|
||||||
path.touch()
|
path.touch()
|
||||||
|
|
||||||
with patch('subprocess.call') as subprocess_call, \
|
with patch('subprocess.run') as subprocess_run, patch('shutil.chown'):
|
||||||
patch('subprocess.run'), patch('shutil.chown'):
|
subprocess_run.side_effect = side_effect
|
||||||
subprocess_call.side_effect = side_effect
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -145,7 +145,7 @@ def pre_change_hostname(old_hostname: str, new_hostname: str):
|
|||||||
logger.info('ejabberdctl not found')
|
logger.info('ejabberdctl not found')
|
||||||
return
|
return
|
||||||
|
|
||||||
subprocess.call(['ejabberdctl', 'backup', EJABBERD_BACKUP])
|
action_utils.run(['ejabberdctl', 'backup', EJABBERD_BACKUP], check=False)
|
||||||
subprocess.check_output([
|
subprocess.check_output([
|
||||||
'ejabberdctl', 'mnesia-change-nodename', 'ejabberd@' + old_hostname,
|
'ejabberdctl', 'mnesia-change-nodename', 'ejabberd@' + old_hostname,
|
||||||
'ejabberd@' + new_hostname, EJABBERD_BACKUP, EJABBERD_BACKUP_NEW
|
'ejabberd@' + new_hostname, EJABBERD_BACKUP, EJABBERD_BACKUP_NEW
|
||||||
@ -160,12 +160,12 @@ def change_hostname():
|
|||||||
return
|
return
|
||||||
|
|
||||||
action_utils.service_stop('ejabberd')
|
action_utils.service_stop('ejabberd')
|
||||||
subprocess.call(['pkill', '-u', 'ejabberd'])
|
action_utils.run(['pkill', '-u', 'ejabberd'], check=False)
|
||||||
|
|
||||||
# Make sure there aren't files in the Mnesia spool dir
|
# Make sure there aren't files in the Mnesia spool dir
|
||||||
os.makedirs('/var/lib/ejabberd/oldfiles', exist_ok=True)
|
os.makedirs('/var/lib/ejabberd/oldfiles', exist_ok=True)
|
||||||
subprocess.call('mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/',
|
action_utils.run('mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/',
|
||||||
shell=True)
|
shell=True, check=False)
|
||||||
|
|
||||||
action_utils.service_start('ejabberd')
|
action_utils.service_start('ejabberd')
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ def mam(command: str) -> bool | None:
|
|||||||
yaml.dump(conf, file_handle)
|
yaml.dump(conf, file_handle)
|
||||||
|
|
||||||
if action_utils.service_is_running('ejabberd'):
|
if action_utils.service_is_running('ejabberd'):
|
||||||
subprocess.call(['ejabberdctl', 'reload_config'])
|
action_utils.run(['ejabberdctl', 'reload_config'], check=False)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ def configure_turn(turn_server_config: dict[str, Any], managed: bool):
|
|||||||
Path(EJABBERD_MANAGED_COTURN).unlink(missing_ok=True)
|
Path(EJABBERD_MANAGED_COTURN).unlink(missing_ok=True)
|
||||||
|
|
||||||
if action_utils.service_is_running('ejabberd'):
|
if action_utils.service_is_running('ejabberd'):
|
||||||
subprocess.call(['ejabberdctl', 'reload_config'])
|
action_utils.run(['ejabberdctl', 'reload_config'], check=False)
|
||||||
|
|
||||||
|
|
||||||
def _get_version():
|
def _get_version():
|
||||||
|
|||||||
@ -104,8 +104,8 @@ def _setup_firewall():
|
|||||||
'firewall-cmd', '--zone', 'internal',
|
'firewall-cmd', '--zone', 'internal',
|
||||||
'--{}-interface'.format(operation), interface
|
'--{}-interface'.format(operation), interface
|
||||||
]
|
]
|
||||||
subprocess.call(command)
|
action_utils.run(command, check=False)
|
||||||
subprocess.call(command + ['--permanent'])
|
action_utils.run(command + ['--permanent'], check=False)
|
||||||
|
|
||||||
def _is_tunplus_enabled():
|
def _is_tunplus_enabled():
|
||||||
"""Return whether tun+ interface is already added."""
|
"""Return whether tun+ interface is already added."""
|
||||||
|
|||||||
@ -1,18 +1,17 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""Shutdown/restart the system."""
|
"""Shutdown/restart the system."""
|
||||||
|
|
||||||
import subprocess
|
from plinth import action_utils
|
||||||
|
|
||||||
from plinth.actions import privileged
|
from plinth.actions import privileged
|
||||||
|
|
||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
def restart():
|
def restart():
|
||||||
"""Restart the system."""
|
"""Restart the system."""
|
||||||
subprocess.call('reboot')
|
action_utils.run('reboot', check=False)
|
||||||
|
|
||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
def shutdown():
|
def shutdown():
|
||||||
"""Shut down the system."""
|
"""Shut down the system."""
|
||||||
subprocess.call(['shutdown', 'now'])
|
action_utils.run(['shutdown', 'now'], check=False)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user