1- #!/usr/bin/env python3
1+ #!/usr/bin/python3
22# Used to check cameras before commiting to install
33# Executed before primary apt install of files
44
@@ -35,7 +35,7 @@ if "install" not in sys.argv:
3535 sys .exit (0 )
3636
3737# The default picked video device id
38- picked = - 1
38+ picked = "none"
3939
4040print (col (1 ) + "Starting IR camera check...\n " + col (0 ))
4141
@@ -45,64 +45,62 @@ if "HOWDY_NO_PROMPT" in os.environ:
4545
4646 # Write the default device to disk and exit
4747 with open ("/tmp/howdy_picked_device" , "w" ) as out_file :
48- out_file .write ("0 " )
48+ out_file .write ("none " )
4949
5050 sys .exit (0 )
5151
5252# Get all devices
53- devices = os .listdir ("/dev" )
53+ devices = os .listdir ("/dev/v4l/by-path " )
5454
5555# Loop though all devices
5656for dev in devices :
57- # Only use the video devices
58- if (dev [:5 ] == "video" ):
59- time .sleep (.5 )
60-
61- # The full path to the device is the default name
62- device_name = "/dev/" + dev
63- # Get the udevadm details to try to get a better name
64- udevadm = subprocess .check_output (["udevadm info -r --query=all -n " + device_name ], shell = True ).decode ("utf-8" )
65-
66- # Loop though udevadm to search for a better name
67- for line in udevadm .split ("\n " ):
68- # Match it and encase it in quotes
69- re_name = re .search ('product.*=(.*)$' , line , re .IGNORECASE )
70- if re_name :
71- device_name = '"' + re_name .group (1 ) + '"'
72-
73- # Show what device we're using
74- print ("Trying " + device_name )
75-
76- # Let fswebcam keep the camera open in the background
77- sub = subprocess .Popen (["fswebcam -S 9999999999 -d /dev/" + dev + " /dev/null 2>/dev/null" ], shell = True , preexec_fn = os .setsid )
78-
79- try :
80- # Ask the user if this is the right one
81- print (col (2 ) + "One of your cameras should now be on." + col (0 ))
82- ans = input ("Did your IR emitters turn on? [y/N]: " )
83- except KeyboardInterrupt :
84- # Kill fswebcam if the user aborts
85- os .killpg (os .getpgid (sub .pid ), signal .SIGTERM )
86- raise
87-
88- # The user has answered, kill fswebcam
57+ time .sleep (.5 )
58+
59+ # The full path to the device is the default name
60+ device_name = "/dev/v4l/by-path/" + dev
61+ # Get the udevadm details to try to get a better name
62+ udevadm = subprocess .check_output (["udevadm info -r --query=all -n " + device_name ], shell = True ).decode ("utf-8" )
63+
64+ # Loop though udevadm to search for a better name
65+ for line in udevadm .split ("\n " ):
66+ # Match it and encase it in quotes
67+ re_name = re .search ('product.*=(.*)$' , line , re .IGNORECASE )
68+ if re_name :
69+ device_name = '"' + re_name .group (1 ) + '"'
70+
71+ # Show what device we're using
72+ print ("Trying " + device_name )
73+
74+ # Let fswebcam keep the camera open in the background
75+ sub = subprocess .Popen (["streamer -t 1:0:0 -c /dev/v4l/by-path/" + dev + " -b 16 -f rgb24 -o /dev/null 1>/dev/null 2>/dev/null" ], shell = True , preexec_fn = os .setsid )
76+
77+ try :
78+ # Ask the user if this is the right one
79+ print (col (2 ) + "One of your cameras should now be on." + col (0 ))
80+ ans = input ("Did your IR emitters turn on? [y/N]: " )
81+ except KeyboardInterrupt :
82+ # Kill fswebcam if the user aborts
8983 os .killpg (os .getpgid (sub .pid ), signal .SIGTERM )
84+ raise
85+
86+ # The user has answered, kill fswebcam
87+ os .killpg (os .getpgid (sub .pid ), signal .SIGTERM )
9088
91- # Set this camera as picked if the answer was yes, go to the next one if no
92- if ans .lower ().strip () == "y" or ans .lower ().strip () == "yes" :
93- picked = dev [ 5 :]
94- break
95- else :
96- print ("Interpreting as a " + col (3 ) + "\" NO\" \n " + col (0 ))
89+ # Set this camera as picked if the answer was yes, go to the next one if no
90+ if ans .lower ().strip () == "y" or ans .lower ().strip () == "yes" :
91+ picked = dev
92+ break
93+ else :
94+ print ("Interpreting as a " + col (3 ) + "\" NO\" \n " + col (0 ))
9795
9896# Abort if no camera was picked
99- if picked == - 1 :
97+ if picked == "none" :
10098 print (col (3 ) + "No suitable IR camera found, aborting install." + col (0 ))
10199 sys .exit (23 )
102100
103101# Write the result to disk so postinst can have a look at it
104102with open ("/tmp/howdy_picked_device" , "w" ) as out_file :
105- out_file .write (str ( picked ) )
103+ out_file .write ("/dev/v4l/by-path/" + picked )
106104
107105# Add a line break
108106print ("" )
0 commit comments