Skip to content

Commit b48cd19

Browse files
author
Paul Sokolovsky
committed
webrepl_cli.py: Add get_ver() method to query remote version.
1 parent a8b7b35 commit b48cd19

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

webrepl_cli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
WEBREPL_REQ_S = "<2sBBQLH64s"
2020
WEBREPL_PUT_FILE = 1
2121
WEBREPL_GET_FILE = 2
22+
WEBREPL_GET_VER = 3
23+
2224

2325
def debugmsg(msg):
2426
if DEBUG:
@@ -100,6 +102,20 @@ def read_resp(ws):
100102
assert sig == b"WB"
101103
return code
102104

105+
106+
def send_req(ws, op, sz=0, fname=""):
107+
rec = struct.pack(WEBREPL_REQ_S, b"WA", op, 0, 0, sz, len(fname), fname)
108+
debugmsg("%r %d" % (rec, len(rec)))
109+
ws.write(rec)
110+
111+
112+
def get_ver(ws):
113+
send_req(ws, WEBREPL_GET_VER)
114+
d = ws.read(3)
115+
d = struct.unpack("<BBB", d)
116+
return d
117+
118+
103119
def put_file(ws, local_file, remote_file):
104120
sz = os.stat(local_file)[6]
105121
dest_fname = (SANDBOX + remote_file).encode("utf-8")
@@ -217,6 +233,7 @@ def main():
217233
import getpass
218234
passwd = getpass.getpass()
219235
login(ws, passwd)
236+
print("Remote WebREPL version:", get_ver(ws))
220237

221238
# Set websocket to send data marked as "binary"
222239
ws.ioctl(9, 2)

0 commit comments

Comments
 (0)