Formatting
This commit is contained in:
parent
29cb1ee77e
commit
414df22757
27
jlmkr.py
27
jlmkr.py
|
@ -174,7 +174,9 @@ class KeyValueParser(configparser.ConfigParser):
|
||||||
# Template to store comments as key value pair
|
# Template to store comments as key value pair
|
||||||
self._comment_template = "#{0} " + delimiter + " {1}"
|
self._comment_template = "#{0} " + delimiter + " {1}"
|
||||||
# Regex to match the comment prefix
|
# Regex to match the comment prefix
|
||||||
self._comment_regex = re.compile(r"^#\d+\s*" + re.escape(delimiter) + r"[^\S\n]*")
|
self._comment_regex = re.compile(
|
||||||
|
r"^#\d+\s*" + re.escape(delimiter) + r"[^\S\n]*"
|
||||||
|
)
|
||||||
# Regex to match cosmetic newlines (skips newlines in multiline values):
|
# Regex to match cosmetic newlines (skips newlines in multiline values):
|
||||||
# consecutive whitespace from start of line followed by a line not starting with whitespace
|
# consecutive whitespace from start of line followed by a line not starting with whitespace
|
||||||
self._cosmetic_newlines_regex = re.compile(r"^(\s+)(?=^\S)", re.MULTILINE)
|
self._cosmetic_newlines_regex = re.compile(r"^(\s+)(?=^\S)", re.MULTILINE)
|
||||||
|
@ -538,7 +540,8 @@ def systemd_escape_path(path):
|
||||||
"""
|
"""
|
||||||
return "".join(
|
return "".join(
|
||||||
map(
|
map(
|
||||||
lambda char: r"\s" if char == " " else "\\\\" if char == "\\" else char, path
|
lambda char: r"\s" if char == " " else "\\\\" if char == "\\" else char,
|
||||||
|
path,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -881,7 +884,6 @@ def run_lxc_download_script(
|
||||||
f"--release={release}",
|
f"--release={release}",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
if rc := subprocess.run(cmd, env={"LXC_CACHE_PATH": lxc_cache}).returncode != 0:
|
if rc := subprocess.run(cmd, env={"LXC_CACHE_PATH": lxc_cache}).returncode != 0:
|
||||||
eprint("Aborting...")
|
eprint("Aborting...")
|
||||||
return rc
|
return rc
|
||||||
|
@ -945,9 +947,11 @@ def get_mount_point(path):
|
||||||
path = os.path.dirname(path)
|
path = os.path.dirname(path)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def get_relative_path_in_jailmaker_dir(absolute_path):
|
def get_relative_path_in_jailmaker_dir(absolute_path):
|
||||||
return PurePath(absolute_path).relative_to(SCRIPT_DIR_PATH)
|
return PurePath(absolute_path).relative_to(SCRIPT_DIR_PATH)
|
||||||
|
|
||||||
|
|
||||||
def get_zfs_dataset(path):
|
def get_zfs_dataset(path):
|
||||||
"""
|
"""
|
||||||
Get ZFS dataset path.
|
Get ZFS dataset path.
|
||||||
|
@ -1285,10 +1289,14 @@ def create_jail(**kwargs):
|
||||||
if jail_config_path:
|
if jail_config_path:
|
||||||
# TODO: fallback to default values for e.g. distro and release if they are not in the config file
|
# TODO: fallback to default values for e.g. distro and release if they are not in the config file
|
||||||
if jail_config_path == "-":
|
if jail_config_path == "-":
|
||||||
print(f"Creating jail {jail_name} from config template passed via stdin.")
|
print(
|
||||||
|
f"Creating jail {jail_name} from config template passed via stdin."
|
||||||
|
)
|
||||||
config.read_string(sys.stdin.read())
|
config.read_string(sys.stdin.read())
|
||||||
else:
|
else:
|
||||||
print(f"Creating jail {jail_name} from config template {jail_config_path}.")
|
print(
|
||||||
|
f"Creating jail {jail_name} from config template {jail_config_path}."
|
||||||
|
)
|
||||||
if jail_config_path not in config.read(jail_config_path):
|
if jail_config_path not in config.read(jail_config_path):
|
||||||
eprint(f"Failed to read config template {jail_config_path}.")
|
eprint(f"Failed to read config template {jail_config_path}.")
|
||||||
return 1
|
return 1
|
||||||
|
@ -1362,9 +1370,12 @@ def create_jail(**kwargs):
|
||||||
# but we don't need it so we will remove it later
|
# but we don't need it so we will remove it later
|
||||||
open(jail_config_path, "a").close()
|
open(jail_config_path, "a").close()
|
||||||
|
|
||||||
if returncode := run_lxc_download_script(
|
if (
|
||||||
jail_name, jail_path, jail_rootfs_path, distro, release
|
returncode := run_lxc_download_script(
|
||||||
) != 0:
|
jail_name, jail_path, jail_rootfs_path, distro, release
|
||||||
|
)
|
||||||
|
!= 0
|
||||||
|
):
|
||||||
cleanup(jail_path)
|
cleanup(jail_path)
|
||||||
return returncode
|
return returncode
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue