def cp(self, _to_path): if len(_to_path) > 255: raise Exception("To path too long.") params = dict( root=self.root, from_path=self.path, to_path=_to_path, ) send(cp_url(), params)
def rm(self, to_recycle=True): if not self.path: raise Exception("Remove root is not allowed/too dangerous, please goto kuaipan.cn and do it there.") params = dict( root=self.root, path=self.path, ) if not to_recycle: params["to_recycle"] = "False" send(rm_url(), params)
def mv(self, _to_path): if len(_to_path) > 255: raise Exception("To path too long.") params = dict( root=self.root, from_path=self.path, to_path=_to_path, ) mv_data = send(mv_url(), params) if mv_data: self.path = _to_path
def mkdir(self, _path): new_path = self.check_path(_path) params = dict( root=self.root, path=new_path ) mkdir_data = send(mkdir_url(), params) if mkdir_data: _id = mkdir_data["file_id"] return kfolder(new_path, _path, _id, self.root) return None
def ls(self): params = dict( page=str(self.page), page_size=str(self.page_size), # filter_ext=self.filter_ext, sort_by=self.sort_by # sort_by=sort_by ) ls_data = send(ls_url(root=self.root, path=self.path), params) files, folders = [], [] if ls_data: for _file in ls_data["files"]: _name = _file['name'] _is_deleted = _file['is_deleted'] _id = _file['file_id'] if not _is_deleted: if _file["type"] == "folder": _folder = kfolder(self.path, _name, _id, self.root, ) folders.append(_folder) elif _file["type"] == "file": files.append(kfile(self.root, self.path, _name, _id)) return folders, files