rtmc/x.py

69 lines
1.7 KiB
Python
Raw Normal View History

2024-08-17 23:08:11 +00:00
#!/usr/bin/python
2024-08-18 03:24:30 +00:00
import string
import random
UPDATE_ID= ''.join(random.choices(string.ascii_letters, k=24))
2024-08-17 23:08:11 +00:00
OUTPUT="keypadOS.lua";
FILES= [
2024-08-18 00:34:13 +00:00
"updater.lua",
"config.lua",
"ui.lua",
"utils.lua",
"main.lua",
2024-08-17 23:08:11 +00:00
]
2024-08-18 11:37:59 +00:00
MINIMISE=True
2024-08-17 23:08:11 +00:00
def read_file(p: str) -> str:
buf = "";
2024-08-18 00:34:13 +00:00
with open("src/"+p, "r", encoding="utf-8") as f:
2024-08-18 11:37:59 +00:00
buf += f"rawset(__BUNDLER_FILES, \"{p}\", function ()\n";
2024-08-18 00:34:13 +00:00
for line in f.readlines():
2024-08-18 11:37:59 +00:00
buf += " " + line;
buf += "\nend)";
if not MINIMISE:
buf += f"-- FILE END: {p} --\n";
else:
buf += "\n";
2024-08-17 23:08:11 +00:00
return buf;
2024-08-18 11:37:59 +00:00
def minimise(buf: str) -> str:
newbuf = "";
for line in buf.splitlines():
if line.strip().startswith("--"):
continue;
if line.strip() == "":
continue
newbuf += line + "\n";
return newbuf;
2024-08-17 23:08:11 +00:00
def main():
2024-08-18 00:34:13 +00:00
buf = ""
2024-08-18 11:48:03 +00:00
buf += "local __UPDATE_HASH = \"" + {UPDATE_ID} + "\"";
2024-08-18 00:34:13 +00:00
buf += "local __BUNDLER_FILES = {}\n";
buf += "local __DEFAULT_IMPORT = require\n";
buf += "local require = function(path)\n";
2024-08-18 00:43:01 +00:00
buf += " if __BUNDLER_FILES[path] then\n";
buf += " return __BUNDLER_FILES[path]()\n";
buf += " else\n";
2024-08-18 01:13:38 +00:00
buf += " return __DEFAULT_IMPORT(path)\n";
2024-08-18 00:43:01 +00:00
buf += " end\n";
2024-08-18 00:34:13 +00:00
buf += "end\n";
2024-08-17 23:08:11 +00:00
for file in FILES:
print(f"=== FILE: {file}");
buf += read_file(file);
print(f"=== UPDATE HASH: {UPDATE_ID}")
2024-08-18 00:34:13 +00:00
2024-08-18 11:37:59 +00:00
buf += "require(\"main.lua\").Main()\n";
if MINIMISE:
buf = minimise(buf);
2024-08-18 00:34:13 +00:00
2024-08-17 23:08:11 +00:00
with open(OUTPUT, "w", encoding="utf-8") as f:
f.write(buf);
print("DONE");
if __name__ == "__main__":
main();