作业-haproxy配置文件的增删查(有一个bug不知道咋改)
# 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类型,在拼接
作业-haproxy配置文件的增删查(有一个bug不知道咋改)的更多相关文章
- [ python ] 项目:haproxy配置文件增删改查
1. 开发要求 实现对 haproxy.cfg 增删改查操作 2. 程序介绍 # 作者:hkey # 博客地址:https://www.cnblogs.com/hukey/p/9288279.html ...
- Python3.5 day3作业二:修改haproxy配置文件。
需求: 1.使python具体增删查的功能. haproxy的配置文件. global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 lo ...
- python之haproxy配置文件操作(第三天)
作业: 对haproxy配置文件进行操作 要求: 对haproxy配置文件中backend下的server实现增删改查的功能 一.这个程序有二个版本 1. python2.7版本见haproxy_py ...
- 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...
- 4.在MVC中使用仓储模式进行增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-using-the-repository-pattern-in-mvc/ 系列目录: ...
- hibernate基础增删查改简单实例
hibernate 基础理论知识网上很多,可以百度和google.这里不做多的介绍,以一个User表来开展例子 建一个web-project 我这里用了junit单元测试环境来进行增删查改的测试,别的 ...
- 一套手写ajax加一般处理程序的增删查改
倾述下感受:8天16次驳回.这个惨不忍睹. 好了不说了,说多了都是泪. 直接上代码 : 这个里面的字段我是用动软生成的,感觉自己手写哪些字段太浪费时间了,说多了都是泪 ajax.model层的代码: ...
- ASP.NET动态的网页增删查改
动态页面的增删查改,不多说了,直接上代码 跟前面的一般处理程序一样我上用的同一套三层,只是UI层的东西不一样,在纠结着要不要重新在上一次以前上过的代码: 纠结来纠结去,最后我觉得还上上吧,毕竟不上为我 ...
- SSH框架的多表查询和增删查改 (方法一)中
原创作品,允许转载,转载时请务必标明作者信息和声明本文章==>http://www.cnblogs.com/zhu520/p/7774144.html 这边文章是接的刚刚前一遍的基础上敲的 ...
随机推荐
- OpenGL坐标系的理解
搬运自: https://learnopengl-cn.github.io/01%20Getting%20started/08%20Coordinate%20Systems/#3d 为了将坐标从一个坐 ...
- 图片上传js
var imgURL; function getImgURL(node) { try{ var file = null; if(node.files && node.files[0] ...
- 2019-04-25-day040-数据库的查询
内容回顾 数据的增删改查 插入数据 insert into 表 values (值1,值2...) insert into 表(指定字段名1,字段名2) values (值1,值2...) 删除数据 ...
- MySQL80修改密码
mysql> update user set password=password('123') where user='root' and host='localhost'; ERROR 106 ...
- MAC IDEA mybatis 逆向工程 无结果文件
mac下路径是./src windows 路径是.\src 解决方法,将\纠正过来即可
- webpos登录不上
jo=new JSONObject(((java.sql.Clob)s).getSubString(1, (int) ((java.sql.Clob)s).length()));
- Day03_Python知识总结
1.元组: 元组其实跟列表差不多,也是存一组数,但它一旦创建便不能修改,所以又叫只读列表. names = ("alex","jack","eric ...
- I/O 模型与 Java
本文主要记录 Java 中 I/O 模型及相关知识点 .另,由于自身知识水平有限,如有不正之处,望各位能够谅解,欢迎批评指正! 一.I/O 基础 由于 Java 中 I/O 相关的 API ,无论是 ...
- 炸金花游戏(4)--炸金花AI基准测试评估
前言: 本文将谈谈如何评估测试炸金花的AI, 其实这个也代表一类的问题, 德州扑克也是类似的解法. 本文将谈谈两种思路, 一种是基于基准AI对抗评估, 另一种是基于测试集(人工选定牌谱). 由于炸金花 ...
- ssh操作服务器
# -*- coding: utf-8 -*- """ Created on Wed Mar 20 10:15:16 2019 @author: Kuma 1. ssh连 ...