def start_udev_monitoring():
    #Setting up Linux UDEV monitoring in a separate thread
    context = Context()
    monitor = Monitor.from_netlink(context)
    monitor.filter_by(subsystem='block')
    observer = MonitorObserver(monitor, callback=find_garmin, name='monitor-observer')
    observer.daemon = True
    observer.start()
Beispiel #2
0
def handle_print_usb_events():
    def print_usb_events(action, device):
        string_to_print = '{} - {}'.format(action, device)
        for key in device.keys():
            string_to_print += '\n    {}: {}'.format(key, device.get(key, ''))
        print(string_to_print)

    # Setup the code for monitoring USB events
    context = Context()
    monitor = Monitor.from_netlink(context)
    monitor.filter_by(subsystem='usb')

    observer = MonitorObserver(monitor,
                               print_usb_events,
                               name='kamvas-usb-monitor')

    # This is needed to prevent the main thread from finishing which would close the process
    # and nothing will be displayed
    observer.daemon = False

    # Start monitoring USB events asynchronously
    observer.start()
def run_main():
    global args
    args = get_args()

    # Setup the code for monitoring USB events
    context = Context()
    monitor = Monitor.from_netlink(context)
    monitor.filter_by(subsystem='usb')

    # Start monitoring USB events asynchronously
    observer = MonitorObserver(monitor,
                               handle_usb_event,
                               name='monitor-observer')
    observer.daemon = False
    observer.start()

    # Try to start the driver. It will raise an error if the USB device is not available
    try:
        evdev_is_running = True
        run_evdev()
    except:
        if not args['--quiet-mode']:
            print('Error occured')
        evdev_is_running = False
Beispiel #4
0
 def run(self):
     observer = MonitorObserver(monitor, self.udev_action)
     observer.daemon = True
     observer.start()