当前位置: 首页>>代码示例>>Python>>正文


Python Device.from_device_number方法代码示例

本文整理汇总了Python中pyudev.Device.from_device_number方法的典型用法代码示例。如果您正苦于以下问题:Python Device.from_device_number方法的具体用法?Python Device.from_device_number怎么用?Python Device.from_device_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyudev.Device的用法示例。


在下文中一共展示了Device.from_device_number方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_indexed_string

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_number [as 别名]
def get_indexed_string(device_handle, index):
	"""Get a string from a HID device, based on its string index.

	Note: currently not working in the ``hidraw`` native implementation.

	:param device_handle: a device handle returned by open() or open_path().
	:param index: the index of the string to get.
	"""
	if index not in _DEVICE_STRINGS:
		return None

	assert device_handle
	stat = _os.fstat(device_handle)
	dev = _Device.from_device_number(_Context(), 'char', stat.st_rdev)
	if dev:
		hid_dev = dev.find_parent('hid')
		if hid_dev:
			assert 'HID_ID' in hid_dev
			bus, _ignore, _ignore = hid_dev['HID_ID'].split(':')

			if bus == '0003':  # USB
				usb_dev = dev.find_parent('usb', 'usb_device')
				assert usb_dev
				key = _DEVICE_STRINGS[index]
				attrs = usb_dev.attributes
				if key in attrs:
					return attrs[key]

			elif bus == '0005':  # BLUETOOTH
				# TODO
				pass
开发者ID:3v1n0,项目名称:Solaar,代码行数:33,代码来源:udev.py

示例2: get_indexed_string

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_number [as 别名]
def get_indexed_string(device_handle, index):
	"""Get a string from a HID device, based on its string index.

	Note: currently not working in the ``hidraw`` native implementation.

	:param device_handle: a device handle returned by open() or open_path().
	:param index: the index of the string to get.
	:returns: the value corresponding to index, or None if no value found
	:rtype: bytes or NoneType
	"""
	try:
	    key = _DEVICE_STRINGS[index]
	except KeyError:
	    return None

	assert device_handle
	stat = _os.fstat(device_handle)
	try:
		dev = _Device.from_device_number(_Context(), 'char', stat.st_rdev)
	except (DeviceNotFoundError, ValueError):
		return None

	hid_dev = dev.find_parent('hid')
	if hid_dev:
		assert 'HID_ID' in hid_dev
		bus, _ignore, _ignore = hid_dev['HID_ID'].split(':')

		if bus == '0003':  # USB
			usb_dev = dev.find_parent('usb', 'usb_device')
			assert usb_dev
			return usb_dev.attributes.get(key)

		elif bus == '0005':  # BLUETOOTH
			# TODO
			pass
开发者ID:Alsan,项目名称:Solaar,代码行数:37,代码来源:udev.py

示例3: test_from_device_number

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_number [as 别名]
 def test_from_device_number(self, context, device_data):
     if not device_data.device_node:
         pytest.skip("no device node, no device number")
     mode = os.stat(device_data.device_node).st_mode
     type = "block" if stat.S_ISBLK(mode) else "char"
     device = Device.from_device_number(context, type, device_data.device_number)
     assert device.device_number == device_data.device_number
     # make sure, we are really referring to the same device
     assert device.device_path == device_data.device_path
开发者ID:bjornarg,项目名称:pyudev,代码行数:11,代码来源:test_device.py

示例4: test_from_device_number

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_number [as 别名]
 def test_from_device_number(self, context, device_path, device_number,
                             device_node):
     if not device_node:
         pytest.skip('no device node, no device number')
     mode = os.stat(device_node).st_mode
     type = 'block' if stat.S_ISBLK(mode) else 'char'
     device = Device.from_device_number(context, type, device_number)
     assert device.device_number == device_number
     # make sure, we are really referring to the same device
     assert device.device_path == device_path
开发者ID:lanstat,项目名称:pyudev,代码行数:12,代码来源:test_device.py

示例5: test_from_device_number_wrong_type

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_number [as 别名]
 def test_from_device_number_wrong_type(self, context, device_data):
     if not device_data.device_node:
         pytest.skip("no device node, no device number")
     mode = os.stat(device_data.device_node).st_mode
     # deliberately use the wrong type here to cause either failure or at
     # least device mismatch
     type = "char" if stat.S_ISBLK(mode) else "block"
     try:
         # this either fails, in which case the caught exception is raised,
         # or succeeds, but returns a wrong device (device numbers are not
         # unique across device types)
         device = Device.from_device_number(context, type, device_data.device_number)
         # if it succeeds, the resulting device must not match the one, we
         # are actually looking for!
         assert device.device_path != device_data.device_path
     except DeviceNotFoundByNumberError as error:
         # check the correctness of the exception attributes
         assert error.device_type == type
         assert error.device_number == device_data.device_number
开发者ID:bjornarg,项目名称:pyudev,代码行数:21,代码来源:test_device.py

示例6: test_from_device_number_invalid_type

# 需要导入模块: from pyudev import Device [as 别名]
# 或者: from pyudev.Device import from_device_number [as 别名]
 def test_from_device_number_invalid_type(self, context):
     with pytest.raises(ValueError) as exc_info:
         Device.from_device_number(context, "foobar", 100)
     assert str(exc_info.value) == ("Invalid type: {0!r}. Must be one of " '"char" or "block".'.format("foobar"))
开发者ID:bjornarg,项目名称:pyudev,代码行数:6,代码来源:test_device.py


注:本文中的pyudev.Device.from_device_number方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。