2024-06-29 18:29:49 +00:00
|
|
|
import base64
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2024-06-29 20:02:25 +00:00
|
|
|
path_prefix = "./_minified/"
|
|
|
|
|
|
|
|
# recursively encode files with base64
|
2024-06-29 18:29:49 +00:00
|
|
|
def encode_recursive(path):
|
|
|
|
list = {}
|
|
|
|
|
|
|
|
for item in os.listdir(path):
|
|
|
|
item_path = path + '/' + item
|
|
|
|
|
|
|
|
if os.path.isfile(item_path):
|
|
|
|
handle = open(item_path, 'r')
|
|
|
|
list[item] = base64.b64encode(bytes(handle.read(), 'UTF-8')).decode('ASCII')
|
|
|
|
handle.close()
|
|
|
|
else:
|
|
|
|
list[item] = encode_recursive(item_path)
|
|
|
|
|
|
|
|
return list
|
|
|
|
|
2024-06-29 20:02:25 +00:00
|
|
|
# encode listed files with base64
|
2024-06-29 18:29:49 +00:00
|
|
|
def encode_files(files):
|
|
|
|
list = {}
|
|
|
|
|
|
|
|
for item in files:
|
2024-06-29 20:02:25 +00:00
|
|
|
item_path = path_prefix + './' + item
|
2024-06-29 18:29:49 +00:00
|
|
|
|
|
|
|
handle = open(item_path, 'r')
|
|
|
|
list[item] = base64.b64encode(bytes(handle.read(), 'UTF-8')).decode('ASCII')
|
|
|
|
handle.close()
|
|
|
|
|
|
|
|
return list
|
|
|
|
|
2024-06-29 20:02:25 +00:00
|
|
|
# file manifest (reflects imgen.py)
|
2024-06-29 18:29:49 +00:00
|
|
|
manifest = {
|
|
|
|
"files" : {
|
|
|
|
# common files
|
|
|
|
"system" : encode_files([ "initenv.lua", "startup.lua", "configure.lua", "LICENSE" ]),
|
2024-06-29 20:02:25 +00:00
|
|
|
"common" : encode_recursive(path_prefix + "./scada-common"),
|
|
|
|
"graphics" : encode_recursive(path_prefix + "./graphics"),
|
|
|
|
"lockbox" : encode_recursive(path_prefix + "./lockbox"),
|
2024-06-29 18:29:49 +00:00
|
|
|
# platform files
|
2024-06-29 20:02:25 +00:00
|
|
|
"reactor-plc" : encode_recursive(path_prefix + "./reactor-plc"),
|
|
|
|
"rtu" : encode_recursive(path_prefix + "./rtu"),
|
|
|
|
"supervisor" : encode_recursive(path_prefix + "./supervisor"),
|
|
|
|
"coordinator" : encode_recursive(path_prefix + "./coordinator"),
|
|
|
|
"pocket" : encode_recursive(path_prefix + "./pocket"),
|
2024-06-29 18:29:49 +00:00
|
|
|
},
|
|
|
|
"depends" : {
|
|
|
|
"reactor-plc" : [ "reactor-plc", "system", "common", "graphics", "lockbox" ],
|
|
|
|
"rtu" : [ "rtu", "system", "common", "graphics", "lockbox" ],
|
|
|
|
"supervisor" : [ "supervisor", "system", "common", "graphics", "lockbox" ],
|
|
|
|
"coordinator" : [ "coordinator", "system", "common", "graphics", "lockbox" ],
|
|
|
|
"pocket" : [ "pocket", "system", "common", "graphics", "lockbox" ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-29 20:02:25 +00:00
|
|
|
# write the application installation items as Lua tables
|
2024-06-29 18:29:49 +00:00
|
|
|
def write_items(body, items, indent):
|
|
|
|
indent_str = " " * indent
|
|
|
|
for key, value in items.items():
|
|
|
|
if isinstance(value, str):
|
|
|
|
body = body + f"{indent_str}['{key}'] = \"{value}\",\n"
|
|
|
|
else:
|
|
|
|
body = body + f"{indent_str}['{key}'] = {{\n"
|
|
|
|
body = write_items(body, value, indent + 4)
|
|
|
|
body = body + f"{indent_str}}},\n"
|
|
|
|
|
|
|
|
return body
|
|
|
|
|
|
|
|
|
2024-06-29 20:02:25 +00:00
|
|
|
|
2024-06-29 18:29:49 +00:00
|
|
|
for app in [ "reactor-plc", "rtu", "supervisor", "coordinator", "pocket" ]:
|
|
|
|
f = open("_" + app + ".lua", "w")
|
|
|
|
body = "local application = {\n"
|
|
|
|
for depend in manifest["depends"][app]:
|
|
|
|
body = body + write_items("", { f"{depend}": manifest["files"][depend] }, 4)
|
|
|
|
body = body + "}\n\n"
|
|
|
|
f.write(body)
|
|
|
|
f.close()
|