forked from XX-net/XX-Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
135 lines (101 loc) · 3.35 KB
/
Copy pathstart.py
File metadata and controls
135 lines (101 loc) · 3.35 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
# coding:utf-8
import os, sys
import time
import atexit
# reduce resource request for threading
# for OpenWrt
import threading
threading.stack_size(128*1024)
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')
data_launcher_path = os.path.join(data_path, 'launcher')
noarch_lib = os.path.join(root_path, 'lib', 'noarch')
sys.path.append(noarch_lib)
common_lib = os.path.join(root_path, 'lib', 'common')
sys.path.append(common_lib)
def create_data_path():
if not os.path.isdir(data_path):
os.mkdir(data_path)
if not os.path.isdir(data_launcher_path):
os.mkdir(data_launcher_path)
data_gae_proxy_path = os.path.join(data_path, 'gae_proxy')
if not os.path.isdir(data_gae_proxy_path):
os.mkdir(data_gae_proxy_path)
create_data_path()
from instances import xlog
has_desktop = True
if sys.platform.startswith("linux"):
def X_is_running():
try:
from gi.repository import Gtk
from subprocess import Popen, PIPE
p = Popen(["xset", "-q"], stdout=PIPE, stderr=PIPE)
p.communicate()
return p.returncode == 0
except:
return False
if X_is_running():
from gtk_tray import sys_tray
else:
from non_tray import sys_tray
has_desktop = False
elif sys.platform == "win32":
win32_lib = os.path.join(root_path, 'lib', 'win32')
sys.path.append(win32_lib)
from win_tray import sys_tray
elif sys.platform == "darwin":
darwin_lib = os.path.abspath( os.path.join(python_path, 'lib', 'darwin'))
sys.path.append(darwin_lib)
extra_lib = "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjc"
sys.path.append(extra_lib)
try:
import mac_tray as sys_tray
except:
from non_tray import sys_tray
else:
print(("detect platform fail:%s" % sys.platform))
from non_tray import sys_tray
has_desktop = False
import config
import web_control
import module_init
import update
import setup_win_python
import update_from_github
def exit_handler():
print('Stopping all modules before exit!')
module_init.stop_all()
web_control.stop()
atexit.register(exit_handler)
def main():
# change path to launcher
global __file__
__file__ = os.path.abspath(__file__)
if os.path.islink(__file__):
__file__ = getattr(os, 'readlink', lambda x: x)(__file__)
os.chdir(os.path.dirname(os.path.abspath(__file__)))
xlog.info("start XX-Net %s", update_from_github.current_version())
web_control.confirm_xxnet_exit()
setup_win_python.check_setup()
module_init.start_all_auto()
web_control.start()
if has_desktop and config.get(["modules", "launcher", "popup_webui"], 1) == 1:
host_port = config.get(["modules", "launcher", "control_port"], 8085)
import webbrowser
webbrowser.open("http://127.0.0.1:%s/" % host_port)
update.start()
if config.get(["modules", "launcher", "show_systray"], 1):
sys_tray.serve_forever()
else:
while True:
time.sleep(100)
module_init.stop_all()
sys.exit()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt: # Ctrl + C on console
module_init.stop_all()
os._exit(0)