-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdetect.py
72 lines (58 loc) · 2.27 KB
/
detect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
OTVision script to call the detect main with arguments parsed from command line
"""
# Copyright (C) 2022 OpenTrafficCam Contributors
# <https://github.com/OpenTrafficCam
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from pathlib import Path
from OTVision.config import Config
from OTVision.detect.builder import DetectBuilder
from OTVision.detect.detect import OTVisionDetect
from OTVision.helpers.files import check_if_all_paths_exist
def main(argv: list[str] | None = None) -> None: # sourcery skip: assign-if-exp
builder = DetectBuilder(argv=argv)
cli_args = builder.detect_cli_parser.parse()
config = builder.update_detect_config_with_ci_args.update(
config=builder.get_config.get(cli_args)
)
log = builder.configure_logger.configure(
config,
log_file=cli_args.logfile,
logfile_overwrite=cli_args.logfile_overwrite,
)
log.info("Call detect from command line")
log.info(f"Arguments: {vars(cli_args)}")
try:
detect = OTVisionDetect(otdet_builder=builder.otdet_builder)
detect.update_config(config)
detect.start()
except FileNotFoundError:
log.exception(f"One of the following files cannot be found: {cli_args.paths}")
raise
except Exception:
log.exception("")
raise
def _extract_paths(config: Config) -> list[Path]:
if paths := config.detect.paths:
converted = [Path(path) for path in paths]
check_if_all_paths_exist(converted)
return converted
raise IOError(
"No paths have been passed as command line args."
"No paths have been defined in the user config."
)
if __name__ == "__main__":
main()