| 1 | -- widget type providing number of pending updates |
| 2 | -- Copyright (C) 2010 Adrian C. <[email protected]> |
| 3 | -- Copyright (C) 2017 Joerg Thalheim <[email protected]> |
| 4 | -- Copyright (C) 2017 getzze <[email protected]> |
| 5 | -- Copyright (C) 2017 mutlusun <[email protected]> |
| 6 | -- Copyright (C) 2019 Nguyễn Gia Phong <[email protected]m> |
| 7 | -- Copyright (C) 2020 Elmeri Niemelä <[email protected]> |
| 8 | -- |
| 9 | -- This file is part of Vicious. |
| 10 | -- |
| 11 | -- Vicious is free software: you can redistribute it and/or modify |
| 12 | -- it under the terms of the GNU General Public License as |
| 13 | -- published by the Free Software Foundation, either version 2 of the |
| 14 | -- License, or (at your option) any later version. |
| 15 | -- |
| 16 | -- Vicious is distributed in the hope that it will be useful, |
| 17 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | -- GNU General Public License for more details. |
| 20 | -- |
| 21 | -- You should have received a copy of the GNU General Public License |
| 22 | -- along with Vicious. If not, see <https://www.gnu.org/licenses/>. |
| 23 | |
| 24 | -- {{{ Grab environment |
| 25 | local spawn = require("vicious.spawn") |
| 26 | local helpers = require("vicious.helpers") |
| 27 | -- }}} |
| 28 | |
| 29 | -- Pkg: provides number of pending updates on UNIX systems |
| 30 | -- vicious.widgets.pkg |
| 31 | local pkg_all = {} |
| 32 | |
| 33 | local PKGMGR = { |
| 34 | ["Arch"] = { cmd = "pacman -Qu", sub = 0 }, |
| 35 | ["Arch C"] = { cmd = "checkupdates", sub = 0 }, |
| 36 | ["Arch S"] = { cmd = "yes | pacman -Sup", sub = 1 }, |
| 37 | ["Debian"] = { cmd = "apt list --upgradable", sub = 1 }, |
| 38 | ["Ubuntu"] = { cmd = "apt list --upgradable", sub = 1 }, |
| 39 | ["Fedora"] = { cmd = "dnf check-update", sub = 2 }, |
| 40 | ["FreeBSD"] = { cmd = "pkg version -I -l '<'", sub = 0 }, |
| 41 | ["Mandriva"] = { cmd = "urpmq --auto-select", sub = 0 } |
| 42 | } |
| 43 | |
| 44 | -- {{{ Packages widget type |
| 45 | function pkg_all.async(format, warg, callback) |
| 46 | if not warg then return callback{} end |
| 47 | local pkgmgr = PKGMGR[warg] |
| 48 | |
| 49 | local size, lines = -pkgmgr.sub, "" |
| 50 | spawn.with_line_callback_with_shell(pkgmgr.cmd, { |
| 51 | stdout = function (str) |
| 52 | size = size + 1 |
| 53 | if size > 0 then lines = lines .. str .. "\n" end |
| 54 | end, |
| 55 | output_done = function () |
| 56 | callback{ size, lines } |
| 57 | end |
| 58 | }) |
| 59 | end |
| 60 | -- }}} |
| 61 | |
| 62 | return helpers.setasyncall(pkg_all) |