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


Python os.major方法代码示例

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


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

示例1: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def __init__(self, name=""):
        """Construct a TarInfo object. name is the optional name
           of the member.
        """
        self.name = name        # member name
        self.mode = 0644        # file permissions
        self.uid = 0            # user id
        self.gid = 0            # group id
        self.size = 0           # file size
        self.mtime = 0          # modification time
        self.chksum = 0         # header checksum
        self.type = REGTYPE     # member type
        self.linkname = ""      # link name
        self.uname = ""         # user name
        self.gname = ""         # group name
        self.devmajor = 0       # device major number
        self.devminor = 0       # device minor number

        self.offset = 0         # the tar header starts here
        self.offset_data = 0    # the file's data starts here

        self.pax_headers = {}   # pax header information

    # In pax headers the "name" and "linkname" field are called
    # "path" and "linkpath". 
开发者ID:glmcdona,项目名称:meddle,代码行数:27,代码来源:tarfile.py

示例2: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def __init__(self, name=""):
        """Construct a TarInfo object. name is the optional name
           of the member.
        """
        self.name = name        # member name (dirnames must end with '/')
        self.mode = 0666        # file permissions
        self.uid = 0            # user id
        self.gid = 0            # group id
        self.size = 0           # file size
        self.mtime = 0          # modification time
        self.chksum = 0         # header checksum
        self.type = REGTYPE     # member type
        self.linkname = ""      # link name
        self.uname = "user"     # user name
        self.gname = "group"    # group name
        self.devmajor = 0       # device major number
        self.devminor = 0       # device minor number

        self.offset = 0         # the tar header starts here
        self.offset_data = 0    # the file's data starts here 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:22,代码来源:tarfile.py

示例3: test_broken_linux_fallback

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def test_broken_linux_fallback(self, openpty):
        openpty.side_effect = OSError(errno.EPERM)
        master_fp, slave_fp = self.func()
        try:
            st = os.fstat(master_fp.fileno())
            self.assertEquals(5, os.major(st.st_rdev))
            flags = fcntl.fcntl(master_fp.fileno(), fcntl.F_GETFL)
            self.assertTrue(flags & os.O_RDWR)

            st = os.fstat(slave_fp.fileno())
            self.assertEquals(136, os.major(st.st_rdev))
            flags = fcntl.fcntl(slave_fp.fileno(), fcntl.F_GETFL)
            self.assertTrue(flags & os.O_RDWR)
        finally:
            master_fp.close()
            slave_fp.close() 
开发者ID:dw,项目名称:mitogen,代码行数:18,代码来源:parent_test.py

示例4: maj_min_to_blk

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def maj_min_to_blk(major, minor):
    """Returns the block device name to the major:minor numbers in the param.

    :param major:
        The major number of the device
    :param minor:
        The minor number of the device
    :returns:
        Block device name.
    :rtype:
        ``str``
    """
    # TODO: Reimplement using /proc/partition
    maj_min = '{}:{}'.format(major, minor)
    block_dev = None
    for sys_path in glob.glob(os.path.join(os.sep, 'sys', 'class', 'block',
                                           '*', 'dev')):
        with io.open(sys_path) as f:
            if f.read().strip() == maj_min:
                block_dev = '/dev/{}'.format(sys_path.split(os.sep)[-2])
                break

    return block_dev 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:25,代码来源:linux.py

示例5: from_device_number

# 需要导入模块: import os [as 别名]
# 或者: from os import major [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

示例6: from_kernel_device

# 需要导入模块: import os [as 别名]
# 或者: from os import major [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

示例7: device_number

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def device_number(self):
        """
        The device number of the associated device as integer, or ``0``, if no
        device number is associated.

        Use :func:`os.major` and :func:`os.minor` to decompose the device
        number into its major and minor number:

        >>> import os
        >>> from pyudev import Context, Device
        >>> context = Context()
        >>> sda = Devices.from_name(context, 'block', 'sda')
        >>> sda.device_number
        2048L
        >>> (os.major(sda.device_number), os.minor(sda.device_number))
        (8, 0)

        For devices with an associated :attr:`device_node`, this is the same as
        the ``st_rdev`` field of the stat result of the :attr:`device_node`:

        >>> os.stat(sda.device_node).st_rdev
        2048

        .. versionadded:: 0.11
        """
        return self._libudev.udev_device_get_devnum(self) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:28,代码来源:_device.py

示例8: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def __init__(self, name=""):
        """Construct a TarInfo object. name is the optional name
           of the member.
        """
        self.name = name        # member name
        self.mode = 0o644       # file permissions
        self.uid = 0            # user id
        self.gid = 0            # group id
        self.size = 0           # file size
        self.mtime = 0          # modification time
        self.chksum = 0         # header checksum
        self.type = REGTYPE     # member type
        self.linkname = ""      # link name
        self.uname = ""         # user name
        self.gname = ""         # group name
        self.devmajor = 0       # device major number
        self.devminor = 0       # device minor number

        self.offset = 0         # the tar header starts here
        self.offset_data = 0    # the file's data starts here

        self.sparse = None      # sparse member information
        self.pax_headers = {}   # pax header information

    # In pax headers the "name" and "linkname" field are called
    # "path" and "linkpath". 
开发者ID:war-and-code,项目名称:jawfish,代码行数:28,代码来源:tarfile.py

示例9: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def __init__( self, path, blocking=True, parent=None ):
        path = Path( '/dev/uio', path )
        self.path = path

        flags = O_RDWR | O_CLOEXEC
        if not blocking:
            flags |= O_NONBLOCK # for irq_recv
        self._fd = os.open( str(path), flags )

        # check parent memory region (if any)
        if parent is not None:
            if isinstance( parent, Uio ):
                parent = parent.region()
            elif isinstance( parent, MemRegion ):
                raise TypeError

        # build path to sysfs dir for obtaining metadata
        dev = os.stat( self._fd ).st_rdev
        dev = '{0}:{1}'.format( os.major(dev), os.minor(dev) )
        self.syspath = Path('/sys/dev/char', dev).resolve()

        # enumerate memory regions
        # beware that if there are none, the dir is absent rather than empty
        self._regions = {}
        rgninfo = self.syspath/'maps'
        if rgninfo.is_dir():
            for info in rgninfo.iterdir():
                rgn = MemRegion.from_sysfs( self, info, parent )

                # allow lookup by index or (if available) by name
                self._regions[ rgn.index ] = rgn
                if rgn.name:
                    self._regions[ rgn.name ] = rgn 
开发者ID:mvduin,项目名称:py-uio,代码行数:35,代码来源:device.py

示例10: format_device_id

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def format_device_id(stats):
    return '{},{}'.format(os.major(stats.st_rdev), os.minor(stats.st_rdev)) 
开发者ID:AndrewX192,项目名称:lenovo-sa120-fanspeed-utility,代码行数:4,代码来源:fancontrol.py

示例11: __get_dev_major_minor

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def __get_dev_major_minor(self, dev_path="/dev/sda"):
        """
        Get the device 'major:minor' number

        :param dev_path: The path to the device
        """
        if not os.path.exists(dev_path):
            logging.debug("device '%s' not existing", dev_path)
            return None
        dev = os.stat(dev_path)
        return "%s:%s" % (os.major(dev.st_rdev), os.minor(dev.st_rdev)) 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:13,代码来源:libvirt_cgroup.py

示例12: get_dev_major_minor

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def get_dev_major_minor(dev):
    """
    Get the major and minor numbers of the device
    @return: Tuple(major, minor) numbers of the device
    """
    try:
        rdev = os.stat(dev).st_rdev
        return (os.major(rdev), os.minor(rdev))
    except IOError as details:
        raise exceptions.TestError("Fail to get major and minor numbers of the "
                                   "device %s:\n%s" % (dev, details)) 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:13,代码来源:utils_misc.py

示例13: get_qemu_version

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def get_qemu_version(params=None):
    """
    Get the qemu-kvm(-rhev) version info.

    :param params: Passed to get_qemu_binary, can set to {} if not needed.
    :return: A dict contain qemu versoins info as {'major': int, 'minor': int,
    'update': int, 'is_rhev': bool}
    """
    version = {'major': None, 'minor': None, 'update': None, 'is_rhev': False, 'module': False}
    regex = r'\s*[Ee]mulator [Vv]ersion\s*(\d+)\.(\d+)\.(\d+)'

    if params is None:
        params = {}
    qemu_binary = get_qemu_binary(params)
    version_raw = process.run("%s -version" % qemu_binary,
                              shell=True).stdout_text.splitlines()
    for line in version_raw:
        search_result = re.search(regex, line)
        if search_result:
            version['major'] = int(search_result.group(1))
            version['minor'] = int(search_result.group(2))
            version['update'] = int(search_result.group(3))
        line_l = str(line).lower()
        if "rhev" in line_l:
            version['is_rhev'] = True
        if "module" in line_l or "scrmod" in line_l:
            version['module'] = True
    if None in list(version.values()):
        logging.error("Local install qemu version cannot be detected, "
                      "the version info is: %s" % version_raw)
        return None
    return version 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:34,代码来源:utils_misc.py

示例14: compare_qemu_version

# 需要导入模块: import os [as 别名]
# 或者: from os import major [as 别名]
def compare_qemu_version(major, minor, update, is_rhev=True, params={}):
    """
    Check if local install qemu versions is newer than provided version.

    :param major: The major version to be compared.
    :param minor: The minor version to be compared.
    :param update: The update version to be compared.
    :param is_rhev: If the qemu is a rhev version.
    :param params: Other params.
    :return: True means local installed version is equal or newer than the
    version provided, otherwise False will be returned.
    """
    installed_version = get_qemu_version(params)
    if installed_version is None:
        logging.error("Cannot get local qemu version, return False directly.")
        return False
    if installed_version['module']:
        is_rhev = False
    if is_rhev != installed_version['is_rhev']:
        return False
    installed_version_value = installed_version['major'] * 1000000 + \
        installed_version['minor'] * 1000 + \
        installed_version['update']
    compared_version_value = int(major) * 1000000 + \
        int(minor) * 1000 + \
        int(update)
    if compared_version_value > installed_version_value:
        return False
    return True 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:31,代码来源:utils_misc.py


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