release.py 1.59 KB
import serial
import io
import os
import sys

######################################
# EDIT THIS TO MATCH YOUR SETTINGS
PORT = 'COM17'
IPADDRESS = '192.168.1.189'
######################################

BAUDRATE = 115200

folders = ['help', 'rooms', 'inventory', 'commands', 'mobs']

files = [
  "commandhandler.py",
  "main.py",
  "mobs.txt",
  "spawner.txt",
  "mudserver.py",
  "utils.py",
  "welcome.txt",
  "wifiweb.py",
  "defaultplayer.json"
]

def run_command(sio, command, expected='>>>'):
    sio.write("{}\n".format(command))
    sio.flush() # it is buffering. required to get the data out *now*
    res = ''
    while expected not in res:
        res = sio.readline()
        # print(res)
    return res

with serial.Serial(PORT, BAUDRATE, timeout=1) as ser:
    sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
    run_command(sio, 'import os')
    root = eval(run_command(sio, 'os.listdir()', expected=']'))

    if not set(folders).issubset(root):

        print('Creating folders.')
        # we are missing folders so they need to be created.
        for folder in folders:
            if folder in root:
                continue
            print('Creating folder: {}'.format(folder))
            run_command(sio, 'os.mkdir("{}")'.format(folder))
    else:
        print('Folders already created.')


for folder in folders:
    for f in os.listdir(folder):
        files.append('{}/{}'.format(folder, f))

with open('releasepw.conf', 'r', encoding='utf-8') as f:
  password = f.read()

for file in files:
  os.system("python webrepl\webrepl_cli.py -p {} {} {}:/{}".format(password, file, IPADDRESS, file))