cc-mek-scada/imgen.py

131 lines
3.9 KiB
Python
Raw Normal View History

2023-02-19 17:54:02 +00:00
import json
import os
2023-04-12 21:21:39 +00:00
import sys
2023-02-19 17:54:02 +00:00
# list files in a directory
def list_files(path):
list = []
for (root, dirs, files) in os.walk(path):
for f in files:
list.append((root[2:] + "/" + f).replace('\\','/'))
2023-02-19 17:54:02 +00:00
return list
# get size of all files in a directory
def dir_size(path):
total = 0
for (root, dirs, files) in os.walk(path):
for f in files:
total += os.path.getsize(root + "/" + f)
return total
# get the version of an application at the provided path
def get_version(path, is_comms = False):
ver = ""
string = "comms.version = \""
if not is_comms:
string = "_VERSION = \""
f = open(path, "r")
for line in f:
pos = line.find(string)
if pos >= 0:
ver = line[(pos + len(string)):(len(line) - 2)]
break
f.close()
return ver
2023-02-28 04:51:26 +00:00
# generate installation manifest object
def make_manifest(size):
manifest = {
"versions" : {
"installer" : get_version("./ccmsi.lua"),
"bootloader" : get_version("./startup.lua"),
2023-02-28 04:51:26 +00:00
"comms" : get_version("./scada-common/comms.lua", True),
"reactor-plc" : get_version("./reactor-plc/startup.lua"),
"rtu" : get_version("./rtu/startup.lua"),
"supervisor" : get_version("./supervisor/startup.lua"),
"coordinator" : get_version("./coordinator/startup.lua"),
"pocket" : get_version("./pocket/startup.lua")
2023-02-28 04:51:26 +00:00
},
"files" : {
# common files
"system" : [ "initenv.lua", "startup.lua" ],
"common" : list_files("./scada-common"),
"graphics" : list_files("./graphics"),
"lockbox" : list_files("./lockbox"),
# platform files
"reactor-plc" : list_files("./reactor-plc"),
"rtu" : list_files("./rtu"),
"supervisor" : list_files("./supervisor"),
"coordinator" : list_files("./coordinator"),
"pocket" : list_files("./pocket"),
},
"depends" : {
2023-04-07 02:10:33 +00:00
"reactor-plc" : [ "system", "common", "graphics" ],
2023-04-21 00:40:28 +00:00
"rtu" : [ "system", "common", "graphics" ],
2023-06-08 01:25:42 +00:00
"supervisor" : [ "system", "common", "graphics" ],
2023-02-28 04:51:26 +00:00
"coordinator" : [ "system", "common", "graphics" ],
"pocket" : [ "system", "common", "graphics" ]
},
"sizes" : {
# manifest file estimate
"manifest" : size,
# common files
"system" : os.path.getsize("initenv.lua") + os.path.getsize("startup.lua"),
"common" : dir_size("./scada-common"),
"graphics" : dir_size("./graphics"),
"lockbox" : dir_size("./lockbox"),
# platform files
"reactor-plc" : dir_size("./reactor-plc"),
"rtu" : dir_size("./rtu"),
"supervisor" : dir_size("./supervisor"),
"coordinator" : dir_size("./coordinator"),
"pocket" : dir_size("./pocket"),
}
2023-02-19 17:54:02 +00:00
}
2023-02-28 04:51:26 +00:00
return manifest
2023-02-19 17:54:02 +00:00
2023-02-28 04:51:26 +00:00
# write initial manifest with placeholder size
f = open("install_manifest.json", "w")
json.dump(make_manifest("-----"), f)
f.close()
2023-02-19 17:54:02 +00:00
manifest_size = os.path.getsize("install_manifest.json")
final_manifest = make_manifest(manifest_size)
2023-02-28 04:51:26 +00:00
# calculate file size then regenerate with embedded size
f = open("install_manifest.json", "w")
json.dump(final_manifest, f)
2023-02-19 17:54:02 +00:00
f.close()
if len(sys.argv) > 1 and sys.argv[1] == "shields":
2023-04-12 21:21:39 +00:00
# write all the JSON files for shields.io
for key, version in final_manifest["versions"].items():
2023-05-31 15:15:55 +00:00
f = open("./deploy/" + key + ".json", "w")
2023-04-12 21:21:39 +00:00
if version.find("alpha") >= 0:
color = "yellow"
elif version.find("beta") >= 0:
color = "orange"
else:
color = "blue"
json.dump({
"schemaVersion": 1,
"label": key,
"message": "" + version,
"color": color
}, f)
f.close()