-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicotool.py
39 lines (32 loc) · 1.06 KB
/
picotool.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
import subprocess
class Picotool:
def __init__(self):
self.nuke_file = "firmware/flash_nuke.uf2"
def picotool_info(self):
try:
output = subprocess.check_output(
["picotool", "info"])
lines = output.decode().strip().split("\n")
info = {}
for line in lines:
if ":" in line:
key, value = line.split(":", 1)
info[key.strip()] = value.strip()
return info
except subprocess.CalledProcessError:
return None
def get_program_name(self):
info = self.picotool_info()
if not info:
return None
return info.get("name")
def nuke_firmware(self):
result = self.flash_firmware(self.nuke_file)
return result
def flash_firmware(self, firmware_file):
try:
subprocess.check_output(
["picotool", "load", "-v", "-x", firmware_file])
return True
except subprocess.CalledProcessError:
return False