diff --git a/src/jlmkr/__main__.py b/src/jlmkr/__main__.py index a73c3c2..2b263d5 100644 --- a/src/jlmkr/__main__.py +++ b/src/jlmkr/__main__.py @@ -19,7 +19,6 @@ import sys from cli import main - if __name__ == "__main__": try: sys.exit(main()) diff --git a/src/jlmkr/actions/create.py b/src/jlmkr/actions/create.py index fff25ae..3ad1fcd 100644 --- a/src/jlmkr/actions/create.py +++ b/src/jlmkr/actions/create.py @@ -5,30 +5,30 @@ import contextlib import os import sys - from inspect import cleandoc from pathlib import Path, PurePath from textwrap import dedent -from actions.start import start_jail from cli import DISCLAIMER -from paths import COMMAND_NAME, JAILS_DIR_PATH, SCRIPT_NAME, SCRIPT_DIR_PATH +from paths import COMMAND_NAME, JAILS_DIR_PATH, SCRIPT_DIR_PATH, SCRIPT_NAME from utils.chroot import Chroot -from utils.config_parser import KeyValueParser, DEFAULT_CONFIG -from utils.console import YELLOW, BOLD, NORMAL, eprint +from utils.config_parser import DEFAULT_CONFIG, KeyValueParser +from utils.console import BOLD, NORMAL, YELLOW, eprint +from utils.dataset import create_zfs_dataset, get_zfs_dataset from utils.download import run_lxc_download_script -from utils.files import stat_chmod, get_mount_point +from utils.files import get_mount_point, stat_chmod from utils.jail import ( - check_jail_name_valid, check_jail_name_available, + check_jail_name_valid, + cleanup, get_jail_config_path, - get_jail_rootfs_path, get_jail_path, + get_jail_rootfs_path, ) -from utils.dataset import get_zfs_dataset, create_zfs_dataset -from utils.jail import cleanup from utils.os_release import parse_os_release +from actions.start import start_jail + def create_jail(**kwargs): print(DISCLAIMER) diff --git a/src/jlmkr/actions/edit.py b/src/jlmkr/actions/edit.py index 6f5827d..74bac96 100644 --- a/src/jlmkr/actions/edit.py +++ b/src/jlmkr/actions/edit.py @@ -5,9 +5,13 @@ import subprocess from utils.console import eprint -from utils.jail import check_jail_name_valid, check_jail_name_available -from utils.jail import get_jail_config_path, jail_is_running from utils.editor import get_text_editor +from utils.jail import ( + check_jail_name_available, + check_jail_name_valid, + get_jail_config_path, + jail_is_running, +) def edit_jail(jail_name): diff --git a/src/jlmkr/actions/list.py b/src/jlmkr/actions/list.py index 3437ea7..7e30cf3 100644 --- a/src/jlmkr/actions/list.py +++ b/src/jlmkr/actions/list.py @@ -4,11 +4,10 @@ import json import subprocess - from collections import defaultdict from utils.config_parser import parse_config_file -from utils.console import eprint, NORMAL, UNDERLINE +from utils.console import NORMAL, UNDERLINE, eprint from utils.jail import get_all_jail_names, get_jail_config_path, get_jail_rootfs_path from utils.os_release import parse_os_release diff --git a/src/jlmkr/actions/remove.py b/src/jlmkr/actions/remove.py index ef88bc4..8070e46 100644 --- a/src/jlmkr/actions/remove.py +++ b/src/jlmkr/actions/remove.py @@ -2,15 +2,16 @@ # # SPDX-License-Identifier: LGPL-3.0-only -from actions.stop import stop_jail from utils.console import eprint from utils.jail import ( - check_jail_name_valid, check_jail_name_available, - get_jail_path, + check_jail_name_valid, cleanup, + get_jail_path, ) +from actions.stop import stop_jail + def remove_jail(jail_name): """ diff --git a/src/jlmkr/actions/restart.py b/src/jlmkr/actions/restart.py index 810099f..0187409 100644 --- a/src/jlmkr/actions/restart.py +++ b/src/jlmkr/actions/restart.py @@ -2,9 +2,10 @@ # # SPDX-License-Identifier: LGPL-3.0-only +from utils.console import eprint + from actions.start import start_jail from actions.stop import stop_jail -from utils.console import eprint def restart_jail(jail_name): diff --git a/src/jlmkr/actions/start.py b/src/jlmkr/actions/start.py index 60214fd..10ed1f3 100644 --- a/src/jlmkr/actions/start.py +++ b/src/jlmkr/actions/start.py @@ -6,22 +6,22 @@ import os.path import shlex import subprocess import tempfile - from pathlib import Path from textwrap import dedent -from actions.exec import exec_jail -from paths import COMMAND_NAME, SHORTNAME, JAIL_ROOTFS_NAME +from paths import COMMAND_NAME, JAIL_ROOTFS_NAME, SHORTNAME from utils.config_parser import parse_config_file -from utils.console import eprint, RED, BOLD, NORMAL -from utils.jail import ( - get_jail_path, - jail_is_running, - get_jail_config_path, - get_jail_rootfs_path, -) +from utils.console import BOLD, NORMAL, RED, eprint from utils.files import stat_chmod from utils.gpu import passthrough_intel, passthrough_nvidia +from utils.jail import ( + get_jail_config_path, + get_jail_path, + get_jail_rootfs_path, + jail_is_running, +) + +from actions.exec import exec_jail def start_jail(jail_name): diff --git a/src/jlmkr/actions/startup.py b/src/jlmkr/actions/startup.py index e6016f2..da79375 100644 --- a/src/jlmkr/actions/startup.py +++ b/src/jlmkr/actions/startup.py @@ -2,10 +2,11 @@ # # SPDX-License-Identifier: LGPL-3.0-only -from actions.start import start_jail from utils.config_parser import parse_config_file from utils.jail import get_all_jail_names, get_jail_config_path +from actions.start import start_jail + def startup_jails(): start_failure = False diff --git a/src/jlmkr/cli.py b/src/jlmkr/cli.py index ac92dcd..d700af5 100644 --- a/src/jlmkr/cli.py +++ b/src/jlmkr/cli.py @@ -6,14 +6,6 @@ import argparse import os import sys -from __main__ import __version__ -from data import DISCLAIMER -from paths import SCRIPT_PATH, COMMAND_NAME, SCRIPT_NAME -from utils.config_parser import ExceptionWithParser -from utils.console import fail -from utils.editor import get_text_editor -from utils.files import stat_chmod - from actions.create import create_jail from actions.edit import edit_jail from actions.exec import exec_jail @@ -27,14 +19,22 @@ from actions.start import start_jail from actions.startup import startup_jails from actions.status import status_jail from actions.stop import stop_jail +from data import DISCLAIMER +from paths import COMMAND_NAME, SCRIPT_NAME, SCRIPT_PATH +from utils.config_parser import ExceptionWithParser +from utils.console import fail +from utils.editor import get_text_editor +from utils.files import stat_chmod + +from __main__ import __version__ def main(): if os.stat(SCRIPT_PATH).st_uid != 0: - if os.environ.get('JLMKR_DEBUG') is None: - fail( - f"This script should be owned by the root user... Fix it manually with: `chown root {SCRIPT_PATH}`." - ) + if os.environ.get("JLMKR_DEBUG") is None: + fail( + f"This script should be owned by the root user... Fix it manually with: `chown root {SCRIPT_PATH}`." + ) parser = argparse.ArgumentParser( description=__doc__, diff --git a/src/jlmkr/data.py b/src/jlmkr/data.py index 2f68e83..135fa76 100644 --- a/src/jlmkr/data.py +++ b/src/jlmkr/data.py @@ -2,9 +2,9 @@ # # SPDX-License-Identifier: LGPL-3.0-only -from __main__ import __disclaimer__ -from utils.console import YELLOW, BOLD, NORMAL +from utils.console import BOLD, NORMAL, YELLOW +from __main__ import __disclaimer__ DISCLAIMER = f"""{YELLOW}{BOLD}{__disclaimer__}{NORMAL}""" diff --git a/src/jlmkr/paths.py b/src/jlmkr/paths.py index bfee658..fbe98ad 100755 --- a/src/jlmkr/paths.py +++ b/src/jlmkr/paths.py @@ -4,7 +4,6 @@ import os.path - # When running as a zipapp, the script file is a parent ZIPAPP_PATH = os.path.realpath(__file__) while not os.path.exists(ZIPAPP_PATH): diff --git a/src/jlmkr/utils/config_parser.py b/src/jlmkr/utils/config_parser.py index 669be7e..55b5acb 100644 --- a/src/jlmkr/utils/config_parser.py +++ b/src/jlmkr/utils/config_parser.py @@ -7,8 +7,8 @@ import io import re from data import DEFAULT_CONFIG -from utils.console import eprint +from utils.console import eprint # Used in parser getters to indicate the default behavior when a specific # option is not found. Created to enable `None` as a valid fallback value. diff --git a/src/jlmkr/utils/console.py b/src/jlmkr/utils/console.py index 20018f7..736c11e 100644 --- a/src/jlmkr/utils/console.py +++ b/src/jlmkr/utils/console.py @@ -4,7 +4,6 @@ import sys - # Only set a color if we have an interactive tty if sys.stdout.isatty(): BOLD = "\033[1m" diff --git a/src/jlmkr/utils/dataset.py b/src/jlmkr/utils/dataset.py index 1a4ec8c..5afee9c 100644 --- a/src/jlmkr/utils/dataset.py +++ b/src/jlmkr/utils/dataset.py @@ -2,11 +2,13 @@ # # SPDX-License-Identifier: LGPL-3.0-only -from pathlib import PurePath -from paths import SCRIPT_DIR_PATH -from utils.console import eprint, fail import os.path import subprocess +from pathlib import PurePath + +from paths import SCRIPT_DIR_PATH + +from utils.console import eprint, fail def _get_relative_path_in_jailmaker_dir(absolute_path): diff --git a/src/jlmkr/utils/download.py b/src/jlmkr/utils/download.py index 3cb608a..1782022 100644 --- a/src/jlmkr/utils/download.py +++ b/src/jlmkr/utils/download.py @@ -11,7 +11,6 @@ import urllib.request from utils.console import eprint from utils.files import stat_chmod - DOWNLOAD_SCRIPT_DIGEST = ( "cfcb5d08b24187d108f2ab0d21a6cc4b73dcd7f5d7dfc80803bfd7f1642d638d" ) diff --git a/src/jlmkr/utils/gpu.py b/src/jlmkr/utils/gpu.py index 6158648..45e7a8d 100644 --- a/src/jlmkr/utils/gpu.py +++ b/src/jlmkr/utils/gpu.py @@ -4,15 +4,14 @@ import os.path import subprocess - from pathlib import Path from textwrap import dedent from paths import SHORTNAME + from utils.console import eprint from utils.jail import get_jail_rootfs_path - # Test intel GPU by decoding mp4 file (output is discarded) # Run the commands below in the jail: # curl -o bunny.mp4 https://www.w3schools.com/html/mov_bbb.mp4 diff --git a/src/jlmkr/utils/os_release.py b/src/jlmkr/utils/os_release.py index 5e7a111..da2a57a 100644 --- a/src/jlmkr/utils/os_release.py +++ b/src/jlmkr/utils/os_release.py @@ -9,6 +9,7 @@ from utils.chroot import Chroot def parse_os_release(new_root): result = {} + with Chroot(new_root): # Use chroot to correctly resolve os-release symlink (for nixos) for candidate in ["/etc/os-release", "/usr/lib/os-release"]: