def parse_json(response) : if response : result = json.JSONDecoder().decode(response.read()) if(result['result']['value'] == 'ok') : for item in result['file'] : if item : f = KFile.new_instance(**item) f.path = os.path.join(kfile and kfile.path or '' , f.name) files.append(f) if recursion and f.type == 'folder' : self.ls_file(f,recursion) if kfile : kfile.list = files return files
def new_dir(self,name,parent_file = None) : if parent_file and parent_file.type == 'file' : print '%s is not a dictionary !' % (parent_file.name) return False parentId = parent_file and parent_file.fileId or '' result = self.request_url(self.new_dir_url, {'parentid':parentId,'name':name}, lambda response :json.JSONDecoder().decode(response.read())) if result and result['xLive_attr'] : if result['xLive_attr']['result'] in ('ok' , 'targetExist') : file = KFile.new_instance(**result['xLive']) file.path = os.path.join(parent_file and parent_file.path or '',name) return file else : return False