Update launch.py
Browse files
launch.py
CHANGED
@@ -1,6 +1,32 @@
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
from modules import launch_utils
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
|
6 |
args = launch_utils.args
|
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
from modules import launch_utils
|
4 |
+
import pyngrok
|
5 |
+
|
6 |
+
#ngrok穿透
|
7 |
+
ngrok_use = True
|
8 |
+
ngrokTokenFile='/bushu/Authtoken.txt' # 非必填 存放ngrokToken的文件的路径
|
9 |
+
|
10 |
+
#ngrok
|
11 |
+
def ngrok_start(ngrokTokenFile: str, port: int, address_name: str, should_run: bool):
|
12 |
+
if not should_run:
|
13 |
+
print('Skipping ngrok start')
|
14 |
+
return
|
15 |
+
if Path(ngrokTokenFile).exists():
|
16 |
+
with open(ngrokTokenFile, encoding="utf-8") as nkfile:
|
17 |
+
ngrokToken = nkfile.readline()
|
18 |
+
print('use nrgok')
|
19 |
+
from pyngrok import conf, ngrok
|
20 |
+
conf.get_default().auth_token = ngrokToken
|
21 |
+
conf.get_default().monitor_thread = False
|
22 |
+
ssh_tunnels = ngrok.get_tunnels(conf.get_default())
|
23 |
+
if len(ssh_tunnels) == 0:
|
24 |
+
ssh_tunnel = ngrok.connect(port, bind_tls=True)
|
25 |
+
print(f'{address_name}:' + ssh_tunnel.public_url)
|
26 |
+
else:
|
27 |
+
print(f'{address_name}:' + ssh_tunnels[0].public_url)
|
28 |
+
else:
|
29 |
+
print('skip start ngrok')
|
30 |
|
31 |
|
32 |
args = launch_utils.args
|