标签:odi gradient rip legend tran first css bottom 作业
def add ():
d = query()
add = input("please input proxy your add:")
count = 0
f_first.seek(0)
for line in f_first:
if count == d[max(d)] :
f_second.write("\t\t"+add+"\n")
f_second.write(line)
count +=1
def change ():
d = query()
old = input("please input proxy your choice:")
new = input("please input new proxy;")
count = 0
f_first.seek(0)
for line in f_first:
count +=1
if count == d[old] :
f_second.write("\t\t" + new + "\n")
continue
f_second.write(line)
def delete():
d = query()
delete = input("please input proxy your want delete:")
count = 0
f_first.seek(0)
for line in f_first:
count += 1
if count == d[delete]:
continue
f_second.write(line)
def query ():
d = {}
flag = False
url = input("please input url:")
count = 0
for line in f_first:
count += 1
if line.startswith("backend") and url in line:
flag = True
continue
if line.startswith("backend") and flag:
flag = False
if flag:
d[line.strip()] = count
for i in d:
print(i)
return d
def main ():
menu = {1: "add", 2: "delete", 3: "change", 4: "query",5:"quit"}
for i in range(1,6):
print (i,menu[i])
action = int(input("choice:"))
if action ==5:quit()
list_url = []
with open("haproxy.conf", encoding="utf8") as f_first:
for line in f_first:
if line.startswith("backend"):
list_url.append(line.strip())
for i in list_url:
print (i.split(" ")[1])
return action
import os
with open("haproxy.conf", encoding="utf8") as f_first, open("haproxy1.conf", mode="w+",
encoding="utf8") as f_second:
choice = main ()
if choice == 1 : add()
if choice == 2 : delete()
if choice == 3 : change()
if choice == 4 : query ()
os.rename("haproxy.conf","haproxy_bak.conf")
os.rename("haproxy1.conf","haproxy.conf")
标签:odi gradient rip legend tran first css bottom 作业
原文地址:http://www.cnblogs.com/kimyeee/p/6687150.html