Extend updater and API to support betas and release dates (untested).

This commit is contained in:
Wouter R 2014-02-21 09:54:03 +01:00
parent b6862c17cc
commit 8582f88e06
3 changed files with 29 additions and 11 deletions

View File

@ -335,4 +335,10 @@ M.doodle3d_tour_enabled = {
description = 'Show tour to new users'
}
M.doodle3d_betas = {
default = false,
type = 'bool',
description = 'Update to beta releases',
}
return M

View File

@ -49,9 +49,9 @@ end
function M.status(request, response)
updater.setLogger(log)
updater.setUseCache(false)
local success,status,msg = updater.getStatus()
local includeBetas = settings.get('doodle3d.betas')
local success,status,msg = updater.getStatus(includeBetas)
--response:addData('current_version', status.currentVersion)
response:addData('current_version', updater.formatVersion(status.currentVersion))
response:addData('state_code', status.stateCode)
@ -62,10 +62,11 @@ function M.status(request, response)
return
end
local canUpdate = updater.compareVersions(status.newestVersion, status.currentVersion) > 0
local canUpdate = updater.compareVersions(status.newestVersion, status.currentVersion, status.newestReleaseTimestamp, status.currentReleaseTimestamp) > 0
--response:addData('newest_version', status.newestVersion)
response:addData('newest_version', updater.formatVersion(status.newestVersion))
if status.currentReleaseTimestamp then response:addData('current_release_date', updater.formatDate(status.currentReleaseTimestamp)) end
if status.newestReleaseTimestamp then response:addData('newest_release_date', updater.formatDate(status.newestReleaseTimestamp)) end
response:addData('can_update', canUpdate)
if status.progress then response:addData('progress', status.progress) end
@ -94,7 +95,8 @@ function M.download_POST(request, response)
local vEnt, rv, msg
if not argVersion then
local success,status,msg = updater.getStatus()
local includeBetas = settings.get('doodle3d.betas')
local success,status,msg = updater.getStatus(includeBetas)
if not success then
updater.setState(updater.STATE.DOWNLOAD_FAILED, msg)
response:setFail(msg)
@ -153,9 +155,9 @@ function M.install_POST(request, response)
local argNoRetain = request:get("no_retain")
log:info("API:update/install (noRetain: "..utils.dump(argNoRetain)..")")
local noRetain = argNoRetain == 'true'
if not operationsAccessOrFail(request, response) then return end
updater.setLogger(log)
updater.setState(updater.STATE.INSTALLING,"")
@ -163,7 +165,8 @@ function M.install_POST(request, response)
--local rv,msg = netconf.enableAccessPoint(ssid)
if not argVersion then
local success,status,msg = updater.getStatus()
local includeBetas = settings.get('doodle3d.betas')
local success,status,msg = updater.getStatus(includeBetas)
if not success then
updater.setState(updater.STATE.INSTALL_FAILED, msg)
response:setFail(msg)

View File

@ -396,7 +396,7 @@ end
-- @treturn bool True if status has been determined fully, false if not.
-- @treturn table The result table.
-- @treturn ?string Descriptive message in case the result table is not complete.
function M.getStatus()
function M.getStatus(includeBetas)
if not baseUrl then baseUrl = M.DEFAULT_BASE_URL end
local unknownVersion = { major = 0, minor = 0, patch = 0 }
local result = {}
@ -405,15 +405,24 @@ function M.getStatus()
result.stateCode, result.stateText = getState()
result.stateCode = tonumber(result.stateCode)
local verTable,msg = M.getAvailableVersions()
local verTable,msg = M.getAvailableVersions(includeBetas and 'both' or 'stables')
if not verTable then
D("could not obtain available versions (" .. msg .. ")")
D("error: could not obtain available versions (" .. msg .. ")")
-- TODO: set an error state in result to signify we probably do not have internet access?
return false, result, msg
end
local newest = verTable and verTable[#verTable]
result.newestVersion = newest and newest.version or unknownVersion
result.newestReleaseTimestamp = newest and newest.timestamp
-- look up timestamp of current version
local cEnt = M.findVersion(result.currentVersion, verTable)
if cEnt then
result.currentReleaseTimestamp = cEnt.timestamp
else
D("warning: could not find current wifibox version in release index, beta setting disabled after having beta installed?")
end
if result.stateCode == M.STATE.DOWNLOADING then
result.progress = fileSize(cachePath .. '/' .. newest.sysupgradeFilename)