forked from XX-net/XX-Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
96 lines (72 loc) · 2.38 KB
/
Copy pathconfig.py
File metadata and controls
96 lines (72 loc) · 2.38 KB
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
import os
from instances import xlog
import yaml
from distutils.version import LooseVersion
current_path = os.path.dirname(os.path.abspath(__file__))
root_path = os.path.abspath( os.path.join(current_path, os.pardir))
data_path = os.path.join(root_path, 'data')
config_path = os.path.join(data_path, 'launcher', 'config.yaml')
config = {}
def load():
global config, config_path
try:
config = yaml.load(open(config_path, 'r'))
#print yaml.dump(config)
except Exception as exc:
print("Error in configuration file:", exc)
def save():
global config, config_path
try:
yaml.dump(config, open(config_path, "w"))
except Exception as e:
xlog.warn("save config %s fail %s", config_path, e)
def get(path, default_val=""):
global config
try:
value = default_val
cmd = "config"
for p in path:
cmd += '["%s"]' % p
value = eval(cmd)
return value
except:
return default_val
def _set(m, k_list, v):
k0 = k_list[0]
if len(k_list) == 1:
m[k0] = v
return
if k0 not in m:
m[k0] = {}
_set(m[k0], k_list[1:], v)
def set(path, val):
global config
_set(config, path, val)
def recheck_module_path():
global config
need_save_config = False
modules = ["gae_proxy", "launcher", "php_proxy"]
for module in modules:
if module not in ["launcher", "php_proxy"]:
if not os.path.isdir(os.path.join(root_path, module)):
del config[module]
continue
if get(["modules", module, "auto_start"], -1) == -1:
set(["modules", module, "auto_start"], 1)
if get(["modules", "launcher", "control_port"], 0) == 0:
set(["modules", "launcher", "control_port"], 8085)
set(["modules", "launcher", "allow_remote_connect"], 0)
if get(["modules", "launcher", "proxy"], 0) == 0:
# default enable PAC on startup.
set(["modules", "launcher", "proxy"], "pac")
#if get(["modules", "gae_proxy", "control_port"], 0) == 0:
# set(["modules", "gae_proxy", "control_port"], 8084)
if get(["modules", "php_proxy", "control_port"], 0) == 0:
set(["modules", "php_proxy", "control_port"], 8083)
return need_save_config
def init():
if os.path.isfile(config_path):
load()
if recheck_module_path():
save()
init()