summaryrefslogtreecommitdiff
path: root/utilities/flasher.py
blob: b39d9130d95754ca5b55986b1d66babc29585081 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python

import sys
import os
from termcolor import colored

try:
    import tty, termios
except ImportError:
    try:
        import msvcrt
    except ImportError:
        raise ImportError('getch not available')
    else:
        getch = msvcrt.getch
else:
    def getch():
        """getch() -> key character

        Read a single keypress from stdin and return the resulting character. 
        Nothing is echoed to the console. This call will block if a keypress 
        is not already available, but will not wait for Enter to be pressed. 

        If the pressed key was a modifier key, nothing will be detected; if
        it were a special function key, it may return the first character of
        of an escape sequence, leaving additional characters in the buffer.
        """
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(fd)
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

code_okay = """
 #######  ##    ##    ###    ##    ## 
##     ## ##   ##    ## ##    ##  ##  
##     ## ##  ##    ##   ##    ####   
##     ## #####    ##     ##    ##    
##     ## ##  ##   #########    ##    
##     ## ##   ##  ##     ##    ##    
 #######  ##    ## ##     ##    ##  
"""

code_error = """
######## ########  ########   #######  ########  
##       ##     ## ##     ## ##     ## ##     ## 
##       ##     ## ##     ## ##     ## ##     ## 
######   ########  ########  ##     ## ########  
##       ##   ##   ##   ##   ##     ## ##   ##   
##       ##    ##  ##    ##  ##     ## ##    ##  
######## ##     ## ##     ##  #######  ##     ## 
"""

def printOkay():
	print colored(code_okay, 'green')

def printError():
	print colored(code_error, 'red')

flash_command = sys.argv[1]

print colored("Using the following command to flash: %s" % flash_command, "green")

while True:
	print colored("Press any key to continue or 'q' to quit.","yellow")
	char = getch()
	print char
	if ord(char) is ord('q'):
		sys.exit(0)
	return_code = os.system(flash_command)
	if return_code > 0:
		printError()
	else:
		printOkay()