]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pycephfs: Add dirent class definition to ease caller
authorHaomai Wang <haomaiwang@gmail.com>
Thu, 30 Apr 2015 13:31:15 +0000 (21:31 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Thu, 30 Apr 2015 14:06:44 +0000 (22:06 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/pybind/cephfs.py

index 0b613d922772df6083f112155462b4bcc824846d..fa2012525f1829e98cc8dcdeba7458aa95c69aa5 100644 (file)
@@ -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")