#Author by Andy
#_*_ coding:utf-8 _*_
import sys
import time
Path="E:\my python study\\files\haproxy.txt"
Path_new="E:\my python study\\files\haproxy_new.txt"
examples='''\033[31;1m内容格式范例 :
arg={
'backend': 'www.oldgirl.org',
'record':{
'server': '100.1.7.10',
'weight': 20,
'maxconn': 30
}
}
\033[;0m'''
#定义主函数
def main_func():
print("Welcome to use this program!")
choice=input("See what you can do:\n"
"Add\n"
"Delete\n"
"Q or q to end program.\n"
"Search\n"
":")
return choice
#定义字符串转字典函数
def str_to_dict():
print("请输入要添加的内容:")
stop_input = ''
user_input = ''
for line in iter(input,''):
user_input = user_input+line + '\n' #input遇到空行才停止,默认是遇到回车停止
dict = eval(user_input.strip("arg = "))
return dict
#定义追加函数
def add(info):
backend_value=info['backend']
record_value=info['record']
f=open(Path,'a+',encoding='utf-8')
f.write('\nbackend %s \n' %backend_value)
f.write('\t\tserver %s weight %s maxconn %s\n'
%(record_value['server'],record_value['weight'],record_value['maxconn']))
time.sleep(2)
f.closed
# add(str_to_dict())
#定义删除函数
def dele(info):
backend_value=info['backend']
record_value=info['record']
del_record='\t\tserver %s weight %s maxconn %s\n' \
%(record_value['server'],record_value['weight'],record_value['maxconn'])
f = open(Path,'r+',encoding='utf-8')
f_new=open(Path_new,'w',encoding='utf-8')
for line in f:
if backend_value in line:
line=line.replace(line,'')
elif del_record == line:
line=line.replace(del_record,'')
f_new.write(line)
time.sleep(2)
f.closed
f_new.closed
#dele(str_to_dict()) def find_keywords(keywords):
f=open(Path,'r+',encoding='utf-8')
while True:
line = f.readline()
if keywords in line:
f.seek(f.tell()+1)
print(f.readline().strip())
target=f.readline().strip()
time.sleep(2)
f.closed
return target
while True:
choice=main_func()
if choice=='Add':
print(examples)
add(str_to_dict())
elif choice=='Search':
keywords=input("请输入关键字:")
find_keywords(keywords)
elif choice=='Delete':
print(examples)
dele(str_to_dict())
elif choice=='q'or choice =='Q':
print("Bye-bye!")
exit() 文件格式:
global
log 127.0.0.1 local2
daemon
maxconn 256
log 127.0.0.1 local2 info
defaults
log global
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
option dontlognull listen stats :8888
stats enable
stats uri /admin
stats auth admin:1234 frontend oldboy.org
bind 0.0.0.0:80
option httplog
option httpclose
option forwardfor
log global
acl www hdr_reg(host) -i www.oldboy1.org
use_backend www.oldboy1.org if www backend www.oldboy.org
server 100.1.7.9 100.1.7.9 weight 20 maxconn 3000 需求:
1、查
输入:www.oldboy.org
获取当前backend下的所有记录 2、新建
输入:
arg = {
'bakend': 'www.oldboy.org',
'record':{
'server': '100.1.7.9',
'weight': 20,
'maxconn': 30
}
} 3、删除
输入:
arg = {
'bakend': 'www.oldboy.org',
'record':{
'server': '100.1.7.9',
'weight': 20,
'maxconn': 30
}
}

python3 文件增删查的更多相关文章

  1. linus上运行jar包文件增删查

    package com.osplat.util; import com.alibaba.fastjson.JSON; import com.osplat.bean.Resultmodel; impor ...

  2. HDFS Java Client对hdfs文件增删查改

      step1:增加依赖 pom.xml           ...      <!-- https://mvnrepository.com/artifact/org.apache.hadoop ...

  3. 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...

  4. 4.在MVC中使用仓储模式进行增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-using-the-repository-pattern-in-mvc/ 系列目录: ...

  5. 5.在MVC中使用泛型仓储模式和工作单元来进行增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...

  6. hibernate基础增删查改简单实例

    hibernate 基础理论知识网上很多,可以百度和google.这里不做多的介绍,以一个User表来开展例子 建一个web-project 我这里用了junit单元测试环境来进行增删查改的测试,别的 ...

  7. 8天学通MongoDB——第二天 细说增删查改

    原文地址:http://www.cnblogs.com/huangxincheng/archive/2012/02/19/2357846.html 看过上一篇,相信大家都会知道如何开启mongodb了 ...

  8. [置顶] cocos2dx sqllite 增删查改等操作

    首先导入文件shell.c sqllite3.c sqlite3.h sqlite3etx.h文件(注意在生成安卓项目是 不要将shell.c写进android.mk文件中,写进去在cywin中生成会 ...

  9. 一套手写ajax加一般处理程序的增删查改

    倾述下感受:8天16次驳回.这个惨不忍睹. 好了不说了,说多了都是泪. 直接上代码 : 这个里面的字段我是用动软生成的,感觉自己手写哪些字段太浪费时间了,说多了都是泪 ajax.model层的代码: ...

随机推荐

  1. 零成本实现Web性能测试:基于Apache JMeter

    http://book.51cto.com/art/201204/327301.htm

  2. bitnami redmine每日自动备份

    主要思路:在半夜时停止服务,进行完整备份,然后再开启服务. 1.主脚本backup.bat: call backup-stopserver.batping /n 20 127.1 >nul ca ...

  3. Linux中环境变量文件及配置

    Linux中环境变量文件及配置   一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统 ...

  4. PostgreSQL的OGG -- bucardo

    bucardo是PostgreSQL数据库中实现双向同步的软件,可以实现PostgreSQL数据库的双master的方案,不过bucardo中的同步都是异步的,它是通过触发器记录变化,程序是perl写 ...

  5. mysql共享表空间转独立表空间

    使用innodb_export_import.py脚本: https://github.com/thecpaneladmin/innodb-tools 安装MySQL-python模块: shell ...

  6. 市面上主流服务器简单介绍(apache、IIS、tomcat..)

    apache:apache(阿帕奇)的具体介绍可以参看apache的网站(http://www.apache.org/),或者在网上随便搜搜吧.apache是世界使用排名第一的web服务器软件:它可以 ...

  7. win7安装oracle11g64位提示环境变量Path长度超出

    解决办法:安装包以管理员方式运行

  8. What technical details should a programmer of a web application consider before making the site public?

    What things should a programmer implementing the technical details of a web application consider bef ...

  9. Boost学习笔记(六) progress_display注意事项

    progress_display可以用作基本的进度显示,但它有个固有的缺陷:无法把进度显示输出与程序的输出分离. 这是因为progress_display和所有C++程序一样,都向标准输出(cout) ...

  10. iOS 10 UserNotifications 使用说明

    本教程以贴代码为主.尽可能直观,少量说明. 注意:XCode8的需要手动开启主target Capabilities中的Push Notification. 关于创建多个target后真机测试的证书问 ...