def delLabelRecord(ha, dict_input): with open(ha, 'r') as all_content, open(ha + '.new', 'w+') as all_content_new: all_content_dict = getAllContentDict(ha) del_str = " server %s %s weight %s maxconn %s\n" % ( dict_input['server'], dict_input['server'], dict_input['weight'], dict_input['maxconn']) if dict_input['label'] in all_content_dict.keys(): flag = False for line in all_content.readlines(): if line.strip('\n') == dict_input['label']: flag = True all_content_new.write(line) continue if flag == True and line == del_str: flag = False continue all_content_new.write(line) else: pass print("删除成功!") choice = input("请选择是否要更新到线上(y/n):").strip() if index.choiceIf(choice) == True: print("你选择的是更新到线上,系统即将把修改后的文件发布到线上并返回系统首页!") if os.path.exists(ha + '.bak'): os.remove(ha + '.bak') os.rename(ha, ha + '.bak') os.rename(ha + '.new', ha) time.sleep(1) index.chooseView(index.showView()) if index.choiceIf(choice) == False: print("你选择的是放弃更新,系统即将返回系统首页!") if os.path.exists(ha + '.new'): os.remove(ha + '.new') index.chooseView(index.showView())
def chgLabelRecord(ha): # 获取用户修改label记录值 print("下面请按照提示输入你要修改的记录值!") dict_input1 = index.getInputConnet() print("下面请按照提示输入你要修改后的记录值!") dict_input2 = index.getInputConnet() with open(ha, "r") as all_content, open(ha + ".new", "w+") as all_content_new: all_content_dict = getAllContentDict(ha) old_str = " server %s %s weight %s maxconn %s\n" % ( dict_input1["server"], dict_input1["server"], dict_input1["weight"], dict_input1["maxconn"], ) new_str = " server %s %s weight %s maxconn %s\n" % ( dict_input2["server"], dict_input2["server"], dict_input2["weight"], dict_input2["maxconn"], ) print(new_str) if dict_input1["label"] in all_content_dict.keys(): flag = False for line in all_content.readlines(): if line.strip("\n") == dict_input1["label"]: flag = True all_content_new.write(line) continue if flag == True and line == old_str: all_content_new.write(new_str) flag = False continue all_content_new.write(line) else: pass print("修改成功!") choice = input("请选择是否要更新到线上(y/n):").strip() if index.choiceIf(choice) == True: print("你选择的是更新到线上,系统即将把修改后的文件发布到线上并返回系统首页!") if os.path.exists(ha + ".bak"): os.remove(ha + ".bak") os.rename(ha, ha + ".bak") os.rename(ha + ".new", ha) time.sleep(1) index.chooseView(index.showView()) if index.choiceIf(choice) == False: print("你选择的是放弃更新,系统即将返回系统首页!") if os.path.exists(ha + ".new"): os.remove(ha + ".new") index.chooseView(index.showView())
def chgLabelRecord(ha): #获取用户修改label记录值 print("下面请按照提示输入你要修改的记录值!") dict_input1 = index.getInputConnet() print("下面请按照提示输入你要修改后的记录值!") dict_input2 = index.getInputConnet() with open(ha, 'r') as all_content, open(ha + '.new', 'w+') as all_content_new: all_content_dict = getAllContentDict(ha) old_str = " server %s %s weight %s maxconn %s\n" % ( dict_input1['server'], dict_input1['server'], dict_input1['weight'], dict_input1['maxconn']) new_str = " server %s %s weight %s maxconn %s\n" % ( dict_input2['server'], dict_input2['server'], dict_input2['weight'], dict_input2['maxconn']) print(new_str) if dict_input1['label'] in all_content_dict.keys(): flag = False for line in all_content.readlines(): if line.strip('\n') == dict_input1['label']: flag = True all_content_new.write(line) continue if flag == True and line == old_str: all_content_new.write(new_str) flag = False continue all_content_new.write(line) else: pass print("修改成功!") choice = input("请选择是否要更新到线上(y/n):").strip() if index.choiceIf(choice) == True: print("你选择的是更新到线上,系统即将把修改后的文件发布到线上并返回系统首页!") if os.path.exists(ha + '.bak'): os.remove(ha + '.bak') os.rename(ha, ha + '.bak') os.rename(ha + '.new', ha) time.sleep(1) index.chooseView(index.showView()) if index.choiceIf(choice) == False: print("你选择的是放弃更新,系统即将返回系统首页!") if os.path.exists(ha + '.new'): os.remove(ha + '.new') index.chooseView(index.showView())
def delLabelRecord(ha, dict_input): with open(ha, "r") as all_content, open(ha + ".new", "w+") as all_content_new: all_content_dict = getAllContentDict(ha) del_str = " server %s %s weight %s maxconn %s\n" % ( dict_input["server"], dict_input["server"], dict_input["weight"], dict_input["maxconn"], ) if dict_input["label"] in all_content_dict.keys(): flag = False for line in all_content.readlines(): if line.strip("\n") == dict_input["label"]: flag = True all_content_new.write(line) continue if flag == True and line == del_str: flag = False continue all_content_new.write(line) else: pass print("删除成功!") choice = input("请选择是否要更新到线上(y/n):").strip() if index.choiceIf(choice) == True: print("你选择的是更新到线上,系统即将把修改后的文件发布到线上并返回系统首页!") if os.path.exists(ha + ".bak"): os.remove(ha + ".bak") os.rename(ha, ha + ".bak") os.rename(ha + ".new", ha) time.sleep(1) index.chooseView(index.showView()) if index.choiceIf(choice) == False: print("你选择的是放弃更新,系统即将返回系统首页!") if os.path.exists(ha + ".new"): os.remove(ha + ".new") index.chooseView(index.showView())