applications/luci-statistics: rework handling of index and detail graphs
[project/luci.git] / applications / luci-statistics / luasrc / statistics / datatree.lua
index 03608b1..b494dc1 100644 (file)
@@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
-        http://www.apache.org/licenses/LICENSE-2.0
+               http://www.apache.org/licenses/LICENSE-2.0
 
 $Id$
 
@@ -17,9 +17,9 @@ module("luci.statistics.datatree", package.seeall)
 
 local util = require("luci.util")
 local sys  = require("luci.sys")
-local fs   = require("luci.fs")
-local uci  = require("luci.model.uci").Session()
-local sections = uci:sections( "luci_statistics" )
+local fs   = require("nixio.fs")
+local uci  = require("luci.model.uci").cursor()
+local sections = uci:get_all("luci_statistics")
 
 
 Instance = util.class()
@@ -50,6 +50,19 @@ function Instance._mkpath( self, plugin, pinstance )
        return dir
 end
 
+function Instance._ls( self, ... )
+       local ditr = fs.dir(self:_mkpath(...))
+       if ditr then
+               local dirs = { }
+               while true do
+                       local d = ditr()
+                       if not d then break end
+                       dirs[#dirs+1] = d
+               end
+               return dirs
+       end
+end
+
 function Instance._notzero( self, table )
        for k in pairs(table) do
                return true
@@ -59,19 +72,31 @@ function Instance._notzero( self, table )
 end
 
 function Instance._scan( self )
-       local dir = fs.dir( self._libdir )
-       if not dir then
+       local dirs = self:_ls()
+       if not dirs then
                return
        end
-       for i, plugin in ipairs( dir ) do
-               if plugin:match("%w+.so") then
-                       self._plugins[ plugin:gsub(".so", "") ] = { }
+
+--     for i, plugin in ipairs( dirs ) do
+--             if plugin:match("%w+.so") then
+--                     self._plugins[ plugin:gsub("%.so$", "") ] = { }
+--             end
+--     end
+
+       for _, dir in ipairs(dirs) do
+               if dir ~= "." and dir ~= ".." and
+                  fs.stat(self:_mkpath(dir)).type == "dir"
+               then
+                       local plugin = dir:gsub("%-.+$", "")
+                       if not self._plugins[plugin] then
+                               self._plugins[plugin] = { }
+                       end
                end
        end
 
        for plugin, instances in pairs( self._plugins ) do
 
-               local dirs = fs.dir( self:_mkpath() )
+               local dirs = self:_ls()
 
                if type(dirs) == "table" then
                        for i, dir in ipairs(dirs) do
@@ -89,7 +114,7 @@ function Instance._scan( self )
 
                for instance, data_instances in pairs( instances ) do
 
-                       dirs = fs.dir( self:_mkpath( plugin, instance ) )
+                       dirs = self:_ls(plugin, instance)
 
                        if type(dirs) == "table" then
                                for i, file in ipairs(dirs) do