vicious/widgets/pkg_all.lua

46 lines
1.3 KiB
Lua
Raw Normal View History

2009-09-29 22:33:19 +02:00
---------------------------------------------------
-- Licensed under the GNU General Public License v2
2010-01-02 21:21:54 +01:00
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
2009-09-29 22:33:19 +02:00
---------------------------------------------------
-- {{{ Grab environment
local spawn = require("vicious.spawn")
local helpers = require("vicious.helpers")
-- }}}
2010-08-29 13:53:26 +02:00
-- Pkg: provides number of pending updates on UNIX systems
-- vicious.widgets.pkg
2017-01-25 17:54:55 +01:00
local pkg_all = {}
local PKGMGR = {
["Arch"] = { cmd = "pacman -Qu" },
["Arch C"] = { cmd = "checkupdates" },
["Arch S"] = { cmd = "yes | pacman -Sup", sub = 1 },
["Debian"] = { cmd = "apt list --upgradable", sub = 1 },
["Ubuntu"] = { cmd = "apt list --upgradable", sub = 1 },
["Fedora"] = { cmd = "dnf check-update", sub = 2 },
["FreeBSD"] = { cmd = "pkg version -I -l '<'" },
["Mandriva"] = { cmd = "urpmq --auto-select" }
}
-- {{{ Packages widget type
function pkg_all.async(format, warg, callback)
if not warg then return callback{} end
local pkgmgr = PKGMGR[warg]
local size, lines = -pkgmgr.sub, ""
spawn.with_line_callback_with_shell(pkgmgr.cmd, {
stdout = function (str)
size = size + 1
if size > 0 then lines = lines .. str .. "\n" end
end,
output_done = function ()
callback{ size, lines }
end
})
end
-- }}}
return helpers.setasyncall(pkg_all)