#增删改查之查def look(): while 1 : enter = input("查看:如www.oldboy.org\n") l = [] flag = False with open("haproxy.conf") as enter_read: for line in enter_read: if line.startswith("backend") and enter in line: flag = True continue if line.startswith("backend") and flag: break if flag: l.append(line.strip()) for out in l: print(out)#增删改查之删def delete(): dels = input("删除:如www.oldboy.org\n") with open("haproxy.conf") as dels_read,open("text",mode="w") as dels_del: for line in dels_read: dels_del.write(line) if line.startswith("backend") and dels in line: break#增删改查之改def amend(): modify = input("修改:如www.oldboy.org\n") servers = " server 1111 weight 2222 maxconn 3333" with open("haproxy.conf") as modify_read,open("text",mode="w") as modify_m: for line in modify_read: modify_m.write(line) if line.startswith("backend") and modify in line: modify_m.write(servers) break#增删改查之增def add(): agg = input("增加:如www.oldboy.org\n") servers = " server 1111 weight 2222 maxconn 3333\n" with open("haproxy.conf") as agg_read, open("text", mode="w") as agg_a: for line in agg_read: agg_a.write(line) if line.startswith("backend") and agg in line: agg_a.write(servers) #列表def list(): user_list = ‘‘‘ 1.look 查看: 2.delete 删除: 3.amend 修改: 4.add 增加: 0.exit 退出: ‘‘‘ print(user_list) def mains(): list() judge = input("弄什么:") if judge==1: look() if judge==2: delete() if judge==3: amend() if judge==4: add() if judge==0: exit()mains()
时间: 2024-08-11 01:33:44