ENH move last update and sync to the pacman_update systemd script

This commit is contained in:
Nathan Dwarshuis 2019-10-11 21:52:10 -04:00
parent 3457a5f675
commit 07f2e89c77
5 changed files with 33 additions and 39 deletions

2
core

@ -1 +1 @@
Subproject commit ad2b82afa454a6c329953bb256e692691e5fd471 Subproject commit 7962fea2442ec51c1e1b30b2822b11959bbbf7d6

View File

@ -8,8 +8,6 @@ local Util = require 'Util'
local __string_match = string.match local __string_match = string.match
local __string_gmatch = string.gmatch local __string_gmatch = string.gmatch
local STATS_FILE = '/tmp/.conky_pacman'
local _TEXT_SPACING_ = 20 local _TEXT_SPACING_ = 20
local header = _G_Widget_.Header{ local header = _G_Widget_.Header{
@ -40,11 +38,11 @@ local info = _G_Widget_.TextColumn{
_TEXT_SPACING_ = nil _TEXT_SPACING_ = nil
local update = function(cr) local update = function(cr, pacman_stats)
local stats = __string_match(Util.read_file(STATS_FILE), '%d+%s+(.*)$') local stats = __string_match(pacman_stats, '%d+%s+[^%s]+%s+[^%s]+%s+(.*)$')
if stats then if stats then
local i = 1 local i = 1
for v in __string_gmatch(stats, '[^%s]+') do for v in __string_gmatch(stats, '%d+') do
TextColumn.set(info, cr, i, v) TextColumn.set(info, cr, i, v)
i = i + 1 i = i + 1
end end
@ -61,9 +59,8 @@ local draw_static = function(cr)
TextColumn.draw(labels, cr) TextColumn.draw(labels, cr)
end end
local draw_dynamic = function(cr, log_is_changed) local draw_dynamic = function(cr, pacman_stats)
if log_is_changed then update(cr) end update(cr, pacman_stats)
TextColumn.draw(info, cr) TextColumn.draw(info, cr)
end end

View File

@ -50,16 +50,15 @@ local draw_static = function(cr)
TextColumn.draw(labels, cr) TextColumn.draw(labels, cr)
end end
local draw_dynamic = function(cr, log_is_changed) local draw_dynamic = function(cr, pacman_stats)
TextColumn.set(info, cr, 2, Util.conky('$uptime')) TextColumn.set(info, cr, 2, Util.conky('$uptime'))
if log_is_changed then if pacman_stats then
TextColumn.set(info, cr, 3, extract_date("sed -n ".. local last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*")
"'/ starting full system upgrade/p' /var/log/pacman.log | tail -1")) TextColumn.set(info, cr, 3, last_update)
TextColumn.set(info, cr, 4, extract_date("sed -n ".. TextColumn.set(info, cr, 4, last_sync)
"'/ synchronizing package lists/p' /var/log/pacman.log | tail -1"))
end end
TextColumn.draw(info, cr) TextColumn.draw(info, cr)
end end

View File

@ -172,26 +172,20 @@ local using_ac = function()
return Util.read_file('/sys/class/power_supply/AC/online', nil, '*n') == 1 return Util.read_file('/sys/class/power_supply/AC/online', nil, '*n') == 1
end end
local LASTLOG_CMD = 'tail -1 /var/log/pacman.log'
local current_last_log_entry = Util.execute_cmd(LASTLOG_CMD)
local check_if_log_changed = function()
local new_last_log_entry = Util.execute_cmd(LASTLOG_CMD)
if new_last_log_entry == current_last_log_entry then return 1 end
current_last_log_entry = new_last_log_entry
return 0
end
-- --
-- main loop -- main loop
-- --
local updates = -2 -- this accounts for the first few spazzy iterations local updates = -2 -- this accounts for the first few spazzy iterations
local __collectgarbage = collectgarbage local __collectgarbage = collectgarbage
local STATS_FILE = '/tmp/.conky_pacman'
function conky_main() function conky_main()
local _cw = conky_window local _cw = conky_window
if not _cw then return end if not _cw then return end
-- local time = os.clock()
local cs = __cairo_xlib_surface_create(_cw.display, _cw.drawable, local cs = __cairo_xlib_surface_create(_cw.display, _cw.drawable,
_cw.visual, 1920, 1080) _cw.visual, 1920, 1080)
local cr = __cairo_create(cs) local cr = __cairo_create(cs)
@ -203,25 +197,17 @@ function conky_main()
local t1 = updates % (UPDATE_FREQUENCY * 10) local t1 = updates % (UPDATE_FREQUENCY * 10)
local t2
local is_using_ac = using_ac() local is_using_ac = using_ac()
if is_using_ac then local pacman_stats = Util.read_file(STATS_FILE)
t2 = updates % (UPDATE_FREQUENCY * 60)
else
t2 = updates % (UPDATE_FREQUENCY * 300)
end
local log_is_changed = false System.draw_dynamic(cr, pacman_stats)
if t2 == 0 then log_is_changed = check_if_log_changed() end
System.draw_dynamic(cr, log_is_changed)
Graphics.draw_dynamic(cr) Graphics.draw_dynamic(cr)
Processor.draw_dynamic(cr) Processor.draw_dynamic(cr)
ReadWrite.draw_dynamic(cr, UPDATE_FREQUENCY) ReadWrite.draw_dynamic(cr, UPDATE_FREQUENCY)
Network.draw_dynamic(cr, UPDATE_FREQUENCY) Network.draw_dynamic(cr, UPDATE_FREQUENCY)
Pacman.draw_dynamic(cr, log_is_changed) Pacman.draw_dynamic(cr, pacman_stats)
FileSystem.draw_dynamic(cr, t1) FileSystem.draw_dynamic(cr, t1)
Power.draw_dynamic(cr, UPDATE_FREQUENCY, is_using_ac) Power.draw_dynamic(cr, UPDATE_FREQUENCY, is_using_ac)
Memory.draw_dynamic(cr) Memory.draw_dynamic(cr)
@ -229,4 +215,6 @@ function conky_main()
__cairo_surface_destroy(cs) __cairo_surface_destroy(cs)
__cairo_destroy(cr) __cairo_destroy(cr)
__collectgarbage() __collectgarbage()
-- print(os.clock() - time)
end end

View File

@ -3,14 +3,24 @@
stat_file=/tmp/.conky_pacman stat_file=/tmp/.conky_pacman
log_file=/var/log/pacman.log log_file=/var/log/pacman.log
get_log_date() {
sed -n "s/\[\(.*\)\] \[PACMAN\] $1/\1/p" \
/var/log/pacman.log | \
tail -1 \
| { read -r f; date -d "$f" +%m-%d-%Y; }
}
write_stats() { write_stats() {
now=$(date +%s) now=$(date +%s)
last_upgrade=$(get_log_date "starting full system upgrade")
last_sync=$(get_log_date "synchronizing package lists")
tot=$(pacman -Qq | wc -l) tot=$(pacman -Qq | wc -l)
exp=$(pacman -Qeq | wc -l) exp=$(pacman -Qeq | wc -l)
out=$(pacman -Quq | wc -l) out=$(pacman -Quq | wc -l)
orp=$(pacman -Qdtq | wc -l) orp=$(pacman -Qdtq | wc -l)
loc=$(pacman -Qmq | wc -l) loc=$(pacman -Qmq | wc -l)
echo "$now" "$tot" "$exp" "$out" "$orp" "$loc" > "$stat_file" echo "$now" "$last_upgrade" "$last_sync" "$tot" "$exp" "$out" \
"$orp" "$loc" > "$stat_file"
} }
if [[ -f "$stat_file" ]]; then if [[ -f "$stat_file" ]]; then