mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 01:39:30 +02:00
Add tool to easily replace OTA file
This commit is contained in:
parent
b5d14edb94
commit
6094a2c85b
1 changed files with 23 additions and 0 deletions
23
Software/src/lib/update_ota_html_gzip.py
Normal file
23
Software/src/lib/update_ota_html_gzip.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
libpath = Path("ayushsharma82-ElegantOTA")
|
||||||
|
gzipped=libpath/"CurrentPlainHTML.txt.gz"
|
||||||
|
header=libpath/"src/elop.h"
|
||||||
|
cpp=libpath/"src/elop.cpp"
|
||||||
|
if not gzipped.exists():
|
||||||
|
print(f"Please create {gzipped.resolve()} to replace OTA file.")
|
||||||
|
print(f"Example: zopfli -v --i10000 {libpath.resolve()}/CurrentPlainHTML.txt")
|
||||||
|
raise SystemExit(1)
|
||||||
|
gzipbytes=gzipped.read_bytes()
|
||||||
|
intlist = [int(one) for one in gzipbytes]
|
||||||
|
content = json.dumps(intlist).replace("[","{").replace("]","}").replace(" ", "")
|
||||||
|
headertext = header.read_text()
|
||||||
|
header.write_text(headertext[:1+headertext.find("[")]+str(len(gzipbytes))+headertext[headertext.find("]"):])
|
||||||
|
cpptext = cpp.read_text()
|
||||||
|
first_bracket = cpptext.find("[")
|
||||||
|
second_bracket = cpptext.find("]")
|
||||||
|
corrected_bytes = cpptext[:1+first_bracket]+str(len(gzipbytes))+cpptext[second_bracket:]
|
||||||
|
cppout = corrected_bytes[:corrected_bytes.find("{")]+content+corrected_bytes[corrected_bytes.find(";"):]+"\n"
|
||||||
|
cpp.write_text(cppout)
|
||||||
|
print("File content updated from", gzipped.resolve())
|
||||||
|
print("Bytes fixed:", cpptext[1+first_bracket:second_bracket], "to", len(gzipbytes))
|
Loading…
Add table
Add a link
Reference in a new issue