拆分配置文件
This commit is contained in:
parent
480cc74e6f
commit
77559364e2
|
@ -10,7 +10,7 @@ from datetime import datetime
|
||||||
# 定义公共的部分
|
# 定义公共的部分
|
||||||
path = Path(__file__)
|
path = Path(__file__)
|
||||||
etc_dir = path.parent.parent / "etc"
|
etc_dir = path.parent.parent / "etc"
|
||||||
config_file_patch = etc_dir / "test_config.yml"
|
config_file_patch = etc_dir / "db_config.yml"
|
||||||
|
|
||||||
|
|
||||||
# 获取配置文件
|
# 获取配置文件
|
||||||
|
|
|
@ -3,6 +3,7 @@ import _load
|
||||||
|
|
||||||
import faker_data
|
import faker_data
|
||||||
import csv
|
import csv
|
||||||
|
import yaml
|
||||||
|
|
||||||
from schedule import every, repeat, run_pending
|
from schedule import every, repeat, run_pending
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -20,10 +21,20 @@ from random import choice
|
||||||
"""
|
"""
|
||||||
#TODO(MH):目前这些参数是写死的,后续看使用情况,也可以去读配置文件的
|
#TODO(MH):目前这些参数是写死的,后续看使用情况,也可以去读配置文件的
|
||||||
|
|
||||||
|
|
||||||
# 定义公共的部分
|
# 定义公共的部分
|
||||||
path = Path(__file__)
|
path = Path(__file__)
|
||||||
|
etc_dir = path.parent.parent / "etc"
|
||||||
|
config_file_patch = etc_dir / "file_config.yml"
|
||||||
|
|
||||||
|
# 获取配置文件
|
||||||
|
with open(config_file_patch, "r", encoding='utf-8') as fy:
|
||||||
|
config = yaml.safe_load(fy)
|
||||||
|
|
||||||
|
# 默认为当前的目录
|
||||||
data_dir = path.parent.parent / "data"
|
data_dir = path.parent.parent / "data"
|
||||||
|
if 'DATADIR' in config.keys() and config['DATADIR']:
|
||||||
|
data_dir = Path(config['DATADIR'])
|
||||||
|
|
||||||
# 初始化目录
|
# 初始化目录
|
||||||
if not data_dir.exists():
|
if not data_dir.exists():
|
||||||
# shutil.rmtree(data_dir)
|
# shutil.rmtree(data_dir)
|
||||||
|
@ -59,13 +70,13 @@ def new():
|
||||||
faker_data.save_data_csv(finfo[4], lines=100)
|
faker_data.save_data_csv(finfo[4], lines=100)
|
||||||
|
|
||||||
|
|
||||||
# 每2秒插入10条数据
|
# 每2秒插入N条数据
|
||||||
@repeat(every(2).seconds)
|
@repeat(every(2).seconds)
|
||||||
def inserting():
|
def inserting():
|
||||||
finfo = file_info()
|
finfo = file_info()
|
||||||
if finfo[4].exists():
|
if finfo[4].exists():
|
||||||
print('insert...')
|
print('insert...')
|
||||||
datas = faker_data.faker_data(lines=200)[1:]
|
datas = faker_data.faker_data(lines=config['InsertRows'])[1:]
|
||||||
with open(finfo[4], 'a+', encoding='utf-8', newline='') as file_csv:
|
with open(finfo[4], 'a+', encoding='utf-8', newline='') as file_csv:
|
||||||
writer = csv.writer(file_csv, delimiter=',',
|
writer = csv.writer(file_csv, delimiter=',',
|
||||||
quotechar='"', quoting=csv.QUOTE_ALL)
|
quotechar='"', quoting=csv.QUOTE_ALL)
|
||||||
|
@ -85,10 +96,10 @@ def deleting_data():
|
||||||
if len(files) > 1:
|
if len(files) > 1:
|
||||||
file = choice(files[:-1])
|
file = choice(files[:-1])
|
||||||
print(str(file) + "start delete data ....")
|
print(str(file) + "start delete data ....")
|
||||||
# 删除掉前100条数据
|
# 删除掉前N条数据
|
||||||
with open(file, 'rb') as fr:
|
with open(file, 'rb') as fr:
|
||||||
data = fr.readlines()
|
data = fr.readlines()
|
||||||
new_data = data[100:]
|
new_data = data[config['DeleteRows']:]
|
||||||
# 少于100条的不删除
|
# 少于100条的不删除
|
||||||
if len(new_data) > 100:
|
if len(new_data) > 100:
|
||||||
with open(file, 'wb') as fw:
|
with open(file, 'wb') as fw:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#数据库配置文件
|
#数据库配置文件
|
||||||
|
|
||||||
# 数据库类型,目前仅支持MySQL和Oracle
|
# 通用配置
|
||||||
|
# 数据库类型,目前仅支持MySQL和Oracle,注意大小写
|
||||||
DBType: Oracle
|
DBType: Oracle
|
||||||
# 数据库地址
|
# 数据库地址
|
||||||
IP: "10.10.29.41"
|
IP: "10.10.29.41"
|
||||||
|
@ -11,7 +12,9 @@ DBUSER: "test"
|
||||||
DBPASSWD: "test123"
|
DBPASSWD: "test123"
|
||||||
# 库名
|
# 库名
|
||||||
DATABASES: "TEST"
|
DATABASES: "TEST"
|
||||||
# 服务名-Oracle
|
|
||||||
SERVER: "orcl"
|
|
||||||
# 每秒中插入多少条数据
|
# 每秒中插入多少条数据
|
||||||
InsertRows: 200
|
InsertRows: 200
|
||||||
|
|
||||||
|
|
||||||
|
# 服务名-Oracle
|
||||||
|
SERVER: "orcl"
|
|
@ -0,0 +1,11 @@
|
||||||
|
#生成文件的配置文件
|
||||||
|
vsersion : 1.3
|
||||||
|
|
||||||
|
# 生成csv输出的目录,默认为程序的运行目录。需要自定义就打开配置
|
||||||
|
#DATADIR : "D:\\data"
|
||||||
|
|
||||||
|
# 每次插入多少条数据
|
||||||
|
InsertRows: 200
|
||||||
|
# 每次删除多少条数据
|
||||||
|
DeleteRows: 100
|
||||||
|
|
Loading…
Reference in New Issue