Extract text editor utils

This commit is contained in:
jonct 2024-07-15 03:51:46 -04:00
parent 58e8b10553
commit 25100ef39d
No known key found for this signature in database
2 changed files with 21 additions and 15 deletions

View File

@ -85,22 +85,8 @@ from utils.download import run_lxc_download_script
from utils.files import stat_chmod
from utils.jail_dataset import get_zfs_dataset, create_zfs_dataset, remove_zfs_dataset
def get_text_editor():
def get_from_environ(key):
if editor := os.environ.get(key):
return shutil.which(editor)
return (
get_from_environ("VISUAL")
or get_from_environ("EDITOR")
or shutil.which("editor")
or shutil.which("/usr/bin/editor")
or "nano"
)
from actions.create import create_jail
from utils.editor import get_text_editor
from utils.jail_dataset import jail_is_running

20
src/jlmkr/utils/editor.py Normal file
View File

@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only
import os
import shutil
def get_text_editor():
def get_from_environ(key):
if editor := os.environ.get(key):
return shutil.which(editor)
return (
get_from_environ("VISUAL")
or get_from_environ("EDITOR")
or shutil.which("editor")
or shutil.which("/usr/bin/editor")
or "nano"
)