convert luci.fs users to nixio.fs api
[project/luci.git] / applications / luci-statistics / luasrc / statistics / rrdtool.lua
index 4335245837a243b210722838a6b42406047042ac..eb5c266b0e5e478eabe7229741c1e28249453db5 100644 (file)
@@ -22,7 +22,8 @@ require("luci.statistics.i18n")
 require("luci.model.uci")
 require("luci.util")
 require("luci.sys")
-require("luci.fs")
+
+local fs = require "nixio.fs"
 
 
 Graph = luci.util.class()
@@ -31,8 +32,8 @@ function Graph.__init__( self, timespan, opts )
 
        opts = opts or { }
 
-       local uci = luci.model.uci
-       local sections = uci.get_all( "luci_statistics" )
+       local uci = luci.model.uci.cursor()
+       local sections = uci:get_all( "luci_statistics" )
 
        -- helper classes
        self.colors = luci.statistics.rrdtool.colors.Instance()
@@ -42,7 +43,7 @@ function Graph.__init__( self, timespan, opts )
 
        -- options
        opts.timespan  = timespan       or sections.rrdtool.default_timespan or 900
-       opts.rrasingle = opts.rrasingle or ( sections.collectd_rrdtool.RRASingle ~= "0" )
+       opts.rrasingle = opts.rrasingle or ( sections.collectd_rrdtool.RRASingle == "1" )
        opts.host      = opts.host      or sections.collectd.Hostname        or luci.sys.hostname()
        opts.width     = opts.width     or sections.rrdtool.image_width      or 400
        opts.rrdpath   = opts.rrdpath   or sections.collectd_rrdtool.DataDir or "/tmp/rrd"
@@ -96,7 +97,7 @@ function Graph._rrdtool( self, def, rrd )
 
        -- prepare directory
        local dir = def[1]:gsub("/[^/]+$","")
-       luci.fs.mkdir( dir, true )
+       fs.mkdirr( dir )
 
        -- construct commandline
        local cmdline = "rrdtool graph"
@@ -281,22 +282,22 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index )
 
                -- don't include MIN if rrasingle is enabled
                if not self.opts.rrasingle then
-                       _tif( _args, "GPRINT:%s_min:MIN:%s Min", source.sname, numfmt )
+                       _tif( _args, "GPRINT:%s_min:MIN:\tMin\\: %s", source.sname, numfmt )
                end
 
                -- always include AVERAGE
-               _tif( _args, "GPRINT:%s_avg:AVERAGE:%s Avg", source.sname, numfmt )
+               _tif( _args, "GPRINT:%s_avg:AVERAGE:\tAvg\\: %s", source.sname, numfmt )
 
                -- don't include MAX if rrasingle is enabled
                if not self.opts.rrasingle then
-                       _tif( _args, "GPRINT:%s_max:MAX:%s Max", source.sname, numfmt )
+                       _tif( _args, "GPRINT:%s_max:MAX:\tMax\\: %s", source.sname, numfmt )
                end
 
                -- include total count if requested else include LAST
                if source.total then
                        _tif( _args, "GPRINT:%s_avg_sum:LAST:(ca. %s Total)\\l", source.sname, totfmt )
                else
-                       _tif( _args, "GPRINT:%s_avg:LAST:%s Last\\l", source.sname, numfmt )
+                       _tif( _args, "GPRINT:%s_avg:LAST:\tLast\\: %s\\l", source.sname, numfmt )
                end
        end
 
@@ -500,7 +501,7 @@ function Graph.render( self, plugin, plugin_instance )
 
        -- check for a whole graph handler
        local plugin_def = "luci.statistics.rrdtool.definitions." .. plugin
-       local stat, def = luci.util.copcall( require, plugin_def )
+       local stat, def = pcall( require, plugin_def )
 
        if stat and def and type(def.rrdargs) == "function" then
 
@@ -539,7 +540,7 @@ function Graph.render( self, plugin, plugin_instance )
 
                        -- check for data type handler
                        local dtype_def = plugin_def .. "." .. dtype
-                       local stat, def = luci.util.copcall( require, dtype_def )
+                       local stat, def = pcall( require, dtype_def )
 
                        if stat and def and type(def.rrdargs) == "function" then