-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathutils.py
More file actions
60 lines (51 loc) · 1.75 KB
/
Copy pathutils.py
File metadata and controls
60 lines (51 loc) · 1.75 KB
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
"""
Utility functions for OpenArc CLI.
"""
import os
from pathlib import Path
def validate_model_path(model_path):
"""
Validate that model_path contains OpenVINO model files.
Checks for at least one file with "_model.bin" and one file with "_model.xml" in filename.
Returns True if valid, False otherwise.
"""
path = Path(model_path)
# Resolve the path
if not path.exists():
return False
# Determine search directory - if path is a file, use its parent; if directory, use it
if path.is_file():
search_dir = path.parent
else:
search_dir = path
if not search_dir.is_absolute():
# Search relative to the config file directory
config_file = get_config_file_path()
search_dir = (config_file.parent / search_dir).resolve()
# Check for required files
has_bin = False
has_xml = False
try:
for file_path in search_dir.rglob("*"):
if file_path.is_file():
filename = file_path.name
if "_model.bin" in filename:
has_bin = True
if "_model.xml" in filename:
has_xml = True
if has_bin and has_xml:
return True
except (OSError, PermissionError):
return False
return False
def get_config_file_path():
"""
Get the path to the config file, checking the OPENARC_CONFIG_FILE environment variable first,
then defaulting to openarc_config.json in the project root.
"""
env_path = os.environ.get("OPENARC_CONFIG_FILE")
if env_path:
return Path(env_path)
else:
project_root = Path(__file__).parent.parent.parent
return project_root / "openarc_config.json"