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