mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-08-26 12:57:50 +08:00
模块优化
This commit is contained in:
+10
-4
@@ -23,8 +23,8 @@ def export(table, db=None, valid=None, path=None, format='xlsx', show=False):
|
|||||||
|
|
||||||
Note:
|
Note:
|
||||||
参数valid可选值1,0,None,分别表示导出有效,无效,全部子域
|
参数valid可选值1,0,None,分别表示导出有效,无效,全部子域
|
||||||
参数format可选格式:'csv', 'tsv', 'json', 'yaml', 'html', 'xls', 'xlsx',
|
参数format可选格式:'csv', 'tsv', 'json', 'yaml', 'html', 'jira',
|
||||||
'dbf', 'latex', 'ods'
|
'xls', 'xlsx', 'dbf', 'latex', 'ods'
|
||||||
参数path为None会根据format参数和域名名称在项目结果目录生成相应文件
|
参数path为None会根据format参数和域名名称在项目结果目录生成相应文件
|
||||||
|
|
||||||
:param str table: 要导出的表
|
:param str table: 要导出的表
|
||||||
@@ -34,6 +34,11 @@ def export(table, db=None, valid=None, path=None, format='xlsx', show=False):
|
|||||||
:param str path: 导出路径(默认None)
|
:param str path: 导出路径(默认None)
|
||||||
:param bool show: 终端显示导出数据(默认False)
|
:param bool show: 终端显示导出数据(默认False)
|
||||||
"""
|
"""
|
||||||
|
formats = ['csv', 'tsv', 'json', 'yaml', 'html',
|
||||||
|
'latex', 'xls', 'xlsx', 'dbf', 'ods']
|
||||||
|
if format not in formats:
|
||||||
|
logger.log('FATAL', f'不支持{format}格式导出')
|
||||||
|
return
|
||||||
database = Database(db)
|
database = Database(db)
|
||||||
if valid is None:
|
if valid is None:
|
||||||
rows = database.get_data(table)
|
rows = database.get_data(table)
|
||||||
@@ -46,14 +51,15 @@ def export(table, db=None, valid=None, path=None, format='xlsx', show=False):
|
|||||||
if not path:
|
if not path:
|
||||||
path = 'export.' + format
|
path = 'export.' + format
|
||||||
logger.log('INFOR', f'正在将数据库中{table}表导出')
|
logger.log('INFOR', f'正在将数据库中{table}表导出')
|
||||||
|
data = rows.export(format)
|
||||||
try:
|
try:
|
||||||
with open(path, 'w') as file:
|
with open(path, 'w') as file:
|
||||||
file.write(rows.export(format))
|
file.write(data)
|
||||||
logger.log('INFOR', '成功完成导出')
|
logger.log('INFOR', '成功完成导出')
|
||||||
logger.log('INFOR', path)
|
logger.log('INFOR', path)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
with open(path, 'wb') as file:
|
with open(path, 'wb') as file:
|
||||||
file.write(rows.export(format))
|
file.write(data)
|
||||||
logger.log('INFOR', '成功完成导出')
|
logger.log('INFOR', '成功完成导出')
|
||||||
logger.log('INFOR', path)
|
logger.log('INFOR', path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user