0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-12-22 11:03:48 +01:00

API:config/resetall

This commit is contained in:
peteruithoven 2013-11-22 18:05:51 +01:00
parent 10cf3c35b1
commit d9afb1159e
2 changed files with 35 additions and 0 deletions

View File

@ -88,6 +88,15 @@ function M.all_GET(request, response)
end
end
function M.resetall_POST(request, response)
response:setSuccess()
settings.resetAll()
for k,v in pairs(settings.getAll()) do
response:addData(k,v)
end
end
function M.supportedprinters_GET(request, response)
response:setSuccess()
for k,v in pairs(printer.supportedPrinters()) do

View File

@ -239,6 +239,32 @@ function M.set(key, value)
return true
end
--- Reset all settings to their default values
-- @string key The key to set.
-- @treturn bool|nil True if everything went well, nil in case of error.
function M.resetAll()
log:info("settings:resetAll")
for k,_ in pairs(baseconfig) do
if not k:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
M.reset(k)
end
end
return true
end
--- Reset setting to default value
-- @string key The key to reset.
-- @treturn bool|nil True if everything went well, nil in case of error.
function M.reset(key)
log:info("settings:reset")
--log:info(" key: "..utils.dump(key))
uci:delete(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key)
uci:commit(UCI_CONFIG_NAME)
return true
end
--- Returns a UCI configuration key from the system section.
-- @string key The key for which to return the value, must be non-empty.
-- @return Requested value or false if it does not exist or nil on invalid key.