vicious/uptime.lua

37 lines
1.2 KiB
Lua
Raw Normal View History

2009-09-29 22:33:19 +02:00
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2009, Adrian C. <anrxc.sysphere.org>
-- * (c) Wicked, Lucas de Vries
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { open = io.open }
local setmetatable = setmetatable
local math = { floor = math.floor }
-- }}}
-- Uptime: provides system uptime information
module("vicious.uptime")
-- {{{ Uptime widget type
2009-08-07 17:41:10 +02:00
local function worker(format)
-- Get /proc/uptime
local f = io.open("/proc/uptime")
local line = f:read("*line")
f:close()
local total_uptime = math.floor(tonumber(line:match("[%d%.]+")))
local uptime_days = math.floor(total_uptime / (3600 * 24))
local uptime_hours = math.floor((total_uptime % (3600 * 24)) / 3600)
local uptime_minutes = math.floor(((total_uptime % (3600 * 24)) % 3600) / 60)
local uptime_seconds = math.floor(((total_uptime % (3600 * 24)) % 3600) % 60)
return {total_uptime, uptime_days, uptime_hours, uptime_minutes, uptime_seconds}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })