make use of the new features in the binding for uci v0.4.0 - fixes remaining dependen...
[project/luci.git] / applications / luci-statistics / root / usr / bin / stat-genconfig
index 39532ca..c106ed3 100755 (executable)
@@ -16,31 +16,31 @@ $Id$
 ]]--
 
 
-require("ffluci.model.uci")
-require("ffluci.sys.iptparser")
-require("ffluci.util")
+require("luci.model.uci")
+require("luci.sys.iptparser")
+require("luci.util")
 
-local ipt = ffluci.sys.iptparser.IptParser()
-local uci = ffluci.model.uci.Session()
-local sections, names = uci:sections( "luci_statistics" )
+local ipt = luci.sys.iptparser.IptParser()
+local uci = luci.model.uci.Session()
+local sections = uci:sections( "luci_statistics" )
 
 
 function section( plugin )
 
-       local config = sections[ "collectd_" .. plugin ] or sections["general"]
+       local config = sections[ "collectd_" .. plugin ] or sections["collectd"]
 
-       if type(config) == "table" and ( plugin == "general" or config.enable == "1" ) then
+       if type(config) == "table" and ( plugin == "collectd" or config.enable == "1" ) then
 
                local params = ""
 
                if type( plugins[plugin] ) == "function" then
                        params = plugins[plugin]( config )
                else
-                       params = config_generic( config, plugins[plugin][1], plugins[plugin][2], plugins[plugin][3], plugin == "general" )
+                       params = config_generic( config, plugins[plugin][1], plugins[plugin][2], plugins[plugin][3], plugin == "collectd" )
                end
 
 
-               if plugin ~= "general" then
+               if plugin ~= "collectd" then
                        print( "LoadPlugin " .. plugin )
 
                        if params:len() > 0 then
@@ -61,12 +61,20 @@ function config_generic( c, singles, bools, lists, nopad )
 
                if type(singles) == "table" then
                        for i, key in ipairs( singles ) do
+                               if preprocess[key] then
+                                       c[key] = preprocess[key](c[key])
+                               end
+
                                str = str .. _string( c[key], key, nopad )
                        end
                end
 
                if type(bools) == "table" then
                        for i, key in ipairs( bools ) do
+                               if preprocess[key] then
+                                       c[key] = preprocess[key](c[key])
+                               end
+
                                str = str .. _bool( c[key], key, nopad )
                        end
                end
@@ -113,7 +121,7 @@ function config_iptables( c )
                                v = sections[s][k]
 
                                if type(v) == "string" then
-                                       if k == "options" then v = ffluci.util.split( v, "%s+", nil, true ) end
+                                       if k == "options" then v = luci.util.split( v, "%s+", nil, true ) end
                                        search[k] = v
                                end
                        end
@@ -163,6 +171,10 @@ function _list_expand( c, l, nopad )
 
        for i, n in ipairs(l) do
                if c[n] then
+                       if preprocess[n] then
+                               c[n] = preprocess[n](c[n])
+                       end
+
                        if n:find("(%w+)ses") then
                                k = n:gsub("(%w+)ses", "%1s")
                        else
@@ -180,7 +192,7 @@ function _expand( s, n, nopad )
        if type(s) == "string" then
                local str = ""
 
-               for i, v in ipairs( ffluci.util.split( s, "%s+", nil, true ) ) do
+               for i, v in ipairs( luci.util.split( s, "%s+", nil, true ) ) do
                        str = str .. _string( v, n, nopad )
                end
 
@@ -228,8 +240,14 @@ end
 
 
 plugins = {
-       general = {
-               { "BaseDir", "Include", "PIDFile", "PluginDir", "TypesDB", "Interval", "ReadThreads" },
+       collectd = {
+               { "BaseDir", "Include", "PIDFile", "PluginDir", "TypesDB", "Interval", "ReadThreads", "Hostname" },
+               { },
+               { }
+       },
+
+       cpu     = {
+               { },
                { },
                { }
        },
@@ -329,14 +347,23 @@ plugins = {
                { },
                { }
        },
+}
 
+preprocess = {
+       RRATimespans = function(val)
+               local rv = { }
+               for time in val:gmatch("[^%s]+") do
+                       table.insert( rv, luci.util.parse_units(time) )
+               end
+               return table.concat(rv, " ")
+       end
 }
 
 
-section("general")
+section("collectd")
 
 for plugin in pairs(plugins) do
-       if plugin ~= "general" then
+       if plugin ~= "collectd" then
                section( plugin )
        end
 end