當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。