48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
import select
|
|
import sys
|
|
from src.parser import get_args
|
|
from src.node_manager import NodeManager
|
|
|
|
if __name__ == '__main__':
|
|
args = get_args()
|
|
host, port = args.host, args.port
|
|
|
|
manager = NodeManager(host, port)
|
|
manager.start_service()
|
|
|
|
|
|
is_run = True
|
|
while is_run:
|
|
explanation = '=' * 30 + '\n'
|
|
for index, action in enumerate(manager.actions):
|
|
explanation += f'{index+1}) {action["explanation"]}\n'
|
|
explanation += '=' * 30
|
|
explanation += '\n> '
|
|
print(explanation, end='')
|
|
|
|
while True:
|
|
if sys.stdin.closed:
|
|
sys.stdin = open(0)
|
|
|
|
read_list, _, _ = select.select([sys.stdin], [], [], 1)
|
|
|
|
if read_list:
|
|
action = sys.stdin.readline()
|
|
try:
|
|
action = manager.actions[int(action)-1]
|
|
if action['function'] == 'exit':
|
|
manager.exit()
|
|
is_run = False
|
|
else:
|
|
func = getattr(manager, action['function'])
|
|
func()
|
|
break
|
|
except:
|
|
break
|
|
|
|
print("\n\n\n")
|
|
print("Stopped")
|
|
|
|
|
|
|