release.py
1.59 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
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))