예제 #1
0
    def run(self):
        try:
            try:
                from pyudev.glib import MonitorObserver

                def device_event(observer, device):
                    self.sessaoMultiseat.evento_dispositivo(
                        device.action, device.device_path)
            except:
                from pyudev.glib import GUDevMonitorObserver as MonitorObserver

                def device_event(observer, action, device):
                    self.sessaoMultiseat.evento_dispositivo(
                        action, device.device_path)

            context = Context()
            monitor = Monitor.from_netlink(context)

            #monitor.filter_by(subsystem='usb');
            observer = MonitorObserver(monitor)

            observer.connect('device-event', device_event)
            monitor.start()

            self.loop.run()
        except:
            logging.exception('')
예제 #2
0
 def __init__(self):
     from pyudev.glib import MonitorObserver
     GObject.GObject.__init__(self)
     self.context = pyudev.Context()
     self.monitor = pyudev.Monitor.from_netlink(self.context)
     self.monitor.filter_by(subsystem='sound')
     self.observer = MonitorObserver(self.monitor)
     self.observer.connect('device-event', self.__device_event)
예제 #3
0
def get_usb_devices():
    context = Context()
    monitor = Monitor.from_netlink(context)
    monitor.filter_by(subsystem='usb')
    observer = MonitorObserver(monitor)
    observer.connect('device-event', device_event)
    monitor.start()
    glib.MainLoop().run()
예제 #4
0
def monitor():
    context = Context()
    monitor = Monitor.from_netlink(context)
    monitor.filter_by(subsystem='usb')
    observer = MonitorObserver(monitor)
    observer.connect('device-removed', remove_event)
    observer.connect('device-added', add_event)
    monitor.start()
    glib.MainLoop().run()
예제 #5
0
def main():
    """ main() -- entry point for this program
    """
    global SEND_SMS
    global DAEMONIZE
    global PID_FILE

    # Parse CLI options
    args = parse_cli()

    DAEMONIZE = args.daemonize
    PID_FILE = args.pid_file
    SEND_SMS = args.sms

    context = Context()

    # Populate list of current USB devices
    for device in context.list_devices(subsystem="usb"):
        busnum = get_device_info(device, "busnum")
        devnum = get_device_info(device, "devnum")
        id_product = get_device_info(device, "idProduct")
        id_vendor = get_device_info(device, "idVendor")
        manufacturer = get_device_info(device, "manufacturer")
        product = get_device_info(device, "product")

        if busnum:
            USB_DEVICES.append((device.device_path, busnum, devnum, id_vendor,
                                id_product, manufacturer, product))

    monitor = Monitor.from_netlink(context)

    monitor.filter_by(subsystem='usb')
    observer = MonitorObserver(monitor)

    observer.connect('device-event', device_event)
    monitor.start()

    if DAEMONIZE:
        usbwatch_pid = os.fork()

        if usbwatch_pid != 0:
            return os.EX_OK

    write_pid_file(PID_FILE, os.getpid())

    xprint("[+] usb-watch by Daniel Roberson @dmfroberson Started. PID %s" % \
        os.getpid())

    try:
        glib.MainLoop().run()
    except KeyboardInterrupt:
        print "[-] Caught Control-C. Andross has ordered us to take you down."
        print "[-] Exiting."

    return os.EX_OK
예제 #6
0
def loopForDevices():
    context = Context()
    monitor = Monitor.from_netlink(context)
    
    monitor.filter_by(subsystem='block',device_type='partition')
#     monitor.filter_by(subsystem='usb')
    observer = MonitorObserver(monitor)
    
    observer.connect('device-event', device_event)
    monitor.start()
    glib.MainLoop().run()
예제 #7
0
    def __init__(self):
        """
        Start listening for storage events.
        """

        context = Context()
        monitor = Monitor.from_netlink(context)

        monitor.filter_by(subsystem='block')
        monitor_observer = MonitorObserver(monitor)

        monitor_observer.connect('device-event', self._device_event)
        monitor.start()
예제 #8
0
파일: USBerry.py 프로젝트: icepaule/USBerry
def main():
	context = Context()
	monitor = Monitor.from_netlink(context)
	#monitor.filter_by(subsystem='input')
	observer = MonitorObserver(monitor)
	reload_rules()


	observer.connect('device-event', device_event)
	monitor.start()

	for device in iter(monitor.poll, None):
		print('{0.action} on {0.device_path}'.format(device))
		print('=> {0} is {2} ({1})'.format(device.device_node, device.device_type, device.driver))
예제 #9
0
 def start_usb_detection(self):
     """
     Starts listening to udev events for usb activity
     """
     try:
         #Remove comments to enable usb local update on boot
         #if os.path.exists(DEVICE_PART1):
         #    syslog("start_usb_detection: Mount point exists")
         #    self.check_mount_point()
         context = Context()
         monitor = Monitor.from_netlink(context)
         monitor.filter_by(subsystem='usb')
         observer = MonitorObserver(monitor)
         observer.connect('device-event', self.device_event)
         monitor.start()
     except Exception as e:
         syslog("usbupd:start_usb_detection: %s" % e)
예제 #10
0
def main():
    try:
        from pyudev.glib import MonitorObserver

        def device_event(observer, device):
            remap_pokerii(device)
            remap_filco(device)
    except:
        from pyudev.glib import GUDevMonitorObserver as MonitorObserver

        def device_event(observer, action, device):
            remap_pokerii(device)
            remap_filco(device)

    context = Context()
    monitor = Monitor.from_netlink(context)

    monitor.filter_by(subsystem='usb')
    observer = MonitorObserver(monitor)

    observer.connect('device-event', device_event)
    monitor.start()

    glib.MainLoop().run()
예제 #11
0
    def device_event(observer, device):
        print('\n\nevent {0} on device {1}'.format(device.action, device))
        time.sleep(3)
        print("device details", device.device_node)
        partitions = [
            device.device_node for device in context.list_devices(
                subsystem='block', DEVTYPE='partition', parent=device)
        ]
        print("All removable partitions: {}".format(", ".join(partitions)))
        print("Mounted removable partitions:")
        for p in psutil.disk_partitions():
            if p.device in partitions:
                print("  {}: {}".format(p.device, p.mountpoint))
except Exception as e:
    print("error :", e)
    from pyudev.glib import GUDevMonitorObserver as MonitorObserver

    def device_event(observer, action, device):
        print('event {0} on device {1}'.format(action, device))


monitor = Monitor.from_netlink(context)

monitor.filter_by(subsystem='usb')
observer = MonitorObserver(monitor)

observer.connect('device-event', device_event)
monitor.start()

glib.MainLoop().run()
예제 #12
0
 def create_observer(self, monitor):
     from pyudev.glib import MonitorObserver
     self.observer = MonitorObserver(monitor)