當前位置: 首頁>>代碼示例>>Python>>正文


Python pyudev.Context方法代碼示例

本文整理匯總了Python中pyudev.Context方法的典型用法代碼示例。如果您正苦於以下問題:Python pyudev.Context方法的具體用法?Python pyudev.Context怎麽用?Python pyudev.Context使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyudev的用法示例。


在下文中一共展示了pyudev.Context方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __find_device

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def __find_device(self):
        context = Context()
        for hidraw_device in context.list_devices(subsystem="hidraw"):
            hid_device = hidraw_device.parent
            if hid_device.subsystem != "hid" or hid_device.get("HID_NAME") != "Wireless Controller":
                continue
            for child in hid_device.parent.children:
                event_device = child.get("DEVNAME", "")
                if event_device.startswith("/dev/input/event"):
                    break
            else:
                continue

            device_addr = hid_device.get("HID_UNIQ", "").upper()
            return device_addr, hidraw_device.device_node, event_device
        return None, None, None 
開發者ID:notkarol,項目名稱:derplearning,代碼行數:18,代碼來源:joystick.py

示例2: __init__

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def __init__(self, *callbacks):
        self._logger = Log.get('uchroma.devicemanager')

        self._devices = OrderedDict()
        self._monitor = False
        self._udev_context = Context()
        self._udev_observer = None
        self._callbacks = []

        if callbacks is not None:
            self._callbacks.extend(callbacks)

        self._loop = asyncio.get_event_loop()

        self.device_added = Signal()
        self.device_removed = Signal()

        self.discover() 
開發者ID:cyanogen,項目名稱:uchroma,代碼行數:20,代碼來源:device_manager.py

示例3: autoconnect

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def autoconnect():
    """Sets up a thread to detect when USB devices are plugged and unplugged.
       If the device looks like a MicroPython board, then it will automatically
       connect to it.
    """
    if not USE_AUTOCONNECT:
        return
    try:
        import pyudev
    except ImportError:
        return
    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    connect_thread = threading.Thread(target=autoconnect_thread, args=(monitor,), name='AutoConnect')
    connect_thread.daemon = True
    connect_thread.start() 
開發者ID:dhylands,項目名稱:rshell,代碼行數:18,代碼來源:main.py

示例4: disk_list

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def disk_list():
	disks = []

	context = pyudev.Context()
	for device in context.list_devices(subsystem="block"):
		if device.device_type == u"disk":
			property_dict = dict(device.items())

			if ('ID_MODEL' in property_dict):
				disk_short_name = property_dict.get('DEVNAME', "Unknown").split('/')[-1]
				disks.append(
				{
					'model':	property_dict.get('ID_MODEL', "Unknown"),
					'name':		disk_short_name,
					'size':		get_block_device_size(property_dict.get('DEVNAME', None)),
					'serial':	property_dict.get('ID_SERIAL_SHORT', "Unknown"),
				})

	return disks 
開發者ID:FireDrunk,項目名稱:ZFSmond,代碼行數:21,代碼來源:disk.py

示例5: probe

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def probe(context=None):
    """ Capture detected filesystems found on discovered block devices.  """
    filesystems = {}
    if not context:
        context = pyudev.Context()

    for device in sane_block_devices(context):
        # Ignore block major=1 (ramdisk) and major=7 (loopback)
        # these won't ever be used in recreating storage on target systems.
        if device['MAJOR'] not in ["1", "7"]:
            fs_info = get_device_filesystem(device)
            # The ID_FS_ udev values come from libblkid, which contains code to
            # recognize lots of different things that block devices or their
            # partitions can contain (filesystems, lvm PVs, bcache, ...).  We
            # only want to report things that are mountable filesystems here,
            # which libblkid conveniently tags with ID_FS_USAGE=filesystem.
            # Swap is a bit of a special case because it is not a mountable
            # filesystem in the usual sense, but subiquity still needs to
            # generate mount actions for it.
            if fs_info.get("USAGE") == "filesystem" or \
               fs_info.get("TYPE") == "swap":
                filesystems[device['DEVNAME']] = fs_info

    return filesystems 
開發者ID:canonical,項目名稱:probert,代碼行數:26,代碼來源:filesystem.py

示例6: __init__

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def __init__(self, root='/mnt/usbdrive', readonly=True):
        """Create an instance of the USB drive mounter service.  Root is an
        optional parameter which specifies the location and file name prefix for
        mounted drives (a number will be appended to each mounted drive file
        name).  Readonly is a boolean that indicates if the drives should be
        mounted as read-only or not (default false, writable).
        """
        self._root = root
        self._readonly = readonly
        self._context = pyudev.Context() 
開發者ID:adafruit,項目名稱:pi_video_looper,代碼行數:12,代碼來源:usb_drive_mounter.py

示例7: smart

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def smart():
    c = statsd.StatsClient(STATSD_HOST, 8125, prefix=PREFIX + 'system.smart')
    context = pyudev.Context()
    devices = list()

    for device in context.list_devices(MAJOR='8'):
        if device.device_type == 'disk':
            devices.append(device.device_node)

    while True:
        for device in devices:
            try:
                process = subprocess.Popen([
                    'sudo', 'smartctl', '--attributes',
                    '-d', 'sat+megaraid,0', device
                ], stdout=subprocess.PIPE)

                out, _ = process.communicate()
                out = str(out, 'utf-8').strip()
                out = out.split('\n')
                out = out[7:-2]

                for line in out:
                    try:
                        line = line.split()[0:10]
                        key = '{}.{}_{}'.format(device.split('/')[-1], line[1], line[0])
                        value = int(float(line[-1]))
                        c.gauge(key, value)
                    except Exception as inner_e:
                        print('could not parse line: {}\n{}'.format(str(inner_e), line))
            except Exception as e:
                print('error: %s' % str(e))
        time.sleep(GRANULARITY * 6) 
開發者ID:thenetcircle,項目名稱:dino,代碼行數:35,代碼來源:statsd-agent.py

示例8: udev_monitor_setup

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
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 
開發者ID:openstack,項目名稱:os-net-config,代碼行數:9,代碼來源:sriov_config.py

示例9: reset

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def reset(self):
        self.devices = {}

        context = pyudev.Context()
        for device in context.list_devices(subsystem='input', ID_INPUT_JOYSTICK=1):
            if device.get('ID_VENDOR_ID') == '046d' and device.get('ID_MODEL_ID') in self.supported_models:
                self.add_udev_data(device)

        logging.debug('Devices:' + str(self.devices)) 
開發者ID:berarma,項目名稱:oversteer,代碼行數:11,代碼來源:wheels.py

示例10: wait_for_device

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def wait_for_device(self, device_id):
        context = pyudev.Context()
        monitor = pyudev.Monitor.from_netlink(context)
        monitor.filter_by('input')
        for device in iter(functools.partial(monitor.poll, 2), None):
            if device.action == 'add' and device.get('ID_FOR_SEAT') == device_id:
                self.add_udev_data(device) 
開發者ID:berarma,項目名稱:oversteer,代碼行數:9,代碼來源:wheels.py

示例11: get_serial_from_node

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def get_serial_from_node(device_node):
    try:
        context = pyudev.Context()

        for device in context.list_devices(subsystem="tty"):
            if device.device_node == device_node:
                return device.get("ID_SERIAL")
    except:
        # We weren't able to use pyudev (possibly because of an invalid operating system)
        pass
    return None


# get_node_from_serial() takes a udev serial number, and retuns the associated node (if found) 
開發者ID:thorrak,項目名稱:fermentrack,代碼行數:16,代碼來源:udev_integration.py

示例12: get_node_from_serial

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def get_node_from_serial(device_serial):
    try:
        context = pyudev.Context()

        for device in context.list_devices(subsystem="tty"):
            if device.get("ID_SERIAL", "") == device_serial:
                return device.device_node
    except:
        # We weren't able to use pyudev (possibly because of an invalid operating system)
        pass
    return None


# The following was used for testing during development 
開發者ID:thorrak,項目名稱:fermentrack,代碼行數:16,代碼來源:udev_integration.py

示例13: __init__

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def __init__(self, usb_plugged, usb_unplugged):
		self.usb_plugged = usb_plugged
		self.usb_unplugged = usb_unplugged
		
		self.context = pyudev.Context()
		self.monitor = pyudev.Monitor.from_netlink(self.context)
		self.monitor.filter_by('block') 
開發者ID:turingsec,項目名稱:marsnake,代碼行數:9,代碼來源:usb_detect_linux.py

示例14: find_udev

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
def find_udev(check, product_id):
	ports = []
	if LINUX:
		try:
			import pyudev

			context = pyudev.Context()
			for device in context.list_devices(subsystem='tty', ID_MODEL=product_id):
				if check(device.device_node):
					ports.append(device.device_node)
		except ImportError:
			pass		
	return ports 
開發者ID:theRealTacoTime,項目名稱:poclbm,代碼行數:15,代碼來源:ioutil.py

示例15: monitor

# 需要導入模塊: import pyudev [as 別名]
# 或者: from pyudev import Context [as 別名]
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() 
開發者ID:cryptax,項目名稱:fittools,代碼行數:11,代碼來源:donglelock.py


注:本文中的pyudev.Context方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。