def inspect(doc): data = json.loads(doc) path = FilePath(data['path']) ret = {'kind': 'file', 'path': path.path, 'exists': path.exists()} if not ret['exists']: return ret if path.isdir(): ret['filetype'] = 'dir' elif path.isfile(): ret['filetype'] = 'file' ret['size'] = path.statinfo.st_size h = sha1() fh = open(path.path, 'r') while True: data = fh.read(4096) if not data: break h.update(data) ret['sha1'] = h.hexdigest() ret['owner'] = pwd.getpwuid(path.getUserID()).pw_name ret['group'] = grp.getgrgid(path.getGroupID()).gr_name ret['perms'] = permsString(path.getPermissions()) ret['ctime'] = int(path.statinfo.st_ctime) ret['mtime'] = int(path.statinfo.st_mtime) ret['atime'] = int(path.statinfo.st_atime) return ret