def query_shell(context): (f_log, f_src) = context while 1: cmd = raw_input(">") cmd = cmd.strip() if cmd == '\\q' or cmd == 'q': instr = raw_input('Do you want to quit? (Y or N)') instr = instr.strip() if instr and (instr[0] == 'n' or instr[0] == 'N'): continue else: print('Any bug or suggestion, plz send to <*****@*****.**>') return if cmd == '\\i' or cmd == 'i': print ("INF: src:> %s\nINF: log:> %s\n" % (f_src, f_log)) continue if cmd == '\\h' or cmd == 'h': usage_cmd() continue if cmd[:2] == '\l': cmd = cmd[2:].strip() t_log = get_input_file_name(cmd) if not t_log: print ("Err: Invalid log file, keep log unchanged. \n") else: print ("INF: Log changed to %s\n" % t_log) f_log = t_log continue if cmd[:2] == '\s': cmd = cmd[2:].strip() t_src = get_input_file_name(cmd) if not t_src: print ("Err: Invalid Src file, keep Src unchanged. \n") continue else: print ("INF: Src changed to %s\n" % t_src) print ("Plz hold for a while, will back soon. :-) \n") f_src = t_src #import into new source libappear.import_in_src(serialize_file,f_src) continue # warning for too short query key if len(cmd) <= 3: instr = raw_input("[Warning] Keyword Length <= 3, might too many output, do it (Y or N)") instr = instr.strip() if(instr and (instr[0] == 'N' or instr[0] == 'n')): continue libappear.query_key(cmd, f_log)
def main(): global f_log, f_src, serialize_file init_appear() (f_log, f_src) = get_src_log_path() serialize_file = os.path.basename(f_src) + '.dict' if MYNODE and os.path.exists(MYNODE): serialize_file = os.path.join(MYNODE, serialize_file) #import source data libappear.import_in_src(serialize_file,f_src) #into shell loop query_shell((f_log, f_src)) print ("::Bye!\n")