diff --git a/osbuild/util/parsing.py b/osbuild/util/parsing.py index 3c4c05e5..1f90418b 100644 --- a/osbuild/util/parsing.py +++ b/osbuild/util/parsing.py @@ -2,8 +2,7 @@ import os import re - -from typing import Union, Dict +from typing import Dict, Union from urllib.parse import ParseResult, urlparse @@ -36,7 +35,7 @@ def parse_size(s: str) -> Union[int, str]: raise TypeError(f"invalid size value: '{s}'") -def parse_mount(url: ParseResult, args: Dict): +def parse_mount(url: ParseResult, args: Dict) -> os.PathLike: """ Parses the mount URL to extract the root path. @@ -55,7 +54,7 @@ def parse_mount(url: ParseResult, args: Dict): return root -def parse_input(url: ParseResult, args: Dict): +def parse_input(url: ParseResult, args: Dict) -> os.PathLike: """ Parses the input URL to extract the root path. @@ -71,7 +70,7 @@ def parse_input(url: ParseResult, args: Dict): return root -def parse_location(location, args): +def parse_location(location: str, args: Dict) -> str: """ Parses the location URL to derive the corresponding file path. diff --git a/stages/org.osbuild.chattr b/stages/org.osbuild.chattr index f2a88763..e2138e9f 100755 --- a/stages/org.osbuild.chattr +++ b/stages/org.osbuild.chattr @@ -1,5 +1,4 @@ #!/usr/bin/python3 -import os import subprocess import sys @@ -38,6 +37,7 @@ SCHEMA_2 = r""" } """ + def main(args, options): for path, cmdargs in options["items"].items(): immutable = cmdargs["immutable"] diff --git a/stages/org.osbuild.copy b/stages/org.osbuild.copy index cd92b318..433e592f 100755 --- a/stages/org.osbuild.copy +++ b/stages/org.osbuild.copy @@ -1,5 +1,4 @@ #!/usr/bin/python3 -import os import subprocess import sys diff --git a/stages/org.osbuild.kernel-cmdline.bls-append b/stages/org.osbuild.kernel-cmdline.bls-append index 5d8f29e8..72873498 100755 --- a/stages/org.osbuild.kernel-cmdline.bls-append +++ b/stages/org.osbuild.kernel-cmdline.bls-append @@ -1,9 +1,8 @@ #!/usr/bin/python3 import sys -from urllib.parse import urlparse import osbuild.api -from osbuild.util import bls +from osbuild.util import bls, parsing def main(args, options): @@ -15,6 +14,6 @@ def main(args, options): if __name__ == '__main__': - args = osbuild.api.arguments() - r = main(args, args["options"]) + _args = osbuild.api.arguments() + r = main(_args, _args["options"]) sys.exit(r) diff --git a/test/mod/test_util_parsing.py b/test/mod/test_util_parsing.py index faaa31a5..e501310c 100644 --- a/test/mod/test_util_parsing.py +++ b/test/mod/test_util_parsing.py @@ -37,3 +37,41 @@ def test_parse_size(): else: res = parsing.parse_size(s) assert res == num, f"{s} parsed as {res} (wanted {num})" + + +def test_parse_location_mounts(): + args = { + "paths": { + "mounts": "/run/osbuild/mounts", + }, + "mounts": { + "root": { + "path": "/run/osbuild/mounts/.", + }, + }, + } + location = "mount://root/" + path = parsing.parse_location(location, args) + assert path == "/run/osbuild/mounts/." + + +def test_parse_location_tree(): + args = { + "tree": "/run/osbuild/tree", + } + location = "tree:///disk.img" + path = parsing.parse_location(location, args) + assert path == "/run/osbuild/tree/disk.img" + + +def test_parse_location_inputs(): + args = { + "inputs": { + "tree": { + "path": "/run/osbuild/inputs/tree", + }, + }, + } + location = "input://tree/" + path = parsing.parse_location(location, args) + assert path == "/run/osbuild/inputs/tree/." diff --git a/tox.ini b/tox.ini index dbaf7a94..505719c5 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ setenv = LINTABLES_EXCLUDES = "*.json,*.sh" LINTABLES_EXCLUDES_RE = ".*\.json$,.*\.sh" TYPEABLES = osbuild - TYPEABLES_STRICT = ./osbuild/main_cli.py + TYPEABLES_STRICT = ./osbuild/main_cli.py ./osbuild/util/parsing.py passenv = TEST_CATEGORY