#258 versioned graphics component

This commit is contained in:
Mikayla Fischler
2023-06-18 00:40:01 -04:00
parent 302f3d913f
commit 9266d7d8e1
4 changed files with 137 additions and 141 deletions

259
ccmsi.lua
View File

@@ -20,7 +20,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local function println(message) print(tostring(message)) end local function println(message) print(tostring(message)) end
local function print(message) term.write(tostring(message)) end local function print(message) term.write(tostring(message)) end
local CCMSI_VERSION = "v1.2" local CCMSI_VERSION = "v1.3"
local install_dir = "/.install-cache" local install_dir = "/.install-cache"
local manifest_path = "https://mikaylafischler.github.io/cc-mek-scada/manifests/" local manifest_path = "https://mikaylafischler.github.io/cc-mek-scada/manifests/"
@@ -54,6 +54,68 @@ local function write_install_manifest(manifest, dependencies)
imfile.close() imfile.close()
end end
-- ask the user yes or no
---@nodiscard
---@param question string
---@param default boolean
---@return boolean|nil
local function ask_y_n(question, default)
print(question)
if default == true then
print(" (Y/n)? ")
else
print(" (y/N)? ")
end
local response = read(nil, nil)
if response == "" then
return default
elseif response == "Y" or response == "y" then
return true
elseif response == "N" or response == "n" then
return false
else
return nil
end
end
-- print out a white + blue text message<br>
-- automatically adds a space
---@param message string message
---@param package string dependency/package/version
local function pkg_message(message, package)
term.setTextColor(colors.white)
print(message .. " ")
term.setTextColor(colors.blue)
println(package)
term.setTextColor(colors.white)
end
-- indicate actions to be taken based on package differences for installs/updates
---@param name string package name
---@param _local_v string|nil local version
---@param _remote_v string remote version
local function show_pkg_change(name, _local_v, _remote_v)
if _local_v ~= nil then
if _local_v ~= _remote_v then
print("[" .. name .. "] updating ")
term.setTextColor(colors.blue)
print(_local_v)
term.setTextColor(colors.white)
print(" \xbb ")
term.setTextColor(colors.blue)
println(_local_v)
term.setTextColor(colors.white)
elseif mode == "install" then
pkg_message("[" .. name .. "] reinstalling", _local_v)
end
else
pkg_message("[" .. name .. "] new install of", _remote_v)
end
end
-- --
-- get and validate command line options -- get and validate command line options
-- --
@@ -230,6 +292,13 @@ elseif mode == "install" or mode == "update" then
-- GET LOCAL MANIFEST -- -- GET LOCAL MANIFEST --
------------------------ ------------------------
local ver = {
app = { v_local = nil, v_remote = nil, changed = false },
boot = { v_local = nil, v_remote = nil, changed = false },
comms = { v_local = nil, v_remote = nil, changed = false },
graphics = { v_local = nil, v_remote = nil, changed = false }
}
local imfile = fs.open("install_manifest.json", "r") local imfile = fs.open("install_manifest.json", "r")
local local_ok = false local local_ok = false
local local_manifest = {} local local_manifest = {}
@@ -239,10 +308,6 @@ elseif mode == "install" or mode == "update" then
imfile.close() imfile.close()
end end
local local_app_version = nil
local local_comms_version = nil
local local_boot_version = nil
-- try to find local versions -- try to find local versions
if not local_ok then if not local_ok then
if mode == "update" then if mode == "update" then
@@ -252,9 +317,10 @@ elseif mode == "install" or mode == "update" then
return return
end end
else else
local_app_version = local_manifest.versions[app] ver.boot.v_local = local_manifest.versions.bootloader
local_comms_version = local_manifest.versions.comms ver.app.v_local = local_manifest.versions[app]
local_boot_version = local_manifest.versions.bootloader ver.comms.v_local = local_manifest.versions.comms
ver.graphics.v_local = local_manifest.versions.graphics
if local_manifest.versions[app] == nil then if local_manifest.versions[app] == nil then
term.setTextColor(colors.red) term.setTextColor(colors.red)
@@ -271,94 +337,44 @@ elseif mode == "install" or mode == "update" then
end end
end end
local remote_app_version = manifest.versions[app] ver.boot.v_remote = manifest.versions.bootloader
local remote_comms_version = manifest.versions.comms ver.app.v_remote = manifest.versions[app]
local remote_boot_version = manifest.versions.bootloader ver.comms.v_remote = manifest.versions.comms
ver.graphics.v_remote = manifest.versions.graphics
term.setTextColor(colors.green) term.setTextColor(colors.green)
if mode == "install" then if mode == "install" then
println("installing " .. app .. " files...") println("Installing " .. app .. " files...")
elseif mode == "update" then elseif mode == "update" then
println("updating " .. app .. " files... (keeping old config.lua)") println("Updating " .. app .. " files... (keeping old config.lua)")
end end
term.setTextColor(colors.white) term.setTextColor(colors.white)
-- display bootloader version change information -- display bootloader version change information
if local_boot_version ~= nil then show_pkg_change("bootldr", ver.boot.v_local, ver.boot.v_remote)
if local_boot_version ~= remote_boot_version then ver.boot.changed = ver.boot.v_local ~= ver.boot.v_remote
print("[bootldr] updating ")
term.setTextColor(colors.blue)
print(local_boot_version)
term.setTextColor(colors.white)
print(" \xbb ")
term.setTextColor(colors.blue)
println(remote_boot_version)
term.setTextColor(colors.white)
elseif mode == "install" then
print("[bootldr] reinstalling ")
term.setTextColor(colors.blue)
println(local_boot_version)
term.setTextColor(colors.white)
end
else
print("[bootldr] new install of ")
term.setTextColor(colors.blue)
println(remote_boot_version)
term.setTextColor(colors.white)
end
-- display app version change information -- display app version change information
if local_app_version ~= nil then show_pkg_change(app, ver.app.v_local, ver.app.v_remote)
if local_app_version ~= remote_app_version then ver.app.changed = ver.app.v_local ~= ver.app.v_remote
print("[" .. app .. "] updating ")
term.setTextColor(colors.blue)
print(local_app_version)
term.setTextColor(colors.white)
print(" \xbb ")
term.setTextColor(colors.blue)
println(remote_app_version)
term.setTextColor(colors.white)
elseif mode == "install" then
print("[" .. app .. "] reinstalling ")
term.setTextColor(colors.blue)
println(local_app_version)
term.setTextColor(colors.white)
end
else
print("[" .. app .. "] new install of ")
term.setTextColor(colors.blue)
println(remote_app_version)
term.setTextColor(colors.white)
end
-- display comms version change information -- display comms version change information
if local_comms_version ~= nil then show_pkg_change("comms", ver.comms.v_local, ver.comms.v_remote)
if local_comms_version ~= remote_comms_version then ver.comms.changed = ver.comms.v_local ~= ver.comms.v_remote
print("[comms] updating ") if ver.comms.changed then
term.setTextColor(colors.blue)
print(local_comms_version)
term.setTextColor(colors.white)
print(" \xbb ")
term.setTextColor(colors.blue)
println(remote_comms_version)
term.setTextColor(colors.white)
print("[comms] ") print("[comms] ")
term.setTextColor(colors.yellow) term.setTextColor(colors.yellow)
println("other devices on the network will require an update") println("other devices on the network will require an update")
term.setTextColor(colors.white) term.setTextColor(colors.white)
elseif mode == "install" then
print("[comms] reinstalling ")
term.setTextColor(colors.blue)
println(local_comms_version)
term.setTextColor(colors.white)
end
else
print("[comms] new install of ")
term.setTextColor(colors.blue)
println(remote_comms_version)
term.setTextColor(colors.white)
end end
-- display graphics version change information
show_pkg_change("graphics", ver.graphics.v_local, ver.graphics.v_remote)
ver.graphics.changed = ver.graphics.v_local ~= ver.graphics.v_remote
-- ask for confirmation
if not ask_y_n("Continue?", false) then return end
-------------------------- --------------------------
-- START INSTALL/UPDATE -- -- START INSTALL/UPDATE --
-------------------------- --------------------------
@@ -386,18 +402,13 @@ elseif mode == "install" or mode == "update" then
println("WARNING: Insufficient space available for a full download!") println("WARNING: Insufficient space available for a full download!")
term.setTextColor(colors.white) term.setTextColor(colors.white)
println("Files can be downloaded one by one, so if you are replacing a current install this will not be a problem unless installation fails.") println("Files can be downloaded one by one, so if you are replacing a current install this will not be a problem unless installation fails.")
println("Do you wish to continue? (y/N)") if mode == "update" then println("If installation still fails, delete this device's log file and try again.") end
if not ask_y_n("Do you wish to continue?", false) then
local confirm = read() println("Operation cancelled.")
if confirm ~= "y" and confirm ~= "Y" then
println("installation cancelled")
return return
end end
end end
---@diagnostic disable-next-line: undefined-field
os.sleep(2)
local success = true local success = true
if not single_file_mode then if not single_file_mode then
@@ -408,20 +419,14 @@ elseif mode == "install" or mode == "update" then
-- download all dependencies -- download all dependencies
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
if mode == "update" and ((dependency == "system" and local_boot_version == remote_boot_version) or (local_app_version == remote_app_version)) then if mode == "update" and ((dependency == "system" and ver.boot.changed) or
-- skip system package if unchanged, skip app package if not changed (dependency == "graphics" and ver.graphics.changed) or
-- skip packages that have no version if app version didn't change (ver.changed.app)) then
term.setTextColor(colors.white) pkg_message("skipping download of unchanged package", dependency)
print("skipping download of unchanged package ")
term.setTextColor(colors.blue)
println(dependency)
else else
term.setTextColor(colors.white) pkg_message("downloading package", dependency)
print("downloading package ")
term.setTextColor(colors.blue)
println(dependency)
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
local files = file_list[dependency] local files = file_list[dependency]
for _, file in pairs(files) do for _, file in pairs(files) do
println("GET " .. file) println("GET " .. file)
@@ -444,20 +449,14 @@ elseif mode == "install" or mode == "update" then
-- copy in downloaded files (installation) -- copy in downloaded files (installation)
if success then if success then
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
if mode == "update" and ((dependency == "system" and local_boot_version == remote_boot_version) or (local_app_version == remote_app_version)) then if mode == "update" and ((dependency == "system" and ver.boot.changed) or
-- skip system package if unchanged, skip app package if not changed (dependency == "graphics" and ver.graphics.changed) or
-- skip packages that have no version if app version didn't change (ver.changed.app)) then
term.setTextColor(colors.white) pkg_message("skipping install of unchanged package", dependency)
print("skipping install of unchanged package ")
term.setTextColor(colors.blue)
println(dependency)
else else
term.setTextColor(colors.white) pkg_message("installing package", dependency)
print("installing package ")
term.setTextColor(colors.blue)
println(dependency)
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
local files = file_list[dependency] local files = file_list[dependency]
for _, file in pairs(files) do for _, file in pairs(files) do
if mode == "install" or file ~= config_file then if mode == "install" or file ~= config_file then
@@ -478,36 +477,30 @@ elseif mode == "install" or mode == "update" then
write_install_manifest(manifest, dependencies) write_install_manifest(manifest, dependencies)
term.setTextColor(colors.green) term.setTextColor(colors.green)
if mode == "install" then if mode == "install" then
println("installation completed successfully") println("Installation completed successfully.")
else else
println("update completed successfully") println("Update completed successfully.")
end end
else else
if mode == "install" then if mode == "install" then
term.setTextColor(colors.red) term.setTextColor(colors.red)
println("installation failed") println("Installation failed.")
else else
term.setTextColor(colors.orange) term.setTextColor(colors.orange)
println("update failed, existing files unmodified") println("Update failed, existing files unmodified.")
end end
end end
else else
-- go through all files and replace one by one -- go through all files and replace one by one
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
if mode == "update" and ((dependency == "system" and local_boot_version == remote_boot_version) or (local_app_version == remote_app_version)) then if mode == "update" and ((dependency == "system" and ver.boot.changed) or
-- skip system package if unchanged, skip app package if not changed (dependency == "graphics" and ver.graphics.changed) or
-- skip packages that have no version if app version didn't change (ver.changed.app)) then
term.setTextColor(colors.white) pkg_message("skipping install of unchanged package", dependency)
print("skipping install of unchanged package ")
term.setTextColor(colors.blue)
println(dependency)
else else
term.setTextColor(colors.white) pkg_message("installing package", dependency)
print("installing package ")
term.setTextColor(colors.blue)
println(dependency)
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
local files = file_list[dependency] local files = file_list[dependency]
for _, file in pairs(files) do for _, file in pairs(files) do
if mode == "install" or file ~= config_file then if mode == "install" or file ~= config_file then
@@ -534,16 +527,16 @@ elseif mode == "install" or mode == "update" then
write_install_manifest(manifest, dependencies) write_install_manifest(manifest, dependencies)
term.setTextColor(colors.green) term.setTextColor(colors.green)
if mode == "install" then if mode == "install" then
println("installation completed successfully") println("Installation completed successfully.")
else else
println("update completed successfully") println("Update completed successfully.")
end end
else else
term.setTextColor(colors.red) term.setTextColor(colors.red)
if mode == "install" then if mode == "install" then
println("installation failed, files may have been skipped") println("Installation failed, files may have been skipped.")
else else
println("update failed, files may have been skipped") println("Update failed, files may have been skipped.")
end end
end end
end end
@@ -576,8 +569,8 @@ elseif mode == "remove" or mode == "purge" then
println("purging all " .. app .. " files...") println("purging all " .. app .. " files...")
end end
---@diagnostic disable-next-line: undefined-field -- ask for confirmation
os.sleep(2) if not ask_y_n("Continue?", false) then return end
local file_list = manifest.files local file_list = manifest.files
local dependencies = manifest.depends[app] local dependencies = manifest.depends[app]
@@ -666,7 +659,7 @@ elseif mode == "remove" or mode == "purge" then
end end
term.setTextColor(colors.green) term.setTextColor(colors.green)
println("done!") println("Done!")
end end
term.setTextColor(colors.white) term.setTextColor(colors.white)

View File

@@ -7,6 +7,8 @@ local flasher = require("graphics.flasher")
local core = {} local core = {}
core.version = "1.0.0"
core.flasher = flasher core.flasher = flasher
core.events = events core.events = events

View File

@@ -23,11 +23,11 @@ def dir_size(path):
return total return total
# get the version of an application at the provided path # get the version of an application at the provided path
def get_version(path, is_comms = False): def get_version(path, is_lib = False):
ver = "" ver = ""
string = "comms.version = \"" string = ".version = \""
if not is_comms: if not is_lib:
string = "_VERSION = \"" string = "_VERSION = \""
f = open(path, "r") f = open(path, "r")
@@ -49,6 +49,7 @@ def make_manifest(size):
"installer" : get_version("./ccmsi.lua"), "installer" : get_version("./ccmsi.lua"),
"bootloader" : get_version("./startup.lua"), "bootloader" : get_version("./startup.lua"),
"comms" : get_version("./scada-common/comms.lua", True), "comms" : get_version("./scada-common/comms.lua", True),
"graphics" : get_version("./graphics/core.lua", True),
"reactor-plc" : get_version("./reactor-plc/startup.lua"), "reactor-plc" : get_version("./reactor-plc/startup.lua"),
"rtu" : get_version("./rtu/startup.lua"), "rtu" : get_version("./rtu/startup.lua"),
"supervisor" : get_version("./supervisor/startup.lua"), "supervisor" : get_version("./supervisor/startup.lua"),

File diff suppressed because one or more lines are too long