Skip to content

Commit bd780c6

Browse files
committed
replace logger infos with exceptions
1 parent c1e6377 commit bd780c6

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/gardenlinux/build/exporter.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ def _isElf(path: str | PathLike[str]) -> bool:
3737
return False
3838

3939

40-
def _getInterpreter(path: str | PathLike[str], logger) -> pathlib.Path:
40+
def _getInterpreter(path: str | PathLike[str]) -> pathlib.Path:
4141
"""
4242
Returns the interpreter of an ELF. Supported architectures: x86_64, aarch64, i686.
4343
4444
:param path: Path to file
45-
:param logger: Logger to log errors
4645
4746
:return: (str) Path of the interpreter
4847
:since: TODO
@@ -63,15 +62,12 @@ def _getInterpreter(path: str | PathLike[str], logger) -> pathlib.Path:
6362
case "EM_X86_64":
6463
return pathlib.Path("/lib64/ld-linux-x86-64.so.2")
6564
case arch:
66-
logger.error(
67-
f"Error: Unsupported architecture for {path}: only support x86_64 (003e), aarch64 (00b7) and i686 (0003), but was {arch}"
68-
)
69-
exit(1)
65+
raise RuntimeError(f"Error: Unsupported architecture for {path}: only support x86_64 (003e), aarch64 (00b7) and i686 (0003), but was {arch}")
7066

7167
def _get_python_from_path() -> pathlib.Path | None:
7268
interpreter = None
7369
for dir in os.environ["PATH"].split(":"):
74-
binary = pathlib.Path(dir).joinpath("python3")
70+
binary = pathlib.Path(dir, "python3").joinpath("python3")
7571
if binary.is_file():
7672
interpreter = binary
7773
break
@@ -99,40 +95,33 @@ def _get_default_package_dir() -> pathlib.Path | None:
9995

10096
def export(
10197
output_dir: str | PathLike[str] = "/required_libs",
102-
package_dir: str | PathLike[str] | None = None,
103-
logger=None,
98+
package_dir: str | PathLike[str] | None = None
10499
) -> None:
105100
"""
106101
Identifies shared library dependencies of `package_dir` and copies them to `output_dir`.
107102
108103
:param output_dir: Path to output_dir
109104
:param package_dir: Path to package_dir
110-
:param logger: Logger to log errors
111105
112106
:since: TODO
113107
"""
114108

115109
if not package_dir:
116110
package_dir = _get_default_package_dir()
117111
if not package_dir:
118-
logger.error(
119-
f"Error: Couldn't identify a default python package directory. Please specifiy one using the --package-dir option. Use -h for more information."
120-
)
121-
exit(1)
112+
raise RuntimeError(f"Error: Couldn't identify a default python package directory. Please specifiy one using the --package-dir option. Use -h for more information.")
122113
else:
123114
package_dir = pathlib.Path(package_dir)
124115
output_dir = pathlib.Path(output_dir)
125116

126-
if logger is None or not logger.hasHandlers():
127-
logger = LoggerSetup.get_logger("gardenlinux.export_libs")
128117
# Collect ld dependencies for installed pip packages
129118
dependencies = set()
130119
for root, dirs, files in package_dir.walk():
131120
for file in files:
132121
path = root.joinpath(file)
133122
if not path.is_symlink() and _isElf(path):
134123
out = subprocess.run(
135-
[_getInterpreter(path, logger), "--inhibit-cache", "--list", path],
124+
[_getInterpreter(path), "--inhibit-cache", "--list", path],
136125
stdout=subprocess.PIPE,
137126
)
138127
for dependency in parse_output.findall(out.stdout.decode()):

0 commit comments

Comments
 (0)