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


Python stat.S_ISBLK属性代码示例

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


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

示例1: get_device_type

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def get_device_type(filename):
    """
    Get the device type of a device file.

    ``filename`` is a string containing the path of a device file.

    Return ``'char'`` if ``filename`` is a character device, or ``'block'`` if
    ``filename`` is a block device.  Raise :exc:`~exceptions.ValueError` if
    ``filename`` is no device file at all.  Raise
    :exc:`~exceptions.EnvironmentError` if ``filename`` does not exist or if
    its metadata was inaccessible.

    .. versionadded:: 0.15
    """
    mode = os.stat(filename).st_mode
    if stat.S_ISCHR(mode):
        return 'char'
    elif stat.S_ISBLK(mode):
        return 'block'
    else:
        raise ValueError('not a device file: {0!r}'.format(filename)) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:23,代码来源:_util.py

示例2: is_block

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def is_block(usb_disk):
    """
    Function to detect if the USB is block device
    :param usb_disk: USB disk path
    :return: True is devie is block device else False
    """
    import stat
    if platform.system() == 'Linux':
        if len(usb_disk) != 9:
            return False
    elif platform.system() == 'Windows':
        if len(usb_disk) != 2:
            return False
        else:
            return True
    try:
        mode = os.stat(usb_disk).st_mode
        gen.log(mode)
        gen.log(stat.S_ISBLK(mode))
    except:
        return False

    return stat.S_ISBLK(mode) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:25,代码来源:usb.py

示例3: __hashEntry

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def __hashEntry(self, prefix, entry, s):
        if stat.S_ISREG(s.st_mode):
            digest = self.__index.check(prefix, entry, s, hashFile)
        elif stat.S_ISDIR(s.st_mode):
            digest = self.__hashDir(prefix, entry)
        elif stat.S_ISLNK(s.st_mode):
            digest = self.__index.check(prefix, entry, s, DirHasher.__hashLink)
        elif stat.S_ISBLK(s.st_mode) or stat.S_ISCHR(s.st_mode):
            digest = struct.pack("<L", s.st_rdev)
        elif stat.S_ISFIFO(s.st_mode):
            digest = b''
        else:
            digest = b''
            logging.getLogger(__name__).warning("Unknown file: %s", entry)

        return digest 
开发者ID:BobBuildTool,项目名称:bob,代码行数:18,代码来源:utils.py

示例4: mode_filetype

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def mode_filetype(mode):
    mode = stat.S_IFMT(mode)
    dic = {
            stat.S_ISFIFO: "fifo file",
            stat.S_ISCHR: "character device",
            stat.S_ISDIR: "directory",
            stat.S_ISBLK: "block device",
            stat.S_ISREG: "regular file",
            stat.S_ISLNK: "symbolic link",
            stat.S_ISSOCK: "socket",
            stat.S_ISDOOR: "door",
            }
    for test_func, name in dic.items():
        if test_func(mode):
            return name
    return "???" 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:18,代码来源:plugin.py

示例5: is_special_file

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def is_special_file(path):
    """
    This function checks to see if a special file.  It checks if the
    file is a character special device, block special device, FIFO, or
    socket.
    """
    mode = os.stat(path).st_mode
    # Character special device.
    if stat.S_ISCHR(mode):
        return True
    # Block special device
    if stat.S_ISBLK(mode):
        return True
    # FIFO.
    if stat.S_ISFIFO(mode):
        return True
    # Socket.
    if stat.S_ISSOCK(mode):
        return True
    return False 
开发者ID:gkrizek,项目名称:bash-lambda-layer,代码行数:22,代码来源:filegenerator.py

示例6: is_block_device

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def is_block_device(dev):
    """Check whether a device is block or not."""
    attempts = CONF.disk_utils.partition_detection_attempts
    for attempt in range(attempts):
        try:
            s = os.stat(dev)
        except OSError as e:
            LOG.debug("Unable to stat device %(dev)s. Attempt %(attempt)d "
                      "out of %(total)d. Error: %(err)s",
                      {"dev": dev, "attempt": attempt + 1,
                       "total": attempts, "err": e})
            time.sleep(1)
        else:
            return stat.S_ISBLK(s.st_mode)
    msg = _("Unable to stat device %(dev)s after attempting to verify "
            "%(attempts)d times.") % {'dev': dev, 'attempts': attempts}
    LOG.error(msg)
    raise exception.InstanceDeployFailure(msg) 
开发者ID:openstack,项目名称:ironic-lib,代码行数:20,代码来源:disk_utils.py

示例7: __init__

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def __init__(self, id, pwm_filepath, start_value, stop_value):
    assert(0 <= start_value <= 255)
    assert(0 <= stop_value <= 255)
    self.id = id
    self.pwm_filepath = pwm_filepath
    if stat.S_ISBLK(os.stat(self.pwm_filepath).st_mode):
      # we don't want to write to a block device in setPwmValue
      # command line parameters have probably been mixed up
      raise RuntimeError("%s is a block device, PWM /sys file expected" % (self.pwm_filepath))
    pwm_num = int(__class__.LAST_DIGITS_REGEX.search(self.pwm_filepath).group(1))
    self.fan_input_filepath = os.path.join(os.path.dirname(self.pwm_filepath),
                                           "fan%u_input" % (pwm_num))
    self.enable_filepath = "%s_enable" % (self.pwm_filepath)
    self.start_value = start_value
    self.stop_value = stop_value
    self.startup = False
    self.logger = logging.getLogger("Fan #%u" % (self.id)) 
开发者ID:desbma,项目名称:hddfancontrol,代码行数:19,代码来源:__init__.py

示例8: isdev

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def isdev(self):
		from stat import S_ISBLK, S_ISCHR
		mode = self.__st_mode()
		return S_ISBLK(mode) or S_ISCHR(mode) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:6,代码来源:__init__.py

示例9: isblockdev

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def isblockdev(self):
		from stat import S_ISBLK
		return S_ISBLK(self.__st_mode()) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:5,代码来源:__init__.py

示例10: is_special_file

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def is_special_file(cls, filename):
        """Checks to see if a file is a special UNIX file.

        It checks if the file is a character special device, block special
        device, FIFO, or socket.

        :param filename: Name of the file

        :returns: True if the file is a special file. False, if is not.
        """
        # If it does not exist, it must be a new file so it cannot be
        # a special file.
        if not os.path.exists(filename):
            return False
        mode = os.stat(filename).st_mode
        # Character special device.
        if stat.S_ISCHR(mode):
            return True
        # Block special device
        if stat.S_ISBLK(mode):
            return True
        # Named pipe / FIFO
        if stat.S_ISFIFO(mode):
            return True
        # Socket.
        if stat.S_ISSOCK(mode):
            return True
        return False 
开发者ID:skarlekar,项目名称:faces,代码行数:30,代码来源:utils.py

示例11: is_device

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def is_device(mode):
    mode = stat.S_IFMT(mode)
    return stat.S_ISCHR(mode) or stat.S_ISBLK(mode) 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:5,代码来源:plugin.py

示例12: isBlockDevice

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def isBlockDevice(self):
        """
        Returns whether the underlying path is a block device.

        @return: C{True} if it is a block device, C{False} otherwise
        @rtype: L{bool}
        @since: 11.1
        """
        st = self._statinfo
        if not st:
            self.restat(False)
            st = self._statinfo
            if not st:
                return False
        return S_ISBLK(st.st_mode) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:filepath.py

示例13: mode_to_letter

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def mode_to_letter(mode):
	if stat.S_ISDIR(mode):
		return 'DIR'
	elif stat.S_ISBLK(mode):
		return 'BLK'
	elif stat.S_ISCHR(mode):
		return 'CHR'
	elif stat.S_ISFIFO(mode):
		return 'FIFO'
	elif stat.S_ISSOCK(mode):
		return 'SOCK'
	elif stat.S_ISLNK(mode):
		return 'LNK'
	else:
		return '' 
开发者ID:turingsec,项目名称:marsnake,代码行数:17,代码来源:file_op.py

示例14: testStatDirectory_fileModes

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def testStatDirectory_fileModes(self):
    expected_modes = (
      ('some_dir', stat.S_ISDIR),
      ('some_file', stat.S_ISREG),
      ('lnk', stat.S_ISLNK),
      ('a_socket1', stat.S_ISSOCK),
      ('block_dev', stat.S_ISBLK),
      ('random', stat.S_ISCHR),
    )
    entries = self.getStatEntries()
    for filename, check in expected_modes:
      self.assertTrue(check(entries[filename]['st_mode'])) 
开发者ID:FSecureLABS,项目名称:Jandroid,代码行数:14,代码来源:device_utils_test.py

示例15: is_block_device

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISBLK [as 别名]
def is_block_device(self):
        """
        Whether this path is a block device.
        """
        try:
            return S_ISBLK(self.stat().st_mode)
        except OSError as e:
            if e.errno not in (ENOENT, ENOTDIR):
                raise
            # Path doesn't exist or is a broken symlink
            # (see https://bitbucket.org/pitrou/pathlib/issue/12/)
            return False 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:pathlib.py


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