-
Notifications
You must be signed in to change notification settings - Fork 169
/
update_firmware_ref.py
85 lines (73 loc) · 3.01 KB
/
update_firmware_ref.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
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
79
80
81
82
83
84
85
import os
import sys
if sys.platform != 'win32':
print(__file__ + ": not under windows")
exit()
# if not (sys.version_info.major >= 3 and sys.version_info.minor >= 4):
# print('update_firmware_ref: PYTHON VERISON TOO LOW, 3.4+ REQUIRED')
# exit()
try:
dfu_folder = os.path.join('.', 'firmware')
dfu_file_list = [d for d in os.listdir(dfu_folder) if d.startswith('duckypad_v') and d.endswith('.dfu')]
dfu_file_list.sort(key=lambda s: list(map(int, s.replace('duckypad_v', '').replace('.dfu', '').split('.'))))
latest_dfu_file_name = dfu_file_list[-1]
print('latest dfu file is:', latest_dfu_file_name)
except Exception as e:
print("update_firmware_ref: get latest dfu exception:", e)
exit()
readme_file = open('firmware_updates_and_version_history.md', encoding='utf8')
readme_lines = readme_file.readlines()
readme_file.close()
changes_made = False
for index, line in enumerate(readme_lines):
if 'click me' in line.lower() and 'to download the latest firmware' in line.lower():
readme_lines[index] = "* [Click me](https://github.com/dekuNukem/duckyPad/raw/master/firmware/" + str(latest_dfu_file_name) + ") to download the latest firmware (v" + latest_dfu_file_name.replace('duckypad_v', '').replace('.dfu', '') + ")\n"
changes_made = True
if changes_made:
readme_file = open('firmware_updates_and_version_history.md', 'w', encoding='utf8')
readme_file.writelines(readme_lines)
readme_file.close()
print('update_firmware_ref: Success')
else:
print('update_firmware_ref: TARGET STRING NOT FOUND, CHECK MD FILE!!!!!!!!!!!')
try:
discord_path = os.path.join('.', 'resources')
discord_path = os.path.join(discord_path, 'discord_link.txt')
discord_link = None
with open(discord_path) as discord_file:
for line in discord_file:
line = line.replace('\n', '').replace('\r', '').strip()
if line.startswith('https://discord.gg/'):
discord_link = line
except Exception as e:
print("!!!!!!!!!!discord link exception:", e)
exit()
if discord_link is None:
print("DISCORD LINK NOT FOUND!!!!!!!!!!")
exit()
md_file_list = [d for d in os.listdir('.') if d.lower().endswith('.md')]
for filename in md_file_list:
this_md_file = open(filename, encoding='utf-8')
readme_lines = this_md_file.readlines()
this_md_file.close()
changes_made = False
for index, line in enumerate(readme_lines):
if '[official duckyPad discord](' in line:
ssss = line.split('[official duckyPad discord](')
front = ssss[0]
back = ssss[1].split(')', 1)[-1]
readme_lines[index] = front + "[official duckyPad discord](" + discord_link + ")" + back
print(readme_lines[index])
changes_made = True
elif '[Official Discord](' in line:
ssss = line.split('[Official Discord](')
front = ssss[0]
back = ssss[1].split(')', 1)[-1]
readme_lines[index] = front + "[Official Discord](" + discord_link + ")" + back
print(readme_lines[index])
changes_made = True
if changes_made:
this_md_file = open(filename, 'w', encoding='utf-8')
this_md_file.writelines(readme_lines)
this_md_file.close()
print('discord link updated on', filename)