-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackendAccessPanel.py
More file actions
95 lines (75 loc) · 3.24 KB
/
BackendAccessPanel.py
File metadata and controls
95 lines (75 loc) · 3.24 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
"""
basically just a python prompt with a connection
already initialized (c)
Author:
Nilusink
"""
from traceback import format_exc
from sys import platform
import socket
import os
from fridrich.backend import Connection
from fridrich import ConsoleColors
if platform == "win32":
os.system("color") # only for windows
if __name__ == '__main__':
with Connection(host="0.0.0.0") as c:
while True:
hostname: str = input(ConsoleColors.ENDC+"host: ")
try:
c.server_ip = hostname # assign ip / hostname
break
except socket.gaierror:
print(ConsoleColors.FAIL+"Couldn't connect to Server: Getaddrinfo failed")
input(ConsoleColors.WARNING+'to try again hit enter\n')
print(ConsoleColors.OKGREEN+'initialised Connections')
def list_funcs() -> None:
"""
list all the functions of fridrich.backend.Connection
"""
funcs = dir(Connection)
functions, variables = [], []
for element in funcs:
if not element.endswith('__'):
if callable(eval(f"c.{element}")):
functions.append(element)
continue
variables.append(element)
print(ConsoleColors.OKGREEN + '\nFunctions of Connection: ' + ConsoleColors.ENDC)
for func in functions:
print(" - " + ConsoleColors.HEADER + func + ConsoleColors.ENDC)
print(ConsoleColors.OKGREEN + '\nVariables of Connection: ' + ConsoleColors.ENDC)
for var in variables:
print(" - " + ConsoleColors.OKBLUE + var + ConsoleColors.ENDC)
list_funcs()
###########################################################
# Console #
###########################################################
cmd: str
while True: # shell for debugging
try:
cmd = input(f'{ConsoleColors.OKBLUE}>> {ConsoleColors.OKCYAN}') # take input command as string
print(end=ConsoleColors.ENDC)
if cmd == "help":
list_funcs()
continue
elif cmd:
if "\\n" in cmd:
raise RuntimeError("No multiline commands allowed")
print(ConsoleColors.OKGREEN + str(eval(compile(cmd, "backend_command", "eval"))) + ConsoleColors.ENDC) # execute the code and print the result
else:
print(end="\r")
except SystemExit:
print(ConsoleColors.WARNING+"\nClosing connection...")
break
except SyntaxError: # if error occurs, try to execute the command with exec and if that fails again, return the error
trace = format_exc()
try:
exec(compile(cmd, "backend_command", "exec"))
except (Exception,):
print(trace)
continue
except (Exception,):
print(format_exc())
continue
print(ConsoleColors.OKGREEN+"Closed, good bye!\n"+ConsoleColors.ENDC)