-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make cam_test.py available through the depthai binary. (#983)
* Expose cam_test through depthai_cli too. * Change the argument parsing to allow more checks to be done by argparse * Use subparsers for subcommands (like cam_test) to print better help. --------- Co-authored-by: Matevz Morato <[email protected]>
- Loading branch information
Showing
4 changed files
with
69 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
from pathlib import Path | ||
import subprocess | ||
|
||
here = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
if os.path.exists(os.path.join(here, "cam_test.py")): # Installed package | ||
CAM_TEST_PATH = Path(here) / "cam_test.py" | ||
else: | ||
CAM_TEST_PATH = ( | ||
Path(here) / ".." / "utilities" / "cam_test.py" | ||
) # Execution from source | ||
CAM_TEST_PATH = str(CAM_TEST_PATH) | ||
|
||
|
||
def cli() -> int: | ||
import argparse | ||
import sys | ||
import depthai as dai | ||
parser = argparse.ArgumentParser(description="DepthAI CLI", add_help=True) | ||
parser.add_argument("-v", "--version", action="store_true", help="Print version and exit.") | ||
parser.add_argument("-l", "--list-devices", action="store_true", help="List connected devices.") | ||
subparsers = parser.add_subparsers(dest="command", help="Sub-commands") | ||
# Define the parser for the "cam_test" command | ||
cam_test_parser = subparsers.add_parser("cam_test", help="Commands and options for cam_test", add_help=False) | ||
cam_test_parser.add_argument("args", nargs=argparse.REMAINDER, help="Arguments to pass to cam_test") | ||
|
||
# subparser REMINDER args would get parsed too if we used parse_args, so we have to handle unknown args manually | ||
args, unknown_args = parser.parse_known_args() | ||
if args.command == "cam_test": | ||
cam_test_path = CAM_TEST_PATH | ||
return subprocess.run([sys.executable, cam_test_path] + cam_test_parser.parse_args().args[1:]).returncode | ||
# Parse other subcommands here | ||
elif unknown_args: | ||
parser.error(f"Unrecognized arguments: {unknown_args}") # handles exit internally | ||
elif args.version: | ||
print(dai.__version__) | ||
return 0 | ||
elif args.list_devices: | ||
print(dai.Device.getAllConnectedDevices()) | ||
return 0 | ||
else: | ||
# No recognized commands, print help | ||
parser.print_help() | ||
return 1 | ||
|
||
|
||
if __name__ == "__main__": | ||
exit(cli()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters