...
This commit is contained in:
parent
f6aac26bbb
commit
3576135011
@ -1,6 +1,9 @@
|
||||
import pyudev
|
||||
import signal
|
||||
import logging
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def on_usb_attached(device):
|
||||
print(f"USB device attached: {device.device_node or device.sys_name}")
|
||||
@ -31,9 +34,16 @@ def signal_handler(sig, frame):
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
|
||||
try:
|
||||
CURRENT_NODE_NAME=os.environ['CURRENT_NODE_NAME']
|
||||
logging.info(f"Starging USB-watch on {CURRENT_NODE_NAME}")
|
||||
except KeyError:
|
||||
logging.error('Environment variabel CURRENT_NODE_NAME is not set')
|
||||
sys.exit(1)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
list_current_usb_devices()
|
||||
print("Monitoring USB devices. Press Ctrl+C to exit.\n")
|
||||
logging.info("Monitoring USB device changes......")
|
||||
|
||||
monitor_usb()
|
||||
|
Loading…
x
Reference in New Issue
Block a user