BankShot-Search / runtime /bankshot_device.py
chadstthomas's picture
Stage BankShot Search v0.1.0 research preview
fd280c7 verified
Raw History Blame Contribute Delete
1.71 kB
"""Locate the original USB stick and its separately installed Windows runtime."""
import os
from pathlib import Path
import re
import subprocess
import sys
def prepare_ncs1():
if os.name != "nt":
raise RuntimeError("This NCS1 package uses the legacy Windows runtime")
command = ("Get-PnpDevice -PresentOnly | Where-Object "
"{ $_.InstanceId -like 'USB*VID_03E7*' } | Select-Object -ExpandProperty InstanceId")
report = subprocess.run(["powershell.exe", "-NoProfile", "-NonInteractive", "-Command", command],
check=True, stdout=subprocess.PIPE, text=True, timeout=15)
ids = re.findall(r"^\s*USB\\VID_03E7&PID_([0-9A-F]{4})\\", report.stdout, re.I | re.M)
if [value.upper() for value in ids] != ["2150"]:
raise RuntimeError("Connect exactly one cold original NCS1 (USB 03E7:2150)")
default = Path("D:/NTVStudy/tools/ncs1")
path = Path(os.environ.get("BANKSHOT_NCS1_ROOT", str(default))).resolve()
openvino = path / "ov2020"
deployment = openvino / "deployment_tools"
ie = deployment / "inference_engine"
binding = openvino / "python/python3.7"
if not binding.is_dir():
raise RuntimeError("Set BANKSHOT_NCS1_ROOT to the installed OpenVINO 2020.3.2 tool directory")
dlls = (path / "redist", ie / "external/tbb/bin", ie / "bin/intel64/Release",
ie / "bin/intel64/Debug", ie / "external/hddl/bin", deployment / "ngraph/lib")
os.environ["PATH"] = os.pathsep.join(map(str, dlls)) + os.pathsep + os.environ.get("PATH", "")
sys.path[:0] = [str(binding), str(openvino / "python/python3"), str(deployment / "model_optimizer")]
return {"stick": "ncs1", "boot_usb_id": "03E7:2150"}