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:
|
2023-04-06 16:49:23 +00:00
|
|
|
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
|
2023-06-18 04:40:01 +00:00
|
|
|
def get_version(path, is_lib = False):
|
2023-02-19 17:54:02 +00:00
|
|
|
ver = ""
|
2023-06-18 04:40:01 +00:00
|
|
|
string = ".version = \""
|
2023-02-19 17:54:02 +00:00
|
|
|
|
2023-06-18 04:40:01 +00:00
|
|
|
if not is_lib:
|
2023-02-19 17:54:02 +00:00
|
|
|
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" : {
|
2023-03-04 19:13:47 +00:00
|
|
|
"installer" : get_version("./ccmsi.lua"),
|
|
|
|
"bootloader" : get_version("./startup.lua"),
|
2023-07-31 00:46:04 +00:00
|
|
|
"common" : get_version("./scada-common/util.lua", True),
|
2023-02-28 04:51:26 +00:00
|
|
|
"comms" : get_version("./scada-common/comms.lua", True),
|
2023-06-18 04:40:01 +00:00
|
|
|
"graphics" : get_version("./graphics/core.lua", True),
|
2023-06-25 21:53:02 +00:00
|
|
|
"lockbox" : get_version("./lockbox/init.lua", True),
|
2023-03-04 19:13:47 +00:00
|
|
|
"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
|
2023-09-01 14:23:39 +00:00
|
|
|
"system" : [ "initenv.lua", "startup.lua", "configure.lua" ],
|
2023-02-28 04:51:26 +00:00
|
|
|
"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-06-25 21:53:02 +00:00
|
|
|
"reactor-plc" : [ "system", "common", "graphics", "lockbox" ],
|
|
|
|
"rtu" : [ "system", "common", "graphics", "lockbox" ],
|
|
|
|
"supervisor" : [ "system", "common", "graphics", "lockbox" ],
|
|
|
|
"coordinator" : [ "system", "common", "graphics", "lockbox" ],
|
|
|
|
"pocket" : [ "system", "common", "graphics", "lockbox" ]
|
2023-02-28 04:51:26 +00:00
|
|
|
},
|
|
|
|
"sizes" : {
|
|
|
|
# manifest file estimate
|
|
|
|
"manifest" : size,
|
|
|
|
# common files
|
2023-09-01 14:23:39 +00:00
|
|
|
"system" : os.path.getsize("initenv.lua") + os.path.getsize("startup.lua") + os.path.getsize("configure.lua"),
|
2023-02-28 04:51:26 +00:00
|
|
|
"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
|
|
|
|
2023-03-03 03:29:50 +00:00
|
|
|
manifest_size = os.path.getsize("install_manifest.json")
|
|
|
|
|
2023-04-12 21:04:28 +00:00
|
|
|
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")
|
2023-04-12 21:04:28 +00:00
|
|
|
json.dump(final_manifest, f)
|
2023-02-19 17:54:02 +00:00
|
|
|
f.close()
|
2023-04-12 21:04:28 +00:00
|
|
|
|
2023-06-07 19:05:36 +00:00
|
|
|
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()
|