forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlolin_tool.py
More file actions
executable file
·67 lines (51 loc) · 1.61 KB
/
Copy pathlolin_tool.py
File metadata and controls
executable file
·67 lines (51 loc) · 1.61 KB
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
#!/usr/bin/env python3
import argparse
import glob
from hashlib import new
import itertools
import os
import re
import subprocess
import shutil
from datetime import datetime
import platform
pc_name = platform.node()
if(pc_name == "wemos"):
now = datetime.now().strftime("%Y%m%d_%H%M%S")
target_dir = f"firmware_{now}"
os.makedirs(target_dir, exist_ok=True)
def get_version_from_git():
git_tag = subprocess.check_output(
["git", "describe"],
stderr=subprocess.STDOUT,
universal_newlines=True,
).strip()
return git_tag
def main():
firmware_names = ["firmware.bin", "firmware-combined.bin"]
dirs = glob.glob("./ports/*/build-*")
print(dirs)
git_ver = get_version_from_git()
print(git_ver)
for d in dirs:
name = d[d.find("build-") + 6 :]
# print(name)
try:
new_name = d + "/firmware-" + name + "-" + git_ver + ".bin"
old_name = ""
for f_name in firmware_names:
if len(glob.glob(d + "/" + f_name)) == 1:
old_name = d + "/" + f_name
break
if old_name != "":
os.rename(old_name, new_name)
print("[MOVE]: ",old_name, " ---> ", new_name)
if(pc_name == "wemos"):
file_name = os.path.basename(new_name)
target_file = os.path.join(target_dir, file_name)
shutil.copy2(new_name, target_file)
print("[COPY]: ", new_name, " ---> ", target_file)
except:
pass
if __name__ == "__main__":
main()