keypadOS/x.py
2024-08-18 14:48:03 +03:00

69 lines
1.7 KiB
Python
Executable File

#!/usr/bin/python
import string
import random
UPDATE_ID= ''.join(random.choices(string.ascii_letters, k=24))
OUTPUT="keypadOS.lua";
FILES= [
"updater.lua",
"config.lua",
"ui.lua",
"utils.lua",
"main.lua",
]
MINIMISE=True
def read_file(p: str) -> str:
buf = "";
with open("src/"+p, "r", encoding="utf-8") as f:
buf += f"rawset(__BUNDLER_FILES, \"{p}\", function ()\n";
for line in f.readlines():
buf += " " + line;
buf += "\nend)";
if not MINIMISE:
buf += f"-- FILE END: {p} --\n";
else:
buf += "\n";
return buf;
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;
def main():
buf = ""
buf += "local __UPDATE_HASH = \"" + {UPDATE_ID} + "\"";
buf += "local __BUNDLER_FILES = {}\n";
buf += "local __DEFAULT_IMPORT = require\n";
buf += "local require = function(path)\n";
buf += " if __BUNDLER_FILES[path] then\n";
buf += " return __BUNDLER_FILES[path]()\n";
buf += " else\n";
buf += " return __DEFAULT_IMPORT(path)\n";
buf += " end\n";
buf += "end\n";
for file in FILES:
print(f"=== FILE: {file}");
buf += read_file(file);
print(f"=== UPDATE HASH: {UPDATE_ID}")
buf += "require(\"main.lua\").Main()\n";
if MINIMISE:
buf = minimise(buf);
with open(OUTPUT, "w", encoding="utf-8") as f:
f.write(buf);
print("DONE");
if __name__ == "__main__":
main();