diff --git a/src/jlmkr/actions/edit.py b/src/jlmkr/actions/edit.py new file mode 100644 index 0000000..fd5f03c --- /dev/null +++ b/src/jlmkr/actions/edit.py @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers +# +# SPDX-License-Identifier: LGPL-3.0-only + +import os +import subprocess + +from utils.console import eprint +from utils.editor import get_text_editor +from utils.jail_dataset import check_jail_name_valid, check_jail_name_available +from utils.jail_dataset import get_jail_config_path, jail_is_running + + +def edit_jail(jail_name): + """ + Edit jail with given name. + """ + + if not check_jail_name_valid(jail_name): + return 1 + + if check_jail_name_available(jail_name, False): + eprint(f"A jail with name {jail_name} does not exist.") + return 1 + + jail_config_path = get_jail_config_path(jail_name) + + returncode = subprocess.run([get_text_editor(), jail_config_path]).returncode + + if returncode != 0: + eprint(f"An error occurred while editing {jail_config_path}.") + return returncode + + if jail_is_running(jail_name): + print("\nRestart the jail for edits to apply (if you made any).") + + return 0 diff --git a/src/jlmkr/donor/jlmkr.py b/src/jlmkr/donor/jlmkr.py index a2d531a..3a839b2 100755 --- a/src/jlmkr/donor/jlmkr.py +++ b/src/jlmkr/donor/jlmkr.py @@ -89,33 +89,7 @@ from actions.create import create_jail from utils.editor import get_text_editor from utils.jail_dataset import jail_is_running - -def edit_jail(jail_name): - """ - Edit jail with given name. - """ - - if not check_jail_name_valid(jail_name): - return 1 - - if check_jail_name_available(jail_name, False): - eprint(f"A jail with name {jail_name} does not exist.") - return 1 - - jail_config_path = get_jail_config_path(jail_name) - - returncode = subprocess.run([get_text_editor(), jail_config_path]).returncode - - if returncode != 0: - eprint(f"An error occurred while editing {jail_config_path}.") - return returncode - - if jail_is_running(jail_name): - print("\nRestart the jail for edits to apply (if you made any).") - - return 0 - - +from actions.edit import edit_jail from actions.stop import stop_jail from actions.remove import remove_jail