bytebeat_compiler.py: do not use sys.exit
This commit is contained in:
parent
d17a5bff05
commit
542126cb33
@ -8,7 +8,7 @@ from os import environ, makedirs, name as os_name
|
||||
from os.path import exists, join as path_join
|
||||
from shlex import join as command_line_join, split as command_line_split
|
||||
from shutil import which
|
||||
from sys import stdin, stdout, exit
|
||||
from sys import stdin, stdout
|
||||
from typing import Dict, Union
|
||||
import re
|
||||
import subprocess
|
||||
@ -72,8 +72,7 @@ def read_from_file_or_stdin(path: str) -> str:
|
||||
elif exists(path):
|
||||
return read_file(path)
|
||||
else:
|
||||
print("The specified file doesn't exist")
|
||||
raise SystemExit
|
||||
raise SystemExit(f"The specified file {path} doesn't exist")
|
||||
|
||||
def substitute_vars(replacements: Dict[str, Union[bool, str]], text: str,
|
||||
verbose: bool) -> str:
|
||||
@ -93,7 +92,7 @@ def substitute_vars(replacements: Dict[str, Union[bool, str]], text: str,
|
||||
def run_command(*command: list[str]) -> None:
|
||||
print(command_line_join(command), flush=True)
|
||||
if subprocess.run(command).returncode != EXIT_SUCCESS:
|
||||
exit(EXIT_FAILURE)
|
||||
raise SystemExit(EXIT_FAILURE)
|
||||
|
||||
preprocessor_bool = lambda value: "1" if value else "0"
|
||||
C_str_repr = lambda s: '"' + s.replace("\\", "\\\\").replace(r'"', r'\"') + '"'
|
||||
@ -206,8 +205,7 @@ if __name__ == "__main__":
|
||||
bytebeat_contents = read_from_file_or_stdin(args.file).strip()
|
||||
|
||||
if not bytebeat_contents:
|
||||
print("No valid contents")
|
||||
exit(1)
|
||||
raise SystemExit("No valid contents")
|
||||
|
||||
# - Parse arguments from file
|
||||
used_parameter_line = False
|
||||
@ -276,8 +274,7 @@ if __name__ == "__main__":
|
||||
samples_specified = not no_samples
|
||||
|
||||
if seconds_specified and args.seconds < 0:
|
||||
print("CLI: Count of seconds can't be less than zero.")
|
||||
exit(1)
|
||||
raise SystemExit("CLI: Count of seconds can't be less than zero.")
|
||||
|
||||
if no_seconds and samples_specified:
|
||||
samples = args.samples
|
||||
@ -289,17 +286,16 @@ if __name__ == "__main__":
|
||||
args.seconds = 30 # default
|
||||
continue
|
||||
else:
|
||||
print("CLI: Incorrect seconds/samples length format.")
|
||||
exit(1)
|
||||
raise SystemExit("CLI: Incorrect seconds/samples length format.")
|
||||
break
|
||||
|
||||
if samples <= 0:
|
||||
print("CLI: Count of samples should be greater than zero.")
|
||||
exit(1)
|
||||
raise SystemExit("CLI: Count of samples should be greater than zero.")
|
||||
|
||||
if args.mode != "sequential" and args.mode != "instant":
|
||||
print("Invalid mode '%s'" % args.mode)
|
||||
exit(1)
|
||||
raise SystemExit(f"Invalid mode '{args.mode}'")
|
||||
|
||||
gen_length = args.channels * samples
|
||||
|
||||
ansi_escape_codes_supported = args.color == "auto" and stdout_atty or \
|
||||
args.color == "always"
|
||||
@ -375,9 +371,9 @@ if __name__ == "__main__":
|
||||
print()
|
||||
|
||||
if still_unavailable:
|
||||
print("Could not find an available compiler. Please specify it by "
|
||||
"setting\nenvironmental variable CC.")
|
||||
exit(2)
|
||||
raise SystemExit("Could not find an available compiler. Please "
|
||||
"specify it by setting\nenvironmental variable "
|
||||
"CC.")
|
||||
|
||||
# Compile
|
||||
print("Compiling")
|
||||
@ -391,5 +387,3 @@ if __name__ == "__main__":
|
||||
"-I" + PATHS["include_directory"]
|
||||
)
|
||||
run_command(OUTPUT_FILE)
|
||||
|
||||
exit(EXIT_SUCCESS)
|
||||
|
Loading…
Reference in New Issue
Block a user