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 end
default.rsync = { } local rsync = { }
local rsync = default.rsync default.rsync = rsync
-- uses default collect -- uses default collect
-- --
@ -35,8 +36,6 @@ local rsync = default.rsync
-- --
rsync.checkgauge = { rsync.checkgauge = {
default.checkgauge,
-- unsets default user action handlers -- unsets default user action handlers
onCreate = false, onCreate = false,
onModify = false, onModify = false,
@ -46,7 +45,6 @@ rsync.checkgauge = {
delete = true, delete = true,
exclude = true, exclude = true,
source = true,
target = true, target = true,
rsync = { rsync = {

View File

@ -15,6 +15,21 @@ end
default = { } 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 -- used to ensure there aren't typos in the keys
-- --
@ -33,8 +48,9 @@ default.checkgauge = {
onStartup = true, onStartup = true,
onMove = true, onMove = true,
prepare = true, prepare = true,
rsyncExitCodes = true, -- TODO -- rsyncExitCodes = true, -- TODO
sshExitCodes = true -- TODO source = true,
-- sshExitCodes = true -- TODO
} }
-- --
@ -195,13 +211,6 @@ default.init = function(event)
end 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. -- The collapsor tries not to have more than these delays.
-- So it dealy stack does not grow too large, -- So it dealy stack does not grow too large,
@ -210,11 +219,11 @@ default.maxProcesses = 1
default.maxDelays = 1000 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( local function check(
config, config,
gauge, gauge,
subtable,
level level
) )
for k, v in pairs( config ) do for k, v in pairs( config ) do
@ -301,6 +311,7 @@ local function check(
if not gauge[k] then if not gauge[k] then
error( error(
'Parameter "' 'Parameter "'
.. subtable
.. k .. k
.. '" unknown.' .. '" unknown.'
.. ' (if this is not a typo add it to checkgauge)', .. ' (if this is not a typo add it to checkgauge)',
@ -314,6 +325,7 @@ local function check(
error( error(
'Parameter "' 'Parameter "'
.. subtable
.. k .. k
.. '" must be a table.', .. '" must be a table.',
level level
@ -321,7 +333,12 @@ local function check(
end end
check( config[ k ], gauge[ k ], level + 1 ) check(
config[ k ],
gauge[ k ],
subtable .. k .. '.',
level + 1
)
end end
end end
@ -335,6 +352,6 @@ default.prepare = function( config, level )
return return
end end
check( config, gauge, level or 2 ) check( config, gauge, '', level or 2 )
end end

View File

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