作业-haproxy配置文件的增删查(有一个bug不知道咋改)
2024-10-19 00:22:16
# yangqiao #查询
'''
f=open("C:\\aaaaaaaaaaaaa\\haproxy.txt", "r", encoding="utf-8")
haproxy_list = f.readlines()
website_address = input("请输入要查询的网址:")
website_address = "backend " + website_address
lenth=len(haproxy_list)
#print(website_address)
i=0
j=1
for line in haproxy_list:
if website_address in line and line.startswith("backend"):
print(haproxy_list[i])
j=i+1
while "backend" not in haproxy_list[j] :
print(haproxy_list[j])
j+=1
if j >= lenth:
break
elif j == lenth and i == lenth:
print("你输入的内容查询不到")
i+=1
if i == lenth and j==1:
print("你输入的内容查询不到")
f.close() #删除
f=open("C:\\aaaaaaaaaaaaa\\haproxy.txt", "r", encoding="utf-8")
f_new=open("C:\\aaaaaaaaaaaaa\\haproxy_new.txt", "a+", encoding="utf-8")
website_address = input("请输入要删除的网址:")
website_address=eval(website_address)
print(website_address) for line in f:
if website_address["bakend"] in line and line.startswith("backend"):
pass
elif website_address["record"]["server"] in line:
pass
else:
f_new.write(line) f.close()
f_new.close()
''' #新增
f=open("C:\\aaaaaaaaaaaaa\\haproxy.txt", "r", encoding="utf-8")
f_new=open("C:\\aaaaaaaaaaaaa\\haproxy_new.txt", "a+", encoding="utf-8")
haproxy_list = f.readlines()
temple=[]
print(haproxy_list)
lenth=len(haproxy_list)
website_address = input("请输入要新增的网址:")
website_address=eval(website_address)
print("lenth:",lenth)
i=0
j=0
k=0
for line in haproxy_list:
if website_address["backend"] in line and line.startswith("backend") :
#print(haproxy_list[i])
j=i+1
print(j)
print(haproxy_list[j])
#while "backend" not in haproxy_list[j] and j <= lenth-1:
while j <= lenth-1:
if "backend" not in haproxy_list[j]:
if website_address["record"]["server"] in haproxy_list[j]:
j+=1
else:
temple.append(haproxy_list[j])
k+=1
j+=1
#print("ddddddddddddd")
i=j
#print(temple)
elif i <= lenth-1: f_new.write(haproxy_list[i]) if j==0 and i== lenth-1 :
f_new.write("backend "+website_address["backend"]+"\n")
f_new.write(" " + "server " + website_address["record"]["server"] + " weight " + website_address["record"][ "weight"] + " maxconn " + website_address["record"]["maxconn"] + "\n")
i += 1 print(temple)
f.close()
f_new.close() lenth_temple=len(temple)
if lenth_temple != 0: with open("C:\\aaaaaaaaaaaaa\\haproxy_new.txt", "a+", encoding="utf-8") as f_w:
sss="backend "+website_address["backend"]+"\n"
f_w.write(sss)
for line in temple:
f_w.write(line)
zzz=str(" "+"server "+website_address["record"]["server"]+" weight "+website_address["record"]["weight"]+" maxconn "+website_address["record"]["maxconn"]+"\n")
f_w.write(zzz)
Traceback (most recent call last):
File "C:/Users/lcl/PycharmProjects/untitled/day1/修改haproxy配置文件.py", line 105, in <module>
zzz=str(" "+"server "+website_address["record"]["server"]+" weight "+website_address["record"]["weight"]+" maxconn "+website_address["record"]["maxconn"]+"\n")
TypeError: must be str, not int
这样相加,因为里面有INT类型,导致最后zzz不是字符串类型,需要先转换成str类型,在拼接
最新文章
- App制作
- ReactiveCocoa源码拆分解析(五)
- 【转】libevent源码分析
- jsp页面使用el 按key获取map中的对应值
- 一步步编写avalon组件02:分页组件
- HTML+CSS纯干货就业前基础到精通系统学习2016/9/3
- freemarker判断记录集是不是为空
- 【随记】还原SQL Server数据库步骤
- shell入门之流程控制语句 分类: 学习笔记 linux ubuntu 2015-07-10 16:38 89人阅读 评论(0) 收藏
- office2010删除多余空行
- 调查程序phpquestionnaire 2.2中文安装注意
- Nancy之实现API
- Vijos1327回文词【动态规划】
- 小米红米1 android 4.4.4上操作数据库异常问题
- Vuforia开发完全指南---License Manager和Target Manager详解
- 举个栗子看如何做MySQL 内核深度优化
- error.c
- 地址重写 No input file specified的解决方法
- [development][http][libhtp] suricata的http库--libhtp
- 使用swift和rails来实现ios账号系统
热门文章
- Mysql慢查询-Mysql慢查询详细教程
- zabbix添加IIS网站计数器(并发连接数)详解
- TP5 model层 返回的对象转数组
- springboot application.properties 常用完整版配置信息
- js中Attribute和property的区别与联系
- thinkphp5.0验证的封装
- Django的forms表单组件批量设置字段样式
- 无空格字符串的break-all的性能问题
- 转:Eclipse Memory Analyzer入门学习笔记
- $(window).scroll()无法触发问题