updates
This commit is contained in:
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
rich
|
||||||
@@ -1,27 +1,30 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from rich import print
|
|
||||||
|
|
||||||
os.chdir('/root')
|
def run_tunnel():
|
||||||
cmd = ['code', 'tunnel']
|
process = subprocess.Popen(
|
||||||
# cmd = ['echo', '"Hello world"']
|
['/root/code', 'tunnel'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
|
||||||
|
|
||||||
|
|
||||||
print('PATH:\n' + '\n'.join(f' - {p}' for p in os.environ['PATH'].split(':')))
|
|
||||||
try:
|
|
||||||
result = subprocess.run(
|
|
||||||
cmd,
|
|
||||||
shell=True,
|
|
||||||
env=os.environ,
|
|
||||||
text=True,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
)
|
)
|
||||||
result.check_returncode()
|
|
||||||
except subprocess.CalledProcessError as e:
|
with process.stdout:
|
||||||
print(e)
|
try:
|
||||||
finally:
|
for line in iter(process.stdout.readline, ''):
|
||||||
print(result.stdout)
|
print(line, end='')
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('KeyboardInterrupt')
|
||||||
|
finally:
|
||||||
|
process.terminate()
|
||||||
|
try:
|
||||||
|
# Give some time to gracefully shutdown
|
||||||
|
returncode = process.wait(timeout=5)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
print('Timeout expired, sending SIGKILL')
|
||||||
|
process.kill()
|
||||||
|
returncode = process.wait()
|
||||||
|
print(f'Process finished with {returncode}')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run_tunnel()
|
||||||
|
|||||||
@@ -9,16 +9,10 @@ console = Console()
|
|||||||
print = console.print
|
print = console.print
|
||||||
|
|
||||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
|
||||||
try:
|
sock.connect('/run/example.sock')
|
||||||
sock.connect('/run/example.sock')
|
with console.status('Connected...'):
|
||||||
except Exception:
|
while True:
|
||||||
raise
|
try:
|
||||||
else:
|
sleep(0.1)
|
||||||
with console.status('Connected...'):
|
except KeyboardInterrupt:
|
||||||
while True:
|
break
|
||||||
try:
|
|
||||||
sleep(0.1)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
break
|
|
||||||
finally:
|
|
||||||
print('Exiting')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user