本文整理汇总了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
示例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()
示例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()
示例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
示例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
示例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()
示例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)
示例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
示例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))
示例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)
示例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)
示例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
示例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')
示例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
示例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()