This repository has been archived by the owner on Jan 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
settings.py
111 lines (101 loc) · 3.55 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from functions.ui_modules import NavModule
from tornado.log import app_log as log
from tornado.web import gen
import os
import tormysql
import pymysql
# 数据库配置
db_host = 'localhost'
db_port = 3306
db_name = 'OpenStark'
db_user = 'root'
db_password = '123456'
db_charset = 'utf8'
db_pool_size = 150
db_pool_recycle = 3600
db_timeout = 5
# 应用配置
template_path = os.path.join(os.path.dirname(__file__), 'templates')
static_path = os.path.join(os.path.dirname(__file__), 'static')
login_url = '/admin/login'
ui_modules = {'nav': NavModule}
cookie_secret = 'SQYMzDHiShGCl1gx/e4g5HHS7Be1UkPpk7eJxklvKmE='
xsrf_cookie = True
debug = True
# 定时任务配置
cycle_time = 5 # 定时任务监控周期(秒)
# 创建数据库连接池
pool = tormysql.helpers.ConnectionPool(
max_connections=db_pool_size,
idle_seconds=db_pool_recycle,
wait_connection_timeout=db_timeout,
host=db_host,
port=db_port,
user=db_user,
passwd=db_password,
db=db_name,
charset=db_charset,
cursorclass=pymysql.cursors.DictCursor,
autocommit=True
)
# 初始化数据库
@gen.coroutine
def init_db():
sql = """
CREATE TABLE IF NOT EXISTS `t_options` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`value` text NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ix_t_options_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `t_projects` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`user` text,
`status` smallint(6) NOT NULL DEFAULT '1' COMMENT '0 禁用, 1 正常',
PRIMARY KEY (`id`),
UNIQUE KEY `ix_t_projects_name` (`name`),
KEY `ix_t_projects_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `t_settings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`project` int(11) NOT NULL,
`type` varchar(20) NOT NULL COMMENT 'url 接口、crypt 加解密、host 环境、job 任务、case 用例、suite 测试集、param 参数、report 报告、group 部门',
`name` varchar(1000) NOT NULL,
`value` longtext NOT NULL,
`status` smallint(6) NOT NULL DEFAULT '1' COMMENT '0 禁用, 1 正常, job[0 计划中, 1 排队中, 2 测试中, 3 已完成, 4 暂停, 5 异常]',
`sort` smallint(6) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `project` (`project`),
KEY `ix_t_settings_type` (`type`),
KEY `ix_t_settings_status` (`status`),
CONSTRAINT `t_settings_ibfk_1` FOREIGN KEY (`project`) REFERENCES `t_projects` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `t_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(60) DEFAULT '',
`password` varchar(255) NOT NULL DEFAULT '',
`realname` varchar(50) DEFAULT '',
`email` varchar(100) NOT NULL DEFAULT '',
`group` int(10) DEFAULT NULL,
`role` smallint(6) NOT NULL DEFAULT '2' COMMENT '0 超级管理员, 1 管理员, 2 普通用户',
`status` smallint(6) NOT NULL DEFAULT '1' COMMENT '0 禁用, 1 正常',
`registerTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`lastLoginTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `ix_t_users_email` (`email`),
UNIQUE KEY `ix_t_users_username` (`username`),
KEY `ix_t_users_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
tx = yield pool.begin()
try:
log.info('初始化数据库SQL:\n{}'.format(sql))
yield tx.execute(sql)
except pymysql.Error as e:
yield tx.rollback()
log.error('初始化数据库失败#{}'.format(e))
else:
yield tx.commit()
log.info('初始化数据库成功')