35
35
FLASH = 0
36
36
SPIFFS = 100
37
37
AUTH = 200
38
-
38
+ PROGRESS = 0
39
+ # update_progress() : Displays or updates a console progress bar
40
+ ## Accepts a float between 0 and 1. Any int will be converted to a float.
41
+ ## A value under 0 represents a 'halt'.
42
+ ## A value at 1 or bigger represents 100%
43
+ def update_progress (progress ):
44
+ if (PROGRESS == 1 ):
45
+ barLength = 60 # Modify this to change the length of the progress bar
46
+ status = ""
47
+ if isinstance (progress , int ):
48
+ progress = float (progress )
49
+ if not isinstance (progress , float ):
50
+ progress = 0
51
+ status = "error: progress var must be float\r \n "
52
+ if progress < 0 :
53
+ progress = 0
54
+ status = "Halt...\r \n "
55
+ if progress >= 1 :
56
+ progress = 1
57
+ status = "Done...\r \n "
58
+ block = int (round (barLength * progress ))
59
+ text = "\r Uploading: [{0}] {1}% {2}" .format ( "=" * block + " " * (barLength - block ), int (progress * 100 ), status )
60
+ sys .stderr .write (text )
61
+ sys .stderr .flush ()
62
+ else :
63
+ sys .stderr .write ('.' )
64
+ sys .stderr .flush ()
39
65
40
66
def serve (remoteAddr , remotePort , password , filename , command = FLASH ):
41
67
# Create a TCP/IP socket
@@ -115,13 +141,17 @@ def serve(remoteAddr, remotePort, password, filename, command = FLASH):
115
141
116
142
try :
117
143
f = open (filename , "rb" )
118
- sys .stderr .write ('Uploading' )
119
- sys .stderr .flush ()
144
+ if (PROGRESS == 0 ):
145
+ sys .stderr .write ('Uploading' )
146
+ sys .stderr .flush ()
147
+ else :
148
+ update_progress (0 )
149
+ offset = 0
120
150
while True :
121
151
chunk = f .read (1460 )
122
152
if not chunk : break
123
- sys . stderr . write ( '.' )
124
- sys . stderr . flush ( )
153
+ offset += len ( chunk )
154
+ update_progress ( offset / float ( content_size ) )
125
155
connection .settimeout (10 )
126
156
try :
127
157
connection .sendall (chunk )
@@ -220,6 +250,12 @@ def parser():
220
250
action = "store_true" ,
221
251
default = False
222
252
)
253
+ group .add_option ("-r" , "--progress" ,
254
+ dest = "progress" ,
255
+ help = "Show progress output. Does not work for ArduinoIDE" ,
256
+ action = "store_true" ,
257
+ default = False
258
+ )
223
259
parser .add_option_group (group )
224
260
225
261
(options , args ) = parser .parse_args ()
@@ -244,6 +280,8 @@ def main(args):
244
280
logging .debug ("Options: %s" , str (options ))
245
281
246
282
# check options
283
+ if (options .progress ):
284
+ PROGRESS = 1
247
285
if (not options .esp_ip or not options .image ):
248
286
logging .critical ("Not enough arguments." )
249
287
0 commit comments