def find_individual_rp(self, select_list): """基于D字典结构实现 规则: 文件夹作为'问题'返回, 普通文件(除 readme.txt 外)作为'答案'储存在 redis 中,返回一个链接. """ assert select_list != [], "select list shouldn't be empty" multi_state = '' try: for s in select_list: if MULTI_FLAG in s: if s == select_list[-1]: # 普通多选 multi_state = self.multi_select(s) elif s == select_list[-2]: # 生成上一次多选的结果 multi_state = self.multi_select( s, special=select_list[-1]) break else: raise SelectException('Multi select fail') else: self.single_select(s) except SelectException: return self.SELECT_FAIL else: if multi_state == self.M_IS_ANSWER: return self.IS_ANSWER else: files = sorted(self.D.keys(), key=self._key) path = self.root + '/' + os.sep.join(self.path) readme, content, continue_ask = self.get_files_content( files, path) result = ''.join([readme, content]) if continue_ask: return result.strip() else: result += decision_links_dumps(user_select_list(self.id), MULTI_FLAG) # 可能需要股东决议书等 user_result_save(self.id, result.strip()) return self.IS_ANSWER
def find_individual_rp(self, select_list): """基于D字典结构实现 规则: 文件夹作为'问题'返回, 普通文件(除 readme.txt 外)作为'答案'储存在 redis 中,返回一个链接. """ assert select_list != [], "select list shouldn't be empty" multi_state = '' try: for s in select_list: if MULTI_FLAG in s: if s == select_list[-1]: # 普通多选 multi_state = self.multi_select(s) elif s == select_list[-2]: # 生成上一次多选的结果 multi_state = self.multi_select(s, special=select_list[-1]) break else: raise SelectException('Multi select fail') else: self.single_select(s) except SelectException: return self.SELECT_FAIL else: if multi_state == self.M_IS_ANSWER: return self.IS_ANSWER else: files = sorted(self.D.keys(), key=self._key) path = self.root + '/' + os.sep.join(self.path) readme, content, continue_ask = self.get_files_content(files, path) result = ''.join([readme, content]) if continue_ask: return result.strip() else: result += decision_links_dumps(user_select_list(self.id), MULTI_FLAG) # 可能需要股东决议书等 user_result_save(self.id, result.strip()) return self.IS_ANSWER
def multi_select(self, select, special=None): multi_select = select.split(MULTI_FLAG) path = self.root + '/' + os.sep.join(self.path) next_key = '' result = '' keys = self.key_complete(multi_select) if not keys: raise SelectException('Unavailable selects: {}'.format(select)) for k in keys: file_path = os.path.join(path, k) if all_is_file(file_path): files = sorted(self.D[k].keys(), key=self._key) result += '\n' + self.get_files_content(files, file_path)[1] elif special: _key = self.key_complete([special], _next=k)[0] files = sorted(self.D[k][_key].keys(), key=self._key) result += '\n' + self.get_files_content( files, os.path.join(file_path, _key))[1] elif not special and not next_key: next_key = k if next_key: self.path.append(next_key) self.D = self.D[next_key] if result: if next_key: user_result_save(self.id, result.strip()) return self.M_CONTINUE_ASK else: result += decision_links_dumps(user_select_list(self.id), MULTI_FLAG) # 可能需要股东决议书 user_result_save(self.id, result.strip()) return self.M_IS_ANSWER
def individual_response(self): new = self.msg['Content'] user_select = user_select_list(self.id) result = '' if new == BACK_TO_LAST: # 返回上层 if user_select: user_select.pop() user_select_pop(self.id) else: user_select.append(new) user_select_new(self.id, new) rp = self.find_individual_rp(user_select) if rp == self.SELECT_FAIL: result = NO_THIS_SELECTION elif rp == self.IS_ANSWER: result = ANSWER_LINK.format(HOST.MAIN, self.id) else: result = '{}{}'.format(rp, EXTRA_NOTICE) return result
def multi_select(self, select, special=None): multi_select = select.split(MULTI_FLAG) path = self.root + '/' + os.sep.join(self.path) next_key = '' result = '' keys = self.key_complete(multi_select) if not keys: raise SelectException('Unavailable selects: {}'.format(select)) for k in keys: file_path = os.path.join(path, k) if all_is_file(file_path): files = sorted(self.D[k].keys(), key=self._key) result += '\n' + self.get_files_content(files, file_path)[1] elif special: _key = self.key_complete([special], _next=k)[0] files = sorted(self.D[k][_key].keys(), key=self._key) result += '\n' + self.get_files_content(files, os.path.join(file_path, _key))[1] elif not special and not next_key: next_key = k if next_key: self.path.append(next_key) self.D = self.D[next_key] if result: if next_key: user_result_save(self.id, result.strip()) return self.M_CONTINUE_ASK else: result += decision_links_dumps(user_select_list(self.id), MULTI_FLAG) # 可能需要股东决议书 user_result_save(self.id, result.strip()) return self.M_IS_ANSWER