generated from dopt-python/py311
update CLI with loading animation, closes #13
This commit is contained in:
parent
04a75838e6
commit
00214c3b1e
9
cli.py
9
cli.py
@ -3,6 +3,8 @@ import dataclasses as dc
|
||||
import sys
|
||||
from typing import cast
|
||||
|
||||
from dopt_basics import cli
|
||||
|
||||
from dopt_sensor_anomalies import _interface
|
||||
|
||||
|
||||
@ -34,11 +36,18 @@ def main() -> int:
|
||||
)
|
||||
args = cast(CliArgs, parser.parse_args())
|
||||
|
||||
with cli.LoadingAnimation(
|
||||
"Perform anomaly detection...",
|
||||
"Pipeline ended successfully!",
|
||||
) as loader:
|
||||
status = _interface.sensor_anomalies_detection(
|
||||
args.img_path,
|
||||
args.calib_value_x,
|
||||
args.calib_value_y,
|
||||
)
|
||||
if status != 0:
|
||||
loader.stop(interrupt=True)
|
||||
|
||||
sys.exit(status)
|
||||
|
||||
|
||||
|
||||
58
cli_mocked.py
Normal file
58
cli_mocked.py
Normal file
@ -0,0 +1,58 @@
|
||||
import argparse
|
||||
import dataclasses as dc
|
||||
import sys
|
||||
from typing import cast
|
||||
from unittest.mock import patch
|
||||
|
||||
from dopt_basics import cli
|
||||
|
||||
from dopt_sensor_anomalies import _interface
|
||||
|
||||
|
||||
@dc.dataclass()
|
||||
class CliArgs:
|
||||
img_path: str
|
||||
calib_value_x: float
|
||||
calib_value_y: float
|
||||
|
||||
|
||||
@patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "src")
|
||||
@patch("dopt_sensor_anomalies._find_paths.MODEL_FOLDER_NAME", "tests/_models")
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description=("simple CLI tool to analyse single sensor images for anomalies")
|
||||
)
|
||||
parser.add_argument(
|
||||
"img_path",
|
||||
help="file path to the image which is to be analysed",
|
||||
type=str,
|
||||
)
|
||||
parser.add_argument(
|
||||
"calib_value_x",
|
||||
help="calibration value in pixels per mcm for x axis, type: float",
|
||||
type=float,
|
||||
)
|
||||
parser.add_argument(
|
||||
"calib_value_y",
|
||||
help="calibration value in pixels per mcm for y axis, type: float",
|
||||
type=float,
|
||||
)
|
||||
args = cast(CliArgs, parser.parse_args())
|
||||
|
||||
with cli.LoadingAnimation(
|
||||
"Perform anomaly detection...",
|
||||
"Pipeline ended successfully!",
|
||||
) as loader:
|
||||
status = _interface.sensor_anomalies_detection(
|
||||
args.img_path,
|
||||
args.calib_value_x,
|
||||
args.calib_value_y,
|
||||
)
|
||||
if status != 0:
|
||||
loader.stop(interrupt=True)
|
||||
|
||||
sys.exit(status)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@ -23,7 +23,7 @@ def _print_error_state(
|
||||
f"\nType: {state.ExceptionType.__name__}\nDescription: {state.description}\n"
|
||||
f"Message: {state.message}"
|
||||
)
|
||||
print(msg, flush=True, file=out_stream)
|
||||
print(f"\r{msg}", flush=True, file=out_stream)
|
||||
|
||||
|
||||
def sensor_anomalies_detection(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user