Ruff format and sort imports

This commit is contained in:
Jip-Hop 2024-07-16 21:12:39 +02:00
parent 889f4791d3
commit 00fb155c74
17 changed files with 57 additions and 53 deletions

View File

@ -19,7 +19,6 @@ import sys
from cli import main from cli import main
if __name__ == "__main__": if __name__ == "__main__":
try: try:
sys.exit(main()) sys.exit(main())

View File

@ -5,30 +5,30 @@
import contextlib import contextlib
import os import os
import sys import sys
from inspect import cleandoc from inspect import cleandoc
from pathlib import Path, PurePath from pathlib import Path, PurePath
from textwrap import dedent from textwrap import dedent
from actions.start import start_jail
from cli import DISCLAIMER 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.chroot import Chroot
from utils.config_parser import KeyValueParser, DEFAULT_CONFIG from utils.config_parser import DEFAULT_CONFIG, KeyValueParser
from utils.console import YELLOW, BOLD, NORMAL, eprint 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.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 ( from utils.jail import (
check_jail_name_valid,
check_jail_name_available, check_jail_name_available,
check_jail_name_valid,
cleanup,
get_jail_config_path, get_jail_config_path,
get_jail_rootfs_path,
get_jail_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 utils.os_release import parse_os_release
from actions.start import start_jail
def create_jail(**kwargs): def create_jail(**kwargs):
print(DISCLAIMER) print(DISCLAIMER)

View File

@ -5,9 +5,13 @@
import subprocess import subprocess
from utils.console import eprint 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.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): def edit_jail(jail_name):

View File

@ -4,11 +4,10 @@
import json import json
import subprocess import subprocess
from collections import defaultdict from collections import defaultdict
from utils.config_parser import parse_config_file 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.jail import get_all_jail_names, get_jail_config_path, get_jail_rootfs_path
from utils.os_release import parse_os_release from utils.os_release import parse_os_release

View File

@ -2,15 +2,16 @@
# #
# SPDX-License-Identifier: LGPL-3.0-only # SPDX-License-Identifier: LGPL-3.0-only
from actions.stop import stop_jail
from utils.console import eprint from utils.console import eprint
from utils.jail import ( from utils.jail import (
check_jail_name_valid,
check_jail_name_available, check_jail_name_available,
get_jail_path, check_jail_name_valid,
cleanup, cleanup,
get_jail_path,
) )
from actions.stop import stop_jail
def remove_jail(jail_name): def remove_jail(jail_name):
""" """

View File

@ -2,9 +2,10 @@
# #
# SPDX-License-Identifier: LGPL-3.0-only # SPDX-License-Identifier: LGPL-3.0-only
from utils.console import eprint
from actions.start import start_jail from actions.start import start_jail
from actions.stop import stop_jail from actions.stop import stop_jail
from utils.console import eprint
def restart_jail(jail_name): def restart_jail(jail_name):

View File

@ -6,22 +6,22 @@ import os.path
import shlex import shlex
import subprocess import subprocess
import tempfile import tempfile
from pathlib import Path from pathlib import Path
from textwrap import dedent from textwrap import dedent
from actions.exec import exec_jail from paths import COMMAND_NAME, JAIL_ROOTFS_NAME, SHORTNAME
from paths import COMMAND_NAME, SHORTNAME, JAIL_ROOTFS_NAME
from utils.config_parser import parse_config_file from utils.config_parser import parse_config_file
from utils.console import eprint, RED, BOLD, NORMAL from utils.console import BOLD, NORMAL, RED, eprint
from utils.jail import (
get_jail_path,
jail_is_running,
get_jail_config_path,
get_jail_rootfs_path,
)
from utils.files import stat_chmod from utils.files import stat_chmod
from utils.gpu import passthrough_intel, passthrough_nvidia 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): def start_jail(jail_name):

View File

@ -2,10 +2,11 @@
# #
# SPDX-License-Identifier: LGPL-3.0-only # SPDX-License-Identifier: LGPL-3.0-only
from actions.start import start_jail
from utils.config_parser import parse_config_file from utils.config_parser import parse_config_file
from utils.jail import get_all_jail_names, get_jail_config_path from utils.jail import get_all_jail_names, get_jail_config_path
from actions.start import start_jail
def startup_jails(): def startup_jails():
start_failure = False start_failure = False

View File

@ -6,14 +6,6 @@ import argparse
import os import os
import sys 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.create import create_jail
from actions.edit import edit_jail from actions.edit import edit_jail
from actions.exec import exec_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.startup import startup_jails
from actions.status import status_jail from actions.status import status_jail
from actions.stop import stop_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(): def main():
if os.stat(SCRIPT_PATH).st_uid != 0: if os.stat(SCRIPT_PATH).st_uid != 0:
if os.environ.get('JLMKR_DEBUG') is None: if os.environ.get("JLMKR_DEBUG") is None:
fail( fail(
f"This script should be owned by the root user... Fix it manually with: `chown root {SCRIPT_PATH}`." f"This script should be owned by the root user... Fix it manually with: `chown root {SCRIPT_PATH}`."
) )
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=__doc__, description=__doc__,

View File

@ -2,9 +2,9 @@
# #
# SPDX-License-Identifier: LGPL-3.0-only # SPDX-License-Identifier: LGPL-3.0-only
from __main__ import __disclaimer__ from utils.console import BOLD, NORMAL, YELLOW
from utils.console import YELLOW, BOLD, NORMAL
from __main__ import __disclaimer__
DISCLAIMER = f"""{YELLOW}{BOLD}{__disclaimer__}{NORMAL}""" DISCLAIMER = f"""{YELLOW}{BOLD}{__disclaimer__}{NORMAL}"""

View File

@ -4,7 +4,6 @@
import os.path import os.path
# When running as a zipapp, the script file is a parent # When running as a zipapp, the script file is a parent
ZIPAPP_PATH = os.path.realpath(__file__) ZIPAPP_PATH = os.path.realpath(__file__)
while not os.path.exists(ZIPAPP_PATH): while not os.path.exists(ZIPAPP_PATH):

View File

@ -7,8 +7,8 @@ import io
import re import re
from data import DEFAULT_CONFIG 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 # 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. # option is not found. Created to enable `None` as a valid fallback value.

View File

@ -4,7 +4,6 @@
import sys import sys
# Only set a color if we have an interactive tty # Only set a color if we have an interactive tty
if sys.stdout.isatty(): if sys.stdout.isatty():
BOLD = "\033[1m" BOLD = "\033[1m"

View File

@ -2,11 +2,13 @@
# #
# SPDX-License-Identifier: LGPL-3.0-only # 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 os.path
import subprocess 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): def _get_relative_path_in_jailmaker_dir(absolute_path):

View File

@ -11,7 +11,6 @@ import urllib.request
from utils.console import eprint from utils.console import eprint
from utils.files import stat_chmod from utils.files import stat_chmod
DOWNLOAD_SCRIPT_DIGEST = ( DOWNLOAD_SCRIPT_DIGEST = (
"cfcb5d08b24187d108f2ab0d21a6cc4b73dcd7f5d7dfc80803bfd7f1642d638d" "cfcb5d08b24187d108f2ab0d21a6cc4b73dcd7f5d7dfc80803bfd7f1642d638d"
) )

View File

@ -4,15 +4,14 @@
import os.path import os.path
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from textwrap import dedent from textwrap import dedent
from paths import SHORTNAME from paths import SHORTNAME
from utils.console import eprint from utils.console import eprint
from utils.jail import get_jail_rootfs_path from utils.jail import get_jail_rootfs_path
# Test intel GPU by decoding mp4 file (output is discarded) # Test intel GPU by decoding mp4 file (output is discarded)
# Run the commands below in the jail: # Run the commands below in the jail:
# curl -o bunny.mp4 https://www.w3schools.com/html/mov_bbb.mp4 # curl -o bunny.mp4 https://www.w3schools.com/html/mov_bbb.mp4

View File

@ -9,6 +9,7 @@ from utils.chroot import Chroot
def parse_os_release(new_root): def parse_os_release(new_root):
result = {} result = {}
with Chroot(new_root): with Chroot(new_root):
# Use chroot to correctly resolve os-release symlink (for nixos) # Use chroot to correctly resolve os-release symlink (for nixos)
for candidate in ["/etc/os-release", "/usr/lib/os-release"]: for candidate in ["/etc/os-release", "/usr/lib/os-release"]: