コード例 #1
0
ファイル: hidraw.py プロジェクト: FFY00/logitechd
    def _setup_udev(self) -> None:
        '''Setup UDEV and register observers to look for devices and populate the device tree'''
        udev_context = pyudev.Context()

        # register parent monitor
        self._monitor_usb = pyudev.Monitor.from_netlink(udev_context)
        self._monitor_usb.filter_by('usb')
        self._observer_usb = pyudev.MonitorObserver(self._monitor_usb,
                                                    self._event_handler_parent)

        # register child monitor
        self._monitor_hidraw = pyudev.Monitor.from_netlink(udev_context)
        self._monitor_hidraw.filter_by('hidraw')
        self._observer_hidraw = pyudev.MonitorObserver(
            self._monitor_hidraw, self._event_handler_hidraw)

        # trigger the parent event handler manually for initial population
        for device in udev_context.list_devices(subsystem='usb'):
            self._event_handler_parent('add', device)

        self.__logger.info('Device tree populated:')
        for line in self._tree.show(stdout=False).splitlines():
            self.__logger.info('\t' + line)

        # start observers
        self._observer_usb.start()
        self._observer_hidraw.start()
コード例 #2
0
def WaitMaximUsbBootloader(msec_timeout):
    import pyudev

    global maxim_device
    maxim_device = None

    def device_event(action, device):
        global maxim_device
        device_dict = dict(device)

        sys.stdout.write("Get tty device: %s" % device_dict["DEVNAME"])
        if device_dict["ID_MODEL_ID"] != "0625" and device_dict[
                "ID_VENDOR_ID"] != "0b6a":
            print(", it's not maxim bootloader, wait")
            return
        print(" => maxim device")
        maxim_device = device_dict["DEVNAME"]

    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by(subsystem='tty')

    observer = pyudev.MonitorObserver(monitor, device_event)
    observer.start()

    while msec_timeout > 0 and maxim_device is None:
        time.sleep(0.001)
        msec_timeout -= 1

    observer.stop()
    return maxim_device
コード例 #3
0
ファイル: device_manager.py プロジェクト: blockjoe/oversteer
 def start(self):
     context = pyudev.Context()
     monitor = pyudev.Monitor.from_netlink(context)
     monitor.filter_by('input')
     self.observer = pyudev.MonitorObserver(monitor, self.register_event)
     self.init_device_list()
     self.observer.start()
コード例 #4
0
    def __init__(self, filename, verbose=False):
        """Init SystemManager things."""
        super(SystemManager, self).__init__()

        # check for filename
        if not os.path.exists(filename):
            # print(
            #     "filename does not exists.. "
            #     "so we creating a hopefully valid path"
            # )
            # remember config file name
            config_name = os.path.basename(filename)
            # create path on base of script dir.
            # path_to_config = os.path.join(self.path_script, "config")
            path_to_config = self.path_script
            filename = os.path.join(path_to_config, config_name)

        # read config file:
        self.my_config = configdict.ConfigDict(self.default_config, filename)
        # print("my_config.config: {}".format(self.my_config.config))
        self.config = self.my_config.config
        # print("config: {}".format(self.config))

        self.verbose = verbose
        if self.verbose:
            print("config: {}".format(
                json.dumps(self.config,
                           sort_keys=True,
                           indent=4,
                           separators=(',', ': '))))

        # generate absolute path to config files
        path_to_config = os.path.dirname(filename)
        self.config["path_to_config"] = path_to_config

        self.context = pyudev.Context()
        self.monitor = pyudev.Monitor.from_netlink(self.context)
        self.monitor.filter_by('block', device_type="partition")
        self.observer = pyudev.MonitorObserver(self.monitor,
                                               self._even_partition)

        self.mode = None

        self.stick_dict = {}

        self.queue_devices = queue.Queue()
        self.device_handler_thread = threading.Thread(
            target=self.device_handler)

        self.queue_sticks = queue.Queue()
        self.stick_messages = {}
        # init stick_messages with '?'
        for device_path, port_number in self.config['port_map'].items():
            self.stick_messages[port_number] = '?'
        self.stick_messages_thread = threading.Thread(
            target=self.stick_messages_handler)

        if self.verbose:
            print("--> finished.")
            print("config: {}".format(self.config))
コード例 #5
0
def detect_screens(qtile):
    """
    Detect if a new screen is plugged and reconfigure/restart qtile
    """
    def setup_monitors(action=None, device=None):
        """
        Add 1 group per screen
        """

        if action == "change":
            # setup monitors with xrandr
            # call("setup_screens")
            lazy.restart()

        nbr_screens = len(qtile.conn.pseudoscreens)
        for i in xrange(0, nbr_screens - 1):
            groups.append(Group('h%sx' % (i + 5), persist=False))

    setup_monitors()

    import pyudev

    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by('drm')
    monitor.enable_receiving()

    # observe if the monitors change and reset monitors config
    observer = pyudev.MonitorObserver(monitor, setup_monitors)
    observer.start()
コード例 #6
0
    def __init__(self):
        super().__init__()

        # lazy/conditional loading of needed modules
        import pyudev
        import queue

        DBG('Using pyudev {} and udev {}'.format(
             pyudev.__version__, pyudev.udev_version()))

        # create the udev context
        self.udev = pyudev.Context()

        # queue + timer to syncronize the udev thread
        self.queue = queue.Queue()  # items: (action, device)
        self.qtimer = EmcTimer(3.0, self.queue_timer_cb)

        # start monitoring udev for events
        monitor = pyudev.Monitor.from_netlink(self.udev)
        monitor.filter_by(self.managed_subsystems)
        self.observer = pyudev.MonitorObserver(monitor, self.udev_device_filter)
        self.observer.start()

        # search for existing devices
        for udevice in self.udev.list_devices(subsystem=self.managed_subsystems):
            self.udev_device_filter('add', udevice, thread=False)
        self.queue_timer_cb()
コード例 #7
0
    def __init__(self):
        context = pyudev.Context()
        monitor = pyudev.Monitor.from_netlink(context)

        observer = pyudev.MonitorObserver(monitor, callback=self.notify, name='udev_notk')

        observer.start()
コード例 #8
0
ファイル: sriov_config.py プロジェクト: wmousa/os-net-config
def udev_monitor_setup():
    # Create a context for pyudev and observe udev events for network
    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by('net')
    observer = pyudev.MonitorObserver(monitor, udev_event_handler)
    return observer
コード例 #9
0
 def __init__(self, status, recursive=False):
     super(USBMonitor, self).__init__(status)
     self.recursive = recursive
     self.context = pyudev.Context()
     self.monitor = pyudev.Monitor.from_netlink(self.context)
     self.observer = pyudev.MonitorObserver(self.monitor,
                                            self.handle_event)
コード例 #10
0
ファイル: autocompile.py プロジェクト: diarmuid/SBC
 def _setupObserver(self):
     self.context = pyudev.Context()
     self.monitor = pyudev.Monitor.from_netlink(self.context)
     self.monitor.filter_by('block')
     self.observer = pyudev.MonitorObserver(self.monitor,
                                            self._handle_drive)
     self.observer.start()
コード例 #11
0
    def __init__(self):
        super(Monitor, self).__init__()

        # Put data from db into memory
        self.db = JsonDBTool()
        devices = self.db.get_all()
        self.devices = {}

        for device in devices:
            id = device.get('device_id', '')
            if id != '':
                action = device.get('device_action')
                name = device.get('device_name')
                d = USBDevice(id, name, action=action)
                d.action_changed.connect(self.device_registered)
                d.active_toggled.connect(self.device_toggled)
                self.devices[id] = d

        self.udev_context = pyudev.Context()
        self.udev_monitor = pyudev.Monitor.from_netlink(self.udev_context)
        self.udev_monitor.filter_by(subsystem='usb')
        self.udev_observer = pyudev.MonitorObserver(self.udev_monitor,
                                                    handle_udev_event)

        self.app = USBManagerApp()

        # For multiprocessing app and monitor
        # self.queue = Queue()
        # self.app.process = Process(target=self.app.run)

        self.finished = False
コード例 #12
0
ファイル: udevwatch.py プロジェクト: JGodin-C2C/lvm2
def add():
	global observer
	context = pyudev.Context()
	monitor = pyudev.Monitor.from_netlink(context)
	monitor.filter_by('block')
	observer = pyudev.MonitorObserver(monitor, filter_event)
	observer.start()
コード例 #13
0
def _StartUdevMonitor():
    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by(subsystem='block', device_type='disk')
    monitor.set_receive_buffer_size(128 * 1024 * 1024)
    observer = pyudev.MonitorObserver(monitor, _UDevDiskEvent)
    observer.start()
コード例 #14
0
ファイル: Display.py プロジェクト: mhetzi/mqttRaspberry
    def start(self, context: pyudev.Context):
        super().start(context)
        if self._observer is None or self._observer.is_alive():
            self._monitor = pyudev.Monitor.from_netlink(context=context)
            self._monitor.filter_by("drm")
            self._observer = pyudev.MonitorObserver(self._monitor, self.event)
            self._observer.name = "UdevDRM"
            self._observer.start()
            self._log.info("UDEV Observer started!")

        updated = False
        try:
            r_web = pyedid.Registry.from_web()
            if len(r_web) > 0:
                pyedid.DEFAULT_REGISTRY = r_web
            # Save fresh registry to disk
            if self._config is not None:
                pyedid.DEFAULT_REGISTRY.to_csv(
                    str(
                        self._config.getIndependendPath(
                            "EDID_Registry.csv").absolute()))
            updated = True
            self._log.info("EDID Registry aktualisiert")
        except:
            self._log.exception("Error updateing EDID Registry")

        if not updated:
            if self._config is not None:
                r_csv = pyedid.Registry.from_csv(
                    str(
                        self._config.getIndependendPath(
                            "EDID_Registry.csv").absolute()))
                pyedid.DEFAULT_REGISTRY = r_csv
コード例 #15
0
def create_observer(monitor, callback, name):
    """
    This method is needed in order to support different versions of pyudev.
    The 'callback' parameter has been introduced in 0.16.
    TODO: Remove when using pyudev >= 0.16 on all platforms.
    """
    argspec = inspect.getargspec(pyudev.MonitorObserver.__init__)
    if "callback" in argspec.args:
        # pylint: disable=no-value-for-parameter
        return pyudev.MonitorObserver(monitor, callback=callback, name=name)
    else:

        def event_handler(action, device):
            callback(device)

        return pyudev.MonitorObserver(monitor, event_handler, name=name)
コード例 #16
0
ファイル: config.py プロジェクト: shizonic/my-machines
    def __init__(self, **config):
        super().__init__(markup=True, **config)
        self.add_defaults(RFKillWidget.defaults)
        if self.device_name not in ["WLAN", "BT"]:
            raise Exception("Invalid device_name")

        ctx = pyudev.Context()
        rfkill_paths = [
            "/sys/class/rfkill/" + os.readlink('/sys/class/rfkill/' + name)
            for name in os.listdir('/sys/class/rfkill')
        ]
        print(rfkill_paths)
        devices = [
            pyudev.Devices.from_path(ctx, os.path.abspath(path))
            for path in rfkill_paths
            if self.DEV_NAME_MAP[self.device_name] in path
        ]

        if len(devices) != 1:
            raise Exception("no or too many devices")

        self._dev = devices[0]
        monitor = pyudev.Monitor.from_netlink(ctx)
        monitor.filter_by('rfkill')
        observer = pyudev.MonitorObserver(monitor, self._udev_callback)
        observer.start()
        self.text = self._get_text()
コード例 #17
0
    def __init__(self, callback=None, logger=logging):
        context = pyudev.Context()
        monitor = pyudev.Monitor.from_netlink(context)
        monitor.filter_by(subsystem='usb', device_type='usb_device')

        self._log = logger
        self.observer = pyudev.MonitorObserver(monitor=monitor, callback=callback)
コード例 #18
0
ファイル: hotplug.py プロジェクト: molejar/imxsb
 def start(self):
     assert self.callback is not None, ""
     self.callback()
     self.observer = pyudev.MonitorObserver(self.monitor,
                                            callback=self.callback,
                                            name='monitor-observer')
     self.observer.start()
コード例 #19
0
ファイル: __init__.py プロジェクト: nymann/kvm-switcher
 def __init__(self, extra_monitor: str, verbose: bool = False):
     self.extra_monitor = extra_monitor
     self.verbose = verbose
     context = pyudev.Context()
     monitor = pyudev.Monitor.from_netlink(context)
     monitor.filter_by(subsystem='usb')
     self.observer = pyudev.MonitorObserver(monitor=monitor,
                                            event_handler=self._watch)
コード例 #20
0
    def monitor(self, paranoid, screensaver):
        operating_system = platform.system().lower()

        if operating_system in settings.get_supported_operating_systems():
            monitor, context = self.initialise_pyudev()
            if screensaver == 'xscreensaver':
                screensaver_monitor = os.popen('xscreensaver-command -watch')
                observer = pyudev.MonitorObserver(
                    monitor,
                    callback=self.set_device_event,
                    name='monitor-observer')
                if paranoid:
                    observer.start()
                    settings.print_message('Observer started')
                elif not paranoid:
                    while True:
                        line = screensaver_monitor.readline()

                        if line.startswith('LOCK'):
                            observer.start()
                            settings.print_message('Observer started')

                        if line.startswith('UNLOCK'):
                            settings.print_message('Observer stopped')
                            observer.join()
                else:
                    sys.exit(127)
            elif screensaver == 'gnome-screensaver':
                if paranoid:
                    observer = pyudev.MonitorObserver(
                        monitor,
                        callback=self.set_device_event,
                        name='monitor-observer')
                    observer.start()
                    settings.print_message('Observer started')
                    time.sleep(2)
                elif not paranoid:
                    observer = pyudev.MonitorObserver(monitor,
                                                      callback=send_message,
                                                      name='monitor-observer')
                    observer.start()
                    settings.print_message('Observer started')
                else:
                    sys.exit(127)
            else:
                sys.exit(126)
コード例 #21
0
 def __init__(self, usbCheck):
     """ Runs the actual loop to detect the events """
     # print("init usbdetector")
     self.context = pyudev.Context()
     self.monitor = pyudev.Monitor.from_netlink(self.context)
     self.monitor.filter_by(subsystem='usb')
     self.observer = pyudev.MonitorObserver(self.monitor, usbCheck)
     self.observer.start()
コード例 #22
0
ファイル: automount.py プロジェクト: tmeiczin/pyautomount
 def start_monitor(self):
     context = pyudev.Context()
     monitor = pyudev.Monitor.from_netlink(context)
     monitor.filter_by(subsystem='block')
     observer = pyudev.MonitorObserver(monitor,
                                       callback=self.handler,
                                       name='monitor-observer')
     observer.start()
コード例 #23
0
def __x():
    import pyudev
    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by('drm')
    monitor.enable_receiving()
    observer = pyudev.MonitorObserver(monitor, setup_monitors)
    observer.start()
コード例 #24
0
ファイル: udevlistener.py プロジェクト: werpu/input_pipe
    def __init__(self, ev_ctl):
        context = pyudev.Context()
        monitor = pyudev.Monitor.from_netlink(context)
        monitor.filter_by("usb")

        monitor2 = pyudev.Monitor.from_netlink(context)
        monitor2.filter_by("input")

        self.config = ev_ctl.config
        self.ev_ctl = ev_ctl
        self.restarting = False
        self.observer = pyudev.MonitorObserver(monitor,
                                               self._usb_event_handler)
        self.observer2 = pyudev.MonitorObserver(monitor,
                                                self._input_event_handler)
        self.observer.start()
        self.observer2.start()
コード例 #25
0
 def __init__(self,master):
     self.master=master
     self.context = pyudev.Context()
     self.monitor = pyudev.Monitor.from_netlink(self.context)
     self.monitor.filter_by('block')
     self.observer = pyudev.MonitorObserver(self.monitor,self.log_event)
     self.observer.start()
     pass
コード例 #26
0
def main():
    # Main observer daemon
    context = pyudev.Context()
    umonitor = pyudev.Monitor.from_netlink(context)
    umonitor.filter_by(subsystem='block', device_type='disk')
    uobserver = pyudev.MonitorObserver(umonitor, callback=check_for_CDDA)
    uobserver.daemon = False  # set False will block the process when started.
    uobserver.start()
コード例 #27
0
    def start(self):
        context = udev.Context()
        monitor = udev.Monitor.from_netlink(context)
        monitor.filter_by('input')

        self.observer = udev.MonitorObserver(monitor,
                                             callback=self._monitor_callback)
        self.observer.start()
        logging.debug("device_monitor started")
コード例 #28
0
 def _setup_pyudev_monitoring(self):
     """
     Setup the udev monitor.
     """
     context = pyudev.Context()
     monitor = pyudev.Monitor.from_netlink(context)
     self.udev_observer = pyudev.MonitorObserver(monitor, self._udev_event)
     self.udev_observer.start()
     self.py3_wrapper.log("udev monitoring enabled")
コード例 #29
0
 def __init__(self):
     """ Initiate the object """
     self.context = pyudev.Context()
     monitor = pyudev.Monitor.from_netlink(self.context)
     # device_type should filter out interfaces
     monitor.filter_by(subsystem='usb', device_type='usb_device')
     # Not using the Qt binding as there is no reason to tie this to the GUI.
     self.observer = pyudev.MonitorObserver(monitor, self._handler)
     self.listeners = set()
コード例 #30
0
 def __init__(self, context: pyudev.Context = pyudev.Context()):
     self._context = context
     self._map = {}
     self._map_lock = threading.RLock()
     self._monitor = pyudev.Monitor.from_netlink(context)
     self._monitor.filter_by('input')
     self._observer = observer = pyudev.MonitorObserver(self._monitor, self._on_device_change, name='DeviceChangeMonitorChange')
     self._observer.start()
     self.update_devices()