From: Haomai Wang Date: Thu, 30 Apr 2015 13:31:15 +0000 (+0800) Subject: pycephfs: Add dirent class definition to ease caller X-Git-Tag: v9.0.2~227^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d7ffc71c8101dece50d4e3535cc94b8a56337a26;p=ceph.git pycephfs: Add dirent class definition to ease caller Signed-off-by: Haomai Wang --- diff --git a/src/pybind/cephfs.py b/src/pybind/cephfs.py index 0b613d922772..fa2012525f18 100644 --- a/src/pybind/cephfs.py +++ b/src/pybind/cephfs.py @@ -5,6 +5,7 @@ from ctypes import CDLL, c_char_p, c_size_t, c_void_p, c_int, c_long, c_uint, c_ c_ushort, create_string_buffer, byref, Structure, pointer, c_char, POINTER, \ c_uint8 from ctypes.util import find_library +from collections import namedtuple import errno @@ -141,6 +142,21 @@ class cephfs_stat(Structure): ('__unused3', c_long)] +class DirEntry(namedtuple('DirEntry', + ['d_info', 'd_off', 'd_reclen', 'd_type', 'd_name'])): + DT_DIR = 0x4 + DT_REG = 0xA + DT_LNK = 0xC + def is_dir(self): + return self.d_type == DT_DIR + + def is_symbol_file(self): + return self.d_type == DT_LNK + + def is_file(self): + return self.d_type == DT_REG + + def load_libcephfs(): """ Load the libcephfs shared library. @@ -334,11 +350,11 @@ class LibCephFS(object): if not dirent: return None - return {'d_ino': dirent.contents.d_ino, - 'd_off': dirent.contents.d_off, - 'd_reclen': dirent.contents.d_reclen, - 'd_type': dirent.contents.d_type, - 'd_name': dirent.contents.d_name} + return DirEntry(d_ino=dirent.contents.d_ino, + d_off=dirent.contents.d_off, + d_reclen=dirent.contents.d_reclen, + d_type=dirent.contents.d_type, + d_name=dirent.contents.d_name) def closedir(self, dir_handler): self.require_state("mounted")