def parse_dirents_v1(self, data, dir_id, ret_unicode=False): '''json format''' d = json.loads(data) dirents = {} for entry in d['dirents']: name = entry['name'] id = entry['id'] mtime = entry['mtime'] mode = entry['mode'] if stat.S_ISREG(mode): type = SeafDirent.FILE size = entry['size'] elif stat.S_ISDIR(mode): type = SeafDirent.DIR size = 0 else: continue if not ret_unicode: name = to_utf8(name) id = to_utf8(id) dirents[name] = SeafDirent.fromV1(name, type, id, mtime, size) return dirents
def read_object_content(self, repo_id, obj_id): repo_id = to_utf8(repo_id) obj_id = to_utf8(obj_id) ioctx = self.ioctx_pool.get_ioctx(repo_id) try: stat = ioctx.stat(obj_id) return ioctx.read(obj_id, length=stat[0]) finally: self.ioctx_pool.return_ioctx(ioctx)
def parse_blocks_v1(self, data, obj_id): ''''json format''' d = json.loads(data) blocks = [ to_utf8(id) for id in d['block_ids'] ] size = d['size'] return blocks, size
def parse_commit(self, data, ret_unicode=False): commit_dict = json.loads(data) if ret_unicode: return SeafCommit(commit_dict) d = {} for k, v in commit_dict.iteritems(): d[to_utf8(k)] = v return SeafCommit(d)
def lookup(self, name): name = to_utf8(name) if name not in self.dirents: return None dent = self.dirents[name] if dent.is_dir(): return fs_mgr.load_seafdir(self.store_id, self.version, dent.id) else: return fs_mgr.load_seafile(self.store_id, self.version, dent.id)
def parse_commit(self, data): dict = json.loads(data) d = {} for k, v in dict.iteritems(): d[to_utf8(k)] = v return SeafCommit(d)