ENH use external pacman update script now
This commit is contained in:
parent
d4c2fa1f59
commit
3457a5f675
|
@ -5,13 +5,10 @@ local Line = require 'Line'
|
|||
local TextColumn = require 'TextColumn'
|
||||
local Util = require 'Util'
|
||||
|
||||
local PACMAN_TABLE = {
|
||||
'pacman -Qq',
|
||||
'pacman -Qeq',
|
||||
'pacman -Quq',
|
||||
'pacman -Qdtq',
|
||||
'pacman -Qmq'
|
||||
}
|
||||
local __string_match = string.match
|
||||
local __string_gmatch = string.gmatch
|
||||
|
||||
local STATS_FILE = '/tmp/.conky_pacman'
|
||||
|
||||
local _TEXT_SPACING_ = 20
|
||||
|
||||
|
@ -44,9 +41,18 @@ local info = _G_Widget_.TextColumn{
|
|||
_TEXT_SPACING_ = nil
|
||||
|
||||
local update = function(cr)
|
||||
for i, cmd in pairs(PACMAN_TABLE) do
|
||||
TextColumn.set(info, cr, i, Util.line_count(Util.execute_cmd(cmd)))
|
||||
end
|
||||
local stats = __string_match(Util.read_file(STATS_FILE), '%d+%s+(.*)$')
|
||||
if stats then
|
||||
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
|
||||
|
||||
local draw_static = function(cr)
|
||||
|
@ -57,7 +63,7 @@ end
|
|||
|
||||
local draw_dynamic = function(cr, log_is_changed)
|
||||
if log_is_changed then update(cr) end
|
||||
|
||||
|
||||
TextColumn.draw(info, cr)
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue