-
Notifications
You must be signed in to change notification settings - Fork 3
/
upload.py
39 lines (31 loc) · 1.02 KB
/
upload.py
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
# $language = "python"
# $interface = "1.0"
import re
import os
promptStrings = [ "ok.", "Finished. Reset "]
promptTimeout = 10
includePattern = "^include\s+([\.\w/-]+)"
commentPattern = "^\\\s*"
def sendFile(file, level=0):
print("Sending file " + file)
if level>10:
crt.Dialog.MessageBox("Too many nested include files")
raise "Too many include levels"
with open(file, "r") as f:
for line in f:
inc = re.match(includePattern, line)
if inc:
incfile = inc.group(1)
sendFile(os.path.join(os.path.dirname(file), incfile), level + 1)
continue
if re.match(commentPattern, line):
continue
crt.Screen.Send(line)
crt.Screen.WaitForStrings(promptStrings, promptTimeout)
def main():
crt.Screen.Synchronous = True
filePath = crt.Dialog.FileOpenDialog(title="Select forth file to upload")
if filePath:
sendFile(filePath, level=0)
crt.Screen.Synchronous = False
main()