Initial push.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
ganze_zahl : int
|
||||
ganze_zahl = "z"
|
||||
|
||||
print("Hello World")
|
||||
@@ -0,0 +1,57 @@
|
||||
import sys
|
||||
import socket
|
||||
import os
|
||||
|
||||
def read_char():
|
||||
import sys, termios, tty
|
||||
fd = sys.stdin.fileno()
|
||||
old_settings = termios.tcgetattr(fd)
|
||||
try:
|
||||
tty.setraw(sys.stdin.fileno())
|
||||
ch = sys.stdin.read(1)
|
||||
finally:
|
||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||
return ch
|
||||
|
||||
|
||||
def read_view(f):
|
||||
view = f.readline()
|
||||
if not view:
|
||||
return
|
||||
for x in range(2, len(view)):
|
||||
line = f.readline()
|
||||
if not line:
|
||||
return
|
||||
view += line
|
||||
return view
|
||||
|
||||
|
||||
def main(host='localhost', port=62688):
|
||||
s = socket.socket()
|
||||
s.connect((host, port))
|
||||
f = s.makefile()
|
||||
|
||||
commands = {'w':'^', 'a':'<', 's':'v', 'd':'>', 'W':'^', 'A':'<', 'S':'v', 'D':'>' }
|
||||
|
||||
|
||||
while True:
|
||||
try:
|
||||
view = read_view(f)
|
||||
if not view:
|
||||
break
|
||||
os.system('clear')
|
||||
sys.stdout.write(view)
|
||||
cmd = read_char()
|
||||
if cmd == 'q':
|
||||
break
|
||||
cmd = commands[cmd]
|
||||
s.send(cmd if sys.version_info[0] < 3 else str.encode(cmd))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
break
|
||||
s.close()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main( * sys.argv[1:])
|
||||
@@ -0,0 +1,120 @@
|
||||
import docker
|
||||
import os
|
||||
import getpass
|
||||
import logging
|
||||
|
||||
_image = "dokoliho/botserver"
|
||||
_uid = os.getuid()
|
||||
_username = getpass.getuser()
|
||||
_containername = "botserver_" + _username
|
||||
_port = 62187 + _uid
|
||||
_logger = logging.getLogger(__name__)
|
||||
_from_env=False
|
||||
_verbose=False
|
||||
|
||||
def _client():
|
||||
if _from_env:
|
||||
client = docker.from_env()
|
||||
else:
|
||||
client = docker.DockerClient(base_url='tcp://172.17.0.1:2375')
|
||||
return client
|
||||
|
||||
def _get_running_container():
|
||||
client = _client()
|
||||
try:
|
||||
return client.containers.get(_containername)
|
||||
except:
|
||||
msg = f"Container {_containername} not found."
|
||||
if _verbose: print(msg)
|
||||
_logger.info(msg)
|
||||
return None
|
||||
|
||||
def connect_remote_daemon(flag):
|
||||
global _from_env
|
||||
_from_env = not flag
|
||||
|
||||
def stop_container():
|
||||
container = _get_running_container()
|
||||
if container is not None:
|
||||
container.stop()
|
||||
container.remove()
|
||||
msg = f"Container {_containername} stopped."
|
||||
if _verbose: print(msg)
|
||||
_logger.info(msg)
|
||||
|
||||
def start_container(verbose=False):
|
||||
global _verbose
|
||||
_verbose = verbose
|
||||
stop_container()
|
||||
client = _client()
|
||||
try:
|
||||
client.containers.run(_image,
|
||||
command=["sleep", "inf"],
|
||||
detach=True,
|
||||
name=_containername,
|
||||
ports={63187: _port})
|
||||
msg = f"Container {_containername} started with port {_port}"
|
||||
if _verbose: print(msg)
|
||||
_logger.info(msg)
|
||||
return _port
|
||||
except Exception as e:
|
||||
if _verbose: print(str(e))
|
||||
_logger.warning(str(e))
|
||||
return None
|
||||
|
||||
def exec_in_container(command):
|
||||
container = _get_running_container()
|
||||
if container == None:
|
||||
msg = f"Container {_containername} not running."
|
||||
_logger.warning(msg)
|
||||
raise Exception(msg)
|
||||
try:
|
||||
msg = f"Executing {command}"
|
||||
if _verbose: print(msg)
|
||||
_logger.info(msg)
|
||||
result = container.exec_run(command, stream=True)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
_logger.warning(str(e))
|
||||
return
|
||||
for line in result.output:
|
||||
print(line.decode("utf-8"))
|
||||
msg = f"Execution of {command} finished."
|
||||
if _verbose: print(msg)
|
||||
_logger.info(msg)
|
||||
|
||||
def exec_synced_in_container(command):
|
||||
container = _get_running_container()
|
||||
if container == None:
|
||||
msg = f"Container {_containername} not running."
|
||||
_logger.warning(msg)
|
||||
raise Exception(msg)
|
||||
try:
|
||||
msg = f"Executing (sync) {command}"
|
||||
if _verbose: print(msg)
|
||||
_logger.info(msg)
|
||||
exit_code, output = container.exec_run(command)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return
|
||||
print(output.decode("utf-8") )
|
||||
msg = f"Execution of {command} finished."
|
||||
if _verbose: print(msg)
|
||||
_logger.info(msg)
|
||||
|
||||
def print_logs():
|
||||
container = _get_running_container()
|
||||
if container == None:
|
||||
msg = f"Container {_containername} not running."
|
||||
_logger.warning(msg)
|
||||
raise Exception(msg)
|
||||
print(container.logs().decode("utf-8"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
connect_remote_daemon(False)
|
||||
start_container(verbose=True)
|
||||
# exec_in_container("echo 'hello world'")
|
||||
exec_in_container("/bots/server/bots training")
|
||||
stop_container()
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import socket
|
||||
|
||||
def read_view(f):
|
||||
view = f.readline()
|
||||
if not view:
|
||||
return
|
||||
for x in range(2, len(view)):
|
||||
line = f.readline()
|
||||
if not line:
|
||||
return
|
||||
view += line
|
||||
return view
|
||||
|
||||
def main(host, port):
|
||||
s = socket.socket()
|
||||
s.connect((host, port))
|
||||
f = s.makefile()
|
||||
|
||||
commands = {'w': '^', 'a': '<', 's': 'v', 'd': '>', 'W': '^', 'A': '<', 'S': 'v', 'D': '>'}
|
||||
|
||||
while True:
|
||||
try:
|
||||
view = read_view(f)
|
||||
if not view:
|
||||
break
|
||||
print(view)
|
||||
cmd = input("[WASD]:")
|
||||
cmd = commands[cmd]
|
||||
if cmd is None:
|
||||
break
|
||||
s.send(str.encode(cmd))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
break
|
||||
s.close()
|
||||
|
||||
port = 63188
|
||||
main("141.75.33.7", port)
|
||||
@@ -0,0 +1,42 @@
|
||||
import datetime
|
||||
import os
|
||||
|
||||
|
||||
def get_current_date():
|
||||
return datetime.datetime.now()
|
||||
|
||||
|
||||
def file_exists(filename):
|
||||
os.path.exists(filename)
|
||||
|
||||
|
||||
def add(x, y):
|
||||
return x + y
|
||||
|
||||
|
||||
def assert_equals(message, expected, actual):
|
||||
if expected != actual: print(message)
|
||||
|
||||
|
||||
def open_window(parent, top, bottom, left, right, modal):
|
||||
do_something_with(parent, top, bottom, left, right, modal)
|
||||
|
||||
class Parent():
|
||||
def open_modal_window(self, d):
|
||||
pass
|
||||
|
||||
parent = Parent()
|
||||
|
||||
top = bottom = left = right = modal = None
|
||||
|
||||
open_window(parent, top, bottom, left, right, modal)
|
||||
|
||||
|
||||
dimensions = (top, bottom, left, right)
|
||||
parent.open_modal_window(dimensions)
|
||||
|
||||
|
||||
|
||||
def do_something_with(*args):
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
def f1():
|
||||
return 17
|
||||
|
||||
Reference in New Issue
Block a user