working on new inheritance, chechgauge system

This commit is contained in:
Axel Kittenberger 2012-10-06 13:43:55 +02:00
parent 6a862d6b8f
commit 6f90c19196
3 changed files with 114 additions and 64 deletions

View File

@ -26,8 +26,9 @@ if default.rsync then
end
default.rsync = { }
local rsync = default.rsync
local rsync = { }
default.rsync = rsync
-- uses default collect
--
@ -35,8 +36,6 @@ local rsync = default.rsync
--
rsync.checkgauge = {
default.checkgauge,
-- unsets default user action handlers
onCreate = false,
onModify = false,
@ -46,7 +45,6 @@ rsync.checkgauge = {
delete = true,
exclude = true,
source = true,
target = true,
rsync = {

View File

@ -15,6 +15,21 @@ end
default = { }
--
-- Only this items are inherited from the default
-- table
--
default._merge = {
action = true,
checkgauge = true,
collect = true,
delay = true,
init = true,
maxDelays = true,
maxProcesses = true,
prepare = true,
}
--
-- used to ensure there aren't typos in the keys
--
@ -33,8 +48,9 @@ default.checkgauge = {
onStartup = true,
onMove = true,
prepare = true,
rsyncExitCodes = true, -- TODO
sshExitCodes = true -- TODO
-- rsyncExitCodes = true, -- TODO
source = true,
-- sshExitCodes = true -- TODO
}
--
@ -195,13 +211,6 @@ default.init = function(event)
end
--
-- The maximum number of processes Lsyncd will
-- simultanously spawn for this sync.
--
default.maxProcesses = 1
--
-- The collapsor tries not to have more than these delays.
-- So it dealy stack does not grow too large,
@ -210,11 +219,11 @@ default.maxProcesses = 1
default.maxDelays = 1000
---
-- a default configuration using /bin/cp|rm|mv.
-- TODO huh?
--
default.direct = default_direct
-- The maximum number of processes Lsyncd will
-- simultanously spawn for this sync.
--
default.maxProcesses = 1
--
@ -294,6 +303,7 @@ default.statusInterval = 10
local function check(
config,
gauge,
subtable,
level
)
for k, v in pairs( config ) do
@ -301,6 +311,7 @@ local function check(
if not gauge[k] then
error(
'Parameter "'
.. subtable
.. k
.. '" unknown.'
.. ' (if this is not a typo add it to checkgauge)',
@ -314,6 +325,7 @@ local function check(
error(
'Parameter "'
.. subtable
.. k
.. '" must be a table.',
level
@ -321,7 +333,12 @@ local function check(
end
check( config[ k ], gauge[ k ], level + 1 )
check(
config[ k ],
gauge[ k ],
subtable .. k .. '.',
level + 1
)
end
end
@ -335,6 +352,6 @@ default.prepare = function( config, level )
return
end
check( config, gauge, level or 2 )
check( config, gauge, '', level or 2 )
end

View File

@ -2119,7 +2119,7 @@ local Syncs = ( function( )
--
-- the list of all syncs
--
local list = Array.new( )
local syncsList = Array.new( )
--
-- The round robin pointer. In case of global limited maxProcesses
@ -2134,7 +2134,7 @@ local Syncs = ( function( )
round = round + 1;
if round > #list then
if round > #syncsList then
round = 1
end
@ -2152,7 +2152,7 @@ local Syncs = ( function( )
-- Returns sync at listpos i
--
local function get( i )
return list[ i ];
return syncsList[ i ];
end
--
@ -2182,7 +2182,17 @@ local Syncs = ( function( )
-- non integer keys
--
for k, v in pairs( cs ) do
if type( k ) ~= 'number' or cs._verbatim == true then
if
(
type( k ) ~= 'number' or
cs._verbatim == true
)
and
(
type( cs._merge ) ~= 'table' or
cs._merge[ k ] == true
)
then
inheritKV( cd, k, v )
end
end
@ -2211,25 +2221,27 @@ local Syncs = ( function( )
--
inheritKV = function( cd, k, v )
-- don't merge inheritance controls
if k == '_merge' or k == '_verbatim' then
return
end
local dtype = type( cd [ k ] )
if type( v ) == 'table' then
if dtype == 'nil' then
cd[ k ] = { }
inherit( cd[ k ], v )
elseif dtype == 'table' and v._merge ~= false then
elseif
dtype == 'table' and
v._merge ~= false
then
inherit( cd[ k ], v )
end
elseif dtype == 'nil' then
cd[ k ] = v
end
end
@ -2240,22 +2252,42 @@ local Syncs = ( function( )
--
local function add( config )
-- Creates a new config table and inherit all keys/values
-- Creates a new config table which inherits all keys/values
-- from integer keyed tables
local uconfig = config
config = { }
inherit( config, uconfig, false )
-- Lets settings or commandline override delay values.
config = { }
inherit( config, uconfig )
--
-- last and least defaults are inherited
--
inherit( config, default )
local inheritSettings = {
'delay',
'maxDelays',
'maxProcesses'
}
-- Lets settings or commandline override these values.
if settings then
config.delay = settings.delay or config.delay
for _, v in ipairs( inheritSettings ) do
if settings[ v ] then
config[ v ] = settings[ v ]
end
end
end
-- at very first lets the userscript 'prepare' function
-- fill out more values.
--
-- lets the userscript 'prepare' function
-- check and complete the config
--
if type( config.prepare ) == 'function' then
-- explicitly gives a writeable copy of config.
-- prepare is given a writeable copy of config
config.prepare( config )
end
if not config[ 'source' ] then
@ -2268,7 +2300,9 @@ local Syncs = ( function( )
terminate( -1 )
end
--
-- absolute path of source
--
local realsrc = lsyncd.realdir( config.source )
if not realsrc then
@ -2307,20 +2341,6 @@ local Syncs = ( function( )
settings = {}
end
local defaultValues = {
'action',
'collect',
'init',
'maxDelays',
'maxProcesses',
}
for _, dn in pairs( defaultValues ) do
if config[ dn ] == nil then
config[ dn ] = settings[ dn ] or default[ dn ]
end
end
-- the monitor to use
config.monitor =
settings.monitor or
@ -2347,7 +2367,9 @@ local Syncs = ( function( )
--- creates the new sync
local s = Sync.new( config )
table.insert( list, s )
table.insert( syncsList, s )
return s
end
@ -2355,21 +2377,21 @@ local Syncs = ( function( )
-- Allows a for-loop to walk through all syncs.
--
local function iwalk( )
return ipairs( list )
return ipairs( syncsList )
end
--
-- Returns the number of syncs.
--
local size = function( )
return #list
return #syncsList
end
--
-- Tests if any sync is interested in a path.
--
local function concerns( path )
for _, s in ipairs( list ) do
for _, s in ipairs( syncsList ) do
if s:concerns( path ) then
return true
end
@ -3761,41 +3783,54 @@ function runner.initialize( firstTime )
settings[ v ]= true
end
--
-- all command line settings overwrite config file settings
--
for k, v in pairs( clSettings ) do
if k ~= 'syncs' then
settings[ k ] = v
end
end
-- implicitly force 'insist' on Lsyncd resets.
--
-- implicitly forces 'insist' on Lsyncd resets.
--
if not firstTime then
settings.insist = true
end
--
-- adds syncs specified by command line.
--
if clSettings.syncs then
for _, s in ipairs( clSettings.syncs ) do
if s[1] == 'rsync' then
if s[ 1 ] == 'rsync' then
sync{
default.rsync,
source = s[ 2 ],
target = s[ 3 ]
}
elseif s[1] == 'rsyncssh' then
elseif s[ 1 ] == 'rsyncssh' then
sync{
default.rsyncssh,
source = s[ 2 ],
host = s[ 3 ],
targetdir=s[ 4 ]
}
elseif s[1] == 'direct' then
sync{ default.direct, source=s[2], target=s[3]}
elseif s[ 1 ] == 'direct' then
sync{
default.direct,
source=s[ 2 ],
target=s[ 3 ]
}
end
end