本文整理匯總了Python中stat.S_IFDIR屬性的典型用法代碼示例。如果您正苦於以下問題:Python stat.S_IFDIR屬性的具體用法?Python stat.S_IFDIR怎麽用?Python stat.S_IFDIR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類stat
的用法示例。
在下文中一共展示了stat.S_IFDIR屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_lstat_on_dir
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def test_lstat_on_dir(smb_share):
dirname = ntpath.join(smb_share, 'dir')
smbclient.mkdir(dirname)
actual = smbclient.lstat(dirname)
assert isinstance(actual, smbclient.SMBStatResult)
assert actual.st_atime == actual.st_atime_ns / 1000000000
assert actual.st_mtime == actual.st_mtime_ns / 1000000000
assert actual.st_ctime == actual.st_ctime_ns / 1000000000
assert actual.st_chgtime == actual.st_chgtime_ns / 1000000000
assert actual.st_dev is not None
assert actual.st_file_attributes == FileAttributes.FILE_ATTRIBUTE_DIRECTORY
assert actual.st_gid == 0
assert actual.st_uid == 0
assert actual.st_ino is not None
assert actual.st_mode == stat.S_IFDIR | 0o777
assert actual.st_nlink == 1
assert actual.st_size == 0
assert actual.st_uid == 0
assert actual.st_reparse_tag == 0
示例2: getattr
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def getattr(self, path, fh=None):
path = "".join([self.root, path.lstrip("/")]).rstrip("/")
try:
info = self.fs.info(path)
except FileNotFoundError:
raise FuseOSError(ENOENT)
data = {"st_uid": 1000, "st_gid": 1000}
perm = 0o777
if info["type"] != "file":
data["st_mode"] = stat.S_IFDIR | perm
data["st_size"] = 0
data["st_blksize"] = 0
else:
data["st_mode"] = stat.S_IFREG | perm
data["st_size"] = info["size"]
data["st_blksize"] = 5 * 2 ** 20
data["st_nlink"] = 1
data["st_atime"] = time.time()
data["st_ctime"] = time.time()
data["st_mtime"] = time.time()
return data
示例3: getattr
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def getattr(self, path):
# The path represents a pid.
components = os.path.split(path)
if len(components) > 2:
return
if len(components) == 2 and components[1] in self.tasks:
s = make_stat(components[1])
s.st_mode = stat.S_IFREG
s.st_size = self.address_space_size
return s
elif components[0] == "/":
s = make_stat(2)
s.st_mode = stat.S_IFDIR
return s
示例4: __init__
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def __init__(self, filename=None, **kwargs):
filename = common.FileSpec(filename, filesystem="Reg", path_sep="\\")
super(RegistryKeyInformation, self).__init__(
filename=filename, **kwargs)
self.hive = self.key_name = self.value_name = self.value = ""
self.value_type = "REG_NONE"
self.st_mode = stat.S_IFDIR
path_components = self.filename.components()
if not path_components:
return
# The first component MUST be a hive
self.hive = path_components[0]
self._hive_handle = KeyHandle(getattr(_winreg, self.hive, None))
if self._hive_handle is None:
raise IOError("Unknown hive name %s" % self.hive)
# Maybe its a key.
try:
self._read_key(path_components)
except WindowsError:
# Nop - maybe its a value then.
self._read_value(path_components)
示例5: do_commit
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def do_commit(self):
tree = {}
for path, property in self.entries.iteritems():
t = tree
path_arr = path.split('/')
for path_ele in path_arr[:-1]:
t = t.setdefault(path_ele, {})
t = t.setdefault(path_arr[-1], (property['mode'], property['sha1']))
def _build_tree(path):
dir_arr = []
file_arr = []
for name, entry in path.iteritems():
if isinstance(entry, dict):
mode = stat.S_IFDIR
sha1 = _build_tree(entry).sha1
dir_arr.append({'name':name, 'mode':mode, 'sha1':sha1})
else:
(mode, sha1) = entry
file_arr.append({'name':name, 'mode':mode, 'sha1':sha1})
newtree = Tree(sorted(dir_arr,key = lambda x:x['name']) + sorted(file_arr,key = lambda x:x['name']))
write_to_file(newtree.path, newtree.content)
return newtree
return _build_tree(tree)
示例6: getattr
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def getattr(self, path, fh=None):
"""
Returns a dictionary with keys identical to the stat C structure of
stat(2).
st_atime, st_mtime and st_ctime should be floats.
NOTE: There is an incombatibility between Linux and Mac OS X
concerning st_nlink of directories. Mac OS X counts all files inside
the directory, while Linux counts only the subdirectories.
"""
if path != "/":
raise FuseOSError(ENOENT)
attrs = super(IndexView, self).getattr(path, fh)
attrs.update({"st_mode": S_IFDIR | 0o555, "st_nlink": 2})
return attrs
示例7: get_git_object_default_stats
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def get_git_object_default_stats(self, ref, path):
types = {
GIT_FILEMODE_LINK: {"st_mode": S_IFLNK | 0o444},
GIT_FILEMODE_TREE: {"st_mode": S_IFDIR | 0o555, "st_nlink": 2},
GIT_FILEMODE_BLOB: {"st_mode": S_IFREG | 0o444},
GIT_FILEMODE_BLOB_EXECUTABLE: {"st_mode": S_IFREG | 0o555},
}
if path == "/":
return types[GIT_FILEMODE_TREE]
obj_type = self.get_git_object_type(ref, path)
if obj_type is None:
return obj_type
stats = types[obj_type]
if obj_type in [GIT_FILEMODE_BLOB, GIT_FILEMODE_BLOB_EXECUTABLE]:
stats["st_size"] = self.get_blob_size(ref, path)
return stats
示例8: test_getattr_with_simple_path
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def test_getattr_with_simple_path(self):
mocked_repo = MagicMock()
mocked_commit = MagicMock()
stats = {"st_mode": S_IFDIR | 0o555, "st_nlink": 2}
mocked_commit.tree = "tree"
mocked_commit.commit_time = "now+1"
mocked_repo.revparse_single.return_value = mocked_commit
mocked_repo.get_git_object_default_stats.return_value = stats
view = CommitView(
repo=mocked_repo, commit_sha1="sha1", mount_time="now", uid=1, gid=1
)
result = view.getattr("/", 1)
asserted_result = {
"st_uid": 1,
"st_gid": 1,
"st_mtime": "now+1",
"st_ctime": "now+1",
"st_mode": S_IFDIR | 0o555,
"st_nlink": 2,
}
assert result == asserted_result
示例9: stat
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def stat(self, name):
ap = self.abspath(name)
if ap in ("/", "/.", "./", "//", ""):
bytes = 0
isdir = True
else:
try:
meta = self.client.files_get_metadata(ap)
except dropbox.exceptions.ApiError as e:
raise OperationFailure(e.message)
if isinstance(meta, (dropbox.files.FolderMetadata, dropbox.sharing.SharedFolderMetadata)):
bytes = 0
isdir = True
else:
bytes = meta.size
isdir = False
type_ = (stat.S_IFDIR if isdir else stat.S_IFREG)
m = calc_mode(type=type_)
s = make_stat(size=bytes, mode=m)
return s
示例10: stat
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def stat(self, name):
ap = self.abspath(name)
self.log("stat: {ap}\n".format(ap=ap))
isdir = self.isdir(name)
isfile = self.isfile(name)
if not (isdir or isfile):
self.log("stat-target not found.\n")
raise errors.OperationFailure("Not found!")
if isdir:
size = 1
mtime = None
else:
zipinfo = self.zf.getinfo(ap)
size = zipinfo.file_size
timestamp = zipinfo.date_time
dt = datetime.datetime(*timestamp)
mtime = (dt - datetime.datetime(1970, 1, 1)).total_seconds()
type_ = (stat.S_IFREG if isfile else stat.S_IFDIR)
mode = base.calc_mode(type=type_)
self.log("stat return\n")
return base.make_stat(size=size, mtime=mtime, ctime=mtime, mode=mode)
示例11: stat
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def stat(self, path):
node = self.get_node(path)
if node is None:
raise FileNotFoundError
else:
if node.type == "file":
size = len(node.content.getbuffer())
mode = stat.S_IFREG | 0o666
else:
size = 0
mode = stat.S_IFDIR | 0o777
return MemoryPathIO.Stats(
size,
node.ctime,
node.mtime,
1,
mode,
)
示例12: getattr
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def getattr(self, path, fh=None):
(uid, gid, pid) = fuse_get_context()
entry = self._get_path_entry(path)
if entry.is_directory():
mode = (stat.S_IFDIR | PERMISSION_ALL_READ)
nlink = 2
else:
mode = (stat.S_IFREG | PERMISSION_ALL_READ)
nlink = 1
return {
"st_atime": unixtimestamp(entry.get_si_accessed_timestamp()),
"st_ctime": unixtimestamp(entry.get_si_changed_timestamp()),
"st_crtime": unixtimestamp(entry.get_si_created_timestamp()),
"st_mtime": unixtimestamp(entry.get_si_modified_timestamp()),
"st_size": entry.get_size(),
"st_uid": uid,
"st_gid": gid,
"st_mode": mode,
"st_nlink": nlink,
}
示例13: render_python_value
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def render_python_value(value):
if not isinstance(value, int):
return
if value & stat.S_IFDIR:
perm = 'd'
else:
perm = '-'
perm += 'r' if value & stat.S_IRUSR else '-'
perm += 'w' if value & stat.S_IWUSR else '-'
if value & stat.S_ISUID:
perm += 's' if value & stat.S_IXUSR else 'S'
else:
perm += 'x' if value & stat.S_IXUSR else '-'
perm += 'r' if value & stat.S_IRGRP else '-'
perm += 'w' if value & stat.S_IWGRP else '-'
if value & stat.S_ISGID:
perm += 's' if value & stat.S_IXGRP else 'S'
else:
perm += 'x' if value & stat.S_IXGRP else '-'
perm += 'r' if value & stat.S_IROTH else '-'
perm += 'w' if value & stat.S_IWOTH else '-'
perm += 'x' if value & stat.S_IXOTH else '-'
return perm
示例14: stat
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def stat(self):
if self.content_provider.get(self.path) is None:
return SFTP_NO_SUCH_FILE
mtime = calendar.timegm(datetime.now().timetuple())
sftp_attrs = SFTPAttributes()
sftp_attrs.st_size = self.content_provider.get_size(self.path)
sftp_attrs.st_uid = 0
sftp_attrs.st_gid = 0
sftp_attrs.st_mode = (
stat.S_IRWXO
| stat.S_IRWXG
| stat.S_IRWXU
| (stat.S_IFDIR if self.content_provider.is_dir(self.path) else stat.S_IFREG)
)
sftp_attrs.st_atime = mtime
sftp_attrs.st_mtime = mtime
sftp_attrs.filename = posixpath.basename(self.path)
return sftp_attrs
示例15: __init__
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_IFDIR [as 別名]
def __init__(self, sn_api, sync_sec, ext, path='.'):
self.item_manager = ItemManager(sn_api, ext)
self.uid = os.getuid()
self.gid = os.getgid()
now = datetime.now().timestamp()
self.dir_stat = dict(st_mode=(S_IFDIR | DIR_PERMISSIONS), st_ctime=now,
st_mtime=now, st_atime=now, st_nlink=2,
st_uid=self.uid, st_gid=self.gid)
self.note_stat = dict(st_mode=(S_IFREG | FILE_PERMISSIONS), st_ctime=now,
st_mtime=now, st_atime=now, st_nlink=1,
st_uid=self.uid, st_gid=self.gid)
self.sync_sec = sync_sec
self.ext = ext
self.run_sync = Event()
self.stop_sync = Event()
self.sync_thread = Thread(target=self._sync_thread)