-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_operator.py
executable file
·122 lines (91 loc) · 2.83 KB
/
install_operator.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
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python3.5
# -*- coding: utf-8 -*-
# 安装配置环境时执行的程序
from util.common.logger import base_info
# 基础设置
info = """
安装一台新服务器需要对本程序的环境进行配置:
具体操作如下:
1. 代理设置配置 => ./util/web/config.py
2. 数据库设置配置 => ./util/database/config.py
3. Redis设置配置 => ./util/redis/config.py
---
是否按顺序全部配置?(Y/N)
"""
operator_info = """
请选择你需要配置的文件对应的数字:
【0】 退出程序
【1】 代理文件设置
【2】 数据库文件设置
【3】 Redis文件设置
---
"""
# 代理设置配置文件模板
proxy_config_template = """
# -*- coding: utf-8 -*-
#
# 这里存放有关的配置文件
#
# constant 需要迁移走
orderno = "{orderno}"
secret = "5a6fee02149541d18b6e70de5059538b"
ip_port = "forward.xdaili.cn:80"
raw_url = "http://2017.ip138.com/ic.asp"
"""
db_config_template = """
database_info = {
"host":"localhost",
"port":3306,
"user":"root",
"passwd":"%s",
"db":"spider_data",
"charset":"utf8"
}
"""
redis_config_template = """
host = "{host}"
port = {port}
"""
def proxy_config():
'''代理程序设置'''
orderno = input("请输入转发请求代理订单号!")
base_info("配置代理请求转发成功!")
with open("./util/web/config.py","w") as config:
config.writelines(proxy_config_template.format(orderno=orderno))
def database_config():
'''数据库设置'''
passwd = input("请输入本机数据库root密码!")
base_info("配置数据库密码成功!")
with open("./util/database/config.py","w") as config:
config.writelines(db_config_template%passwd)
def redis_config():
'''redis设置'''
host = input("请输入本机Redis-Server的Host")
port = input("请输入本机Redis-Server的端口号(默认是6379)")
with open("./util/redis/config.py","w") as config:
config.writelines(redis_config_template.format(host=host, port=port))
if __name__ == "__main__":
base_info("开始配置一台新机器...")
yorn = input(info)
# 按照顺序配置所有文件
if yorn.strip() == "Y":
proxy_config()
database_config()
redis_config()
# 用户手动选择需要配置的文件
elif yorn.strip() == "N":
while True:
operator = input(operator_info)
if operator.strip() == "0":
print("设置文件配置程序退出...")
break
elif operator.strip() == "1":
proxy_config()
elif operator.strip() == "2":
database_config()
elif operator.strip() == "3":
redis_config()
else:
continue
else:
raise ValueError("没有该选项!")