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


Python os.makedev方法代码示例

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


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

示例1: _match_major_minor

# 需要导入模块: import os [as 别名]
# 或者: from os import makedev [as 别名]
def _match_major_minor(cls, value):
        """
        Match the number under the assumption that it is a major,minor pair.

        :param str value: value to match
        :returns: the device number or None
        :rtype: int or NoneType
        """
        major_minor_re = re.compile(
           r'^(?P<major>\d+)(\D+)(?P<minor>\d+)$'
        )
        match = major_minor_re.match(value)
        return match and os.makedev(
           int(match.group('major')),
           int(match.group('minor'))
        ) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:18,代码来源:discover.py

示例2: from_device_number

# 需要导入模块: import os [as 别名]
# 或者: from os import makedev [as 别名]
def from_device_number(cls, context, typ, number):
        """
        Create a new device from a device ``number`` with the given device
        ``type``:

        >>> import os
        >>> from pyudev import Context, Device
        >>> ctx = Context()
        >>> major, minor = 8, 0
        >>> device = Devices.from_device_number(context, 'block',
        ...     os.makedev(major, minor))
        >>> device
        Device(u'/sys/devices/pci0000:00/0000:00:11.0/host0/target0:0:0/0:0:0:0/block/sda')
        >>> os.major(device.device_number), os.minor(device.device_number)
        (8, 0)

        Use :func:`os.makedev` to construct a device number from a major and a
        minor device number, as shown in the example above.

        .. warning::

           Device numbers are not unique across different device types.
           Passing a correct number with a wrong type may silently yield a
           wrong device object, so make sure to pass the correct device type.

        ``context`` is the :class:`Context`, in which to search the device.
        ``type`` is either ``'char'`` or ``'block'``, according to whether the
        device is a character or block device.  ``number`` is the device number
        as integer.

        Return a :class:`Device` object for the device with the given device
        ``number``.  Raise :exc:`DeviceNotFoundByNumberError`, if no device was
        found with the given device type and number.

        .. versionadded:: 0.18
        """
        device = context._libudev.udev_device_new_from_devnum(
            context, ensure_byte_string(typ[0]), number)
        if not device:
            raise DeviceNotFoundByNumberError(typ, number)
        return Device(context, device) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:43,代码来源:_device.py

示例3: from_kernel_device

# 需要导入模块: import os [as 别名]
# 或者: from os import makedev [as 别名]
def from_kernel_device(cls, context, kernel_device):
        """
        Locate a device based on the kernel device.

        :param `Context` context: the libudev context
        :param str kernel_device: the kernel device
        :returns: the device corresponding to ``kernel_device``
        :rtype: `Device`
        """
        switch_char = kernel_device[0]
        rest = kernel_device[1:]
        if switch_char in ('b', 'c'):
            number_re = re.compile(r'^(?P<major>\d+):(?P<minor>\d+)$')
            match = number_re.match(rest)
            if match:
                number = os.makedev(
                   int(match.group('major')),
                   int(match.group('minor'))
                )
                return cls.from_device_number(context, switch_char, number)
            else:
                raise DeviceNotFoundByKernelDeviceError(kernel_device)
        elif switch_char == 'n':
            return cls.from_interface_index(context, rest)
        elif switch_char == '+':
            (subsystem, _, kernel_device_name) = rest.partition(':')
            if kernel_device_name and subsystem:
                return cls.from_name(context, subsystem, kernel_device_name)
            else:
                raise DeviceNotFoundByKernelDeviceError(kernel_device)
        else:
            raise DeviceNotFoundByKernelDeviceError(kernel_device) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:34,代码来源:_device.py

示例4: makedev

# 需要导入模块: import os [as 别名]
# 或者: from os import makedev [as 别名]
def makedev(self, tarinfo, targetpath):
        """Make a character or block device called targetpath.
        """
        if not hasattr(os, "mknod") or not hasattr(os, "makedev"):
            raise ExtractError("special devices not supported by system")

        mode = tarinfo.mode
        if tarinfo.isblk():
            mode |= stat.S_IFBLK
        else:
            mode |= stat.S_IFCHR

        os.mknod(targetpath, mode,
                 os.makedev(tarinfo.devmajor, tarinfo.devminor)) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:16,代码来源:tarfile.py

示例5: create_tunnel

# 需要导入模块: import os [as 别名]
# 或者: from os import makedev [as 别名]
def create_tunnel(self):
        node = '/dev/net/tun'
        if not os.path.exists(node):
            os.makedirs(os.path.dirname(node), exist_ok=True)
            os.mknod(node, mode=0o640 | stat.S_IFCHR, device = os.makedev(10, 200)) 
开发者ID:dlenski,项目名称:vpn-slice,代码行数:7,代码来源:linux.py

示例6: makedev

# 需要导入模块: import os [as 别名]
# 或者: from os import makedev [as 别名]
def makedev(dev_path):
    for i, dev in enumerate(['stdin', 'stdout', 'stderr']):
        os.symlink('/proc/self/fd/%d' % i, os.path.join(dev_path, dev))
    os.symlink('/proc/self/fd', os.path.join(dev_path, 'fd'))
    # Add extra devices
    DEVICES = {'null': (stat.S_IFCHR, 1, 3), 'zero': (stat.S_IFCHR, 1, 5),
               'random': (stat.S_IFCHR, 1, 8), 'urandom': (stat.S_IFCHR, 1, 9),
               'console': (stat.S_IFCHR, 136, 1), 'tty': (stat.S_IFCHR, 5, 0),
               'full': (stat.S_IFCHR, 1, 7)}
    for device, (dev_type, major, minor) in DEVICES.iteritems():
        os.mknod(os.path.join(dev_path, device),
                 0o666 | dev_type, os.makedev(major, minor)) 
开发者ID:Fewbytes,项目名称:rubber-docker,代码行数:14,代码来源:rd.py


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