spaces->tab, equipper improvements, supertreefarm rewrite, follow improvements, sensor cleanup, milo multiple items allowed in recipes, remote canvas access
This commit is contained in:
@@ -21,97 +21,97 @@ Backup configuration files each minecraft day.
|
||||
]]
|
||||
|
||||
local wizardPage = UI.WizardPage {
|
||||
title = 'Backup Drive',
|
||||
index = 2,
|
||||
backgroundColor = colors.cyan,
|
||||
[1] = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value = string.format(template, Ansi.yellow, Ansi.reset),
|
||||
},
|
||||
title = 'Backup Drive',
|
||||
index = 2,
|
||||
backgroundColor = colors.cyan,
|
||||
[1] = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value = string.format(template, Ansi.yellow, Ansi.reset),
|
||||
},
|
||||
}
|
||||
|
||||
function wizardPage:isValidType(node)
|
||||
local m = device[node.name]
|
||||
return m and m.type == 'drive' and {
|
||||
name = 'Backup Drive',
|
||||
value = 'backup',
|
||||
category = 'custom',
|
||||
help = 'Backup configuration files',
|
||||
}
|
||||
local m = device[node.name]
|
||||
return m and m.type == 'drive' and {
|
||||
name = 'Backup Drive',
|
||||
value = 'backup',
|
||||
category = 'custom',
|
||||
help = 'Backup configuration files',
|
||||
}
|
||||
end
|
||||
|
||||
function wizardPage:isValidFor(node)
|
||||
return node.mtype == 'backup'
|
||||
return node.mtype == 'backup'
|
||||
end
|
||||
|
||||
UI:getPage('nodeWizard').wizard:add({ backupDrive = wizardPage })
|
||||
|
||||
local function clearOld(dir, fname)
|
||||
local files = { }
|
||||
local files = { }
|
||||
|
||||
for _, file in pairs(fs.list(dir)) do
|
||||
if file:match(fname) then
|
||||
table.insert(files, file)
|
||||
end
|
||||
end
|
||||
if #files > 1 then
|
||||
table.sort(files, function(a, b)
|
||||
return tonumber(a:match('.(%d+)')) > tonumber(b:match('.(%d+)'))
|
||||
end)
|
||||
while #files > 1 do
|
||||
local old = table.remove(files, #files)
|
||||
fs.delete(fs.combine(dir, old))
|
||||
end
|
||||
end
|
||||
for _, file in pairs(fs.list(dir)) do
|
||||
if file:match(fname) then
|
||||
table.insert(files, file)
|
||||
end
|
||||
end
|
||||
if #files > 1 then
|
||||
table.sort(files, function(a, b)
|
||||
return tonumber(a:match('.(%d+)')) > tonumber(b:match('.(%d+)'))
|
||||
end)
|
||||
while #files > 1 do
|
||||
local old = table.remove(files, #files)
|
||||
fs.delete(fs.combine(dir, old))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function makeBackup(dir, fname)
|
||||
clearOld(dir, fname)
|
||||
local source = fs.combine('usr/config', fname)
|
||||
local dest = string.format('%s/%s.%d', dir, fname, os.day())
|
||||
fs.copy(source, dest)
|
||||
clearOld(dir, fname)
|
||||
local source = fs.combine('usr/config', fname)
|
||||
local dest = string.format('%s/%s.%d', dir, fname, os.day())
|
||||
fs.copy(source, dest)
|
||||
end
|
||||
|
||||
local function backupNode(node)
|
||||
local files = {
|
||||
'storage',
|
||||
'milo.state',
|
||||
'machine_crafting.db',
|
||||
'recipes.db',
|
||||
'resources.db',
|
||||
}
|
||||
local s, m = pcall(function()
|
||||
if not node.adapter.isDiskPresent() then
|
||||
_G._syslog('BACKUP error: No media present')
|
||||
else
|
||||
local dir = node.adapter.getMountPath()
|
||||
for _, v in pairs(files) do
|
||||
makeBackup(dir, v)
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not s and m then
|
||||
_G._syslog('BACKUP error:' .. m)
|
||||
end
|
||||
local files = {
|
||||
'storage',
|
||||
'milo.state',
|
||||
'machine_crafting.db',
|
||||
'recipes.db',
|
||||
'resources.db',
|
||||
}
|
||||
local s, m = pcall(function()
|
||||
if not node.adapter.isDiskPresent() then
|
||||
_G._syslog('BACKUP error: No media present')
|
||||
else
|
||||
local dir = node.adapter.getMountPath()
|
||||
for _, v in pairs(files) do
|
||||
makeBackup(dir, v)
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not s and m then
|
||||
_G._syslog('BACKUP error:' .. m)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Task ]]--
|
||||
local BackupTask = {
|
||||
name = 'backup',
|
||||
priority = 99,
|
||||
name = 'backup',
|
||||
priority = 99,
|
||||
}
|
||||
|
||||
function BackupTask:cycle()
|
||||
for node in context.storage:filterActive('backup') do
|
||||
if not drives[node.name] then
|
||||
drives[node.name] = Event.onInterval(DAY, function()
|
||||
_G._syslog('BACKUP: started')
|
||||
if node.adapter and node.adapter.online then
|
||||
backupNode(node)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
for node in context.storage:filterActive('backup') do
|
||||
if not drives[node.name] then
|
||||
drives[node.name] = Event.onInterval(DAY, function()
|
||||
_G._syslog('BACKUP: started')
|
||||
if node.adapter and node.adapter.online then
|
||||
backupNode(node)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Milo:registerTask(BackupTask)
|
||||
|
||||
Reference in New Issue
Block a user