ENH use external pacman update script now

This commit is contained in:
Nathan Dwarshuis 2019-10-10 22:52:49 -04:00
parent d4c2fa1f59
commit 3457a5f675
2 changed files with 42 additions and 11 deletions

View File

@ -5,13 +5,10 @@ local Line = require 'Line'
local TextColumn = require 'TextColumn' local TextColumn = require 'TextColumn'
local Util = require 'Util' local Util = require 'Util'
local PACMAN_TABLE = { local __string_match = string.match
'pacman -Qq', local __string_gmatch = string.gmatch
'pacman -Qeq',
'pacman -Quq', local STATS_FILE = '/tmp/.conky_pacman'
'pacman -Qdtq',
'pacman -Qmq'
}
local _TEXT_SPACING_ = 20 local _TEXT_SPACING_ = 20
@ -44,9 +41,18 @@ local info = _G_Widget_.TextColumn{
_TEXT_SPACING_ = nil _TEXT_SPACING_ = nil
local update = function(cr) local update = function(cr)
for i, cmd in pairs(PACMAN_TABLE) do local stats = __string_match(Util.read_file(STATS_FILE), '%d+%s+(.*)$')
TextColumn.set(info, cr, i, Util.line_count(Util.execute_cmd(cmd))) if stats then
end local i = 1
for v in __string_gmatch(stats, '[^%s]+') do
TextColumn.set(info, cr, i, v)
i = i + 1
end
else
for i=1,5 do
TextColumn.set(info, cr, i, 'N/A')
end
end
end end
local draw_static = function(cr) local draw_static = function(cr)
@ -57,7 +63,7 @@ end
local draw_dynamic = function(cr, log_is_changed) local draw_dynamic = function(cr, log_is_changed)
if log_is_changed then update(cr) end if log_is_changed then update(cr) end
TextColumn.draw(info, cr) TextColumn.draw(info, cr)
end end

25
scripts/pacman_stats Executable file
View File

@ -0,0 +1,25 @@
#! /bin/bash
stat_file=/tmp/.conky_pacman
log_file=/var/log/pacman.log
write_stats() {
now=$(date +%s)
tot=$(pacman -Qq | wc -l)
exp=$(pacman -Qeq | wc -l)
out=$(pacman -Quq | wc -l)
orp=$(pacman -Qdtq | wc -l)
loc=$(pacman -Qmq | wc -l)
echo "$now" "$tot" "$exp" "$out" "$orp" "$loc" > "$stat_file"
}
if [[ -f "$stat_file" ]]; then
last_pacman_update=$(stat -c %Y "$log_file")
last_stat_update=$(awk '{ print $1 }' "$stat_file")
if (( last_pacman_update > last_stat_update )); then
write_stats
fi
else
write_stats
fi