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

Fix cleanup in info/logfiles api.

This commit is contained in:
Wouter R 2013-10-10 17:17:23 +02:00
parent 6e80ca8aa2
commit 43eaab4cbf

View File

@ -43,14 +43,14 @@ end
function M.logfiles(request, response)
local rv,msg = lfs.mkdir(LOG_COLLECT_DIR)
local rv,msg = lfs.chdir(TMP_DIR)
--[[ create temporary files ]]--
local rv,sig,code = redirectedExecute('cp ' .. WIFIBOX_LOG_FILE .. ' ' .. LOG_COLLECT_DIR)
local rv,sig,code = os.execute('logread > ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
for file in lfs.dir(PRINT3D_BASEPATH) do
if file:find(PRINT3D_LOG_FILENAME_PREFIX) == 1 and file:find(PRINT3D_LOG_FILENAME_SUFFIX) ~= nil then
local srcLogFile = PRINT3D_BASEPATH .. '/' .. file
@ -58,44 +58,42 @@ function M.logfiles(request, response)
local rv,sig,code = redirectedExecute('cp ' .. srcLogFile .. ' ' .. tgtLogFile)
end
end
local rv,sig,code = redirectedExecute('tar czf ' .. LOG_COLLECT_ARCHIVE_FILE .. ' ' .. LOG_COLLECT_DIRNAME) --returns 0 success, 1 error
--[[ add response content ]]--
local rv,msg = response:setBinaryFileData(LOG_COLLECT_ARCHIVE_FILE, LOG_COLLECT_ARCHIVE_FILENAME, 'application/x-compressed')
if not rv then
response:setError("could not set binary data from file '" .. LOG_COLLECT_ARCHIVE_FILE .. "' (" .. msg .. ")")
else
response:setSuccess()
end
--[[ remove temporary files ]]--
if ultip and ultip == 'directory' then
for file in lfs.dir(ULTIFI_PATH) do
if file ~= '.' and file ~= '..' then
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file .. '-' .. ULTIFI_LOG_FILENAME
local rv,sig,code = redirectedExecute('rm ' .. tgtLogFile)
end
for file in lfs.dir(LOG_COLLECT_DIR) do
if file:find(PRINT3D_LOG_FILENAME_PREFIX) == 1 and file:find(PRINT3D_LOG_FILENAME_SUFFIX) ~= nil then
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file
local rv,sig,code = redirectedExecute('rm ' .. tgtLogFile)
end
end
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. WIFIBOX_LOG_FILENAME)
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
local rv,msg = lfs.rmdir(LOG_COLLECT_DIR)
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_ARCHIVE_FILE)
end
function M.access(request, response)
--log:info(" remoteAddress: |"..utils.dump(request.remoteAddress).."|");
--log:info(" controller: |"..utils.dump(accessManager.getController()).."|");
-- when there is a controller we check if the printer is idle,
-- if so, it should be done printing and we can clear the controller
if accessManager.getController() ~= "" then
@ -104,31 +102,31 @@ function M.access(request, response)
local rv,msg = printer:getState()
if rv then
response:setSuccess()
if(state == "idle") then -- TODO: define in constants somewhere
if(state == "idle") then -- TODO: define in constants somewhere
accessManager.setController("") -- clear controller
end
else
response:setError(msg)
return
return
end
end
local hasControl = accessManager.hasControl(request.remoteAddress)
response:setSuccess()
response:addData('hasControl', hasControl)
return
return
end
function M.status(request, response)
printerAPI.temperature(request, response)
printerAPI.progress(request, response)
printerAPI.state(request, response)
M.access(request, response)
response:addData('v', 9)
end
return M