ENH move last update and sync to the pacman_update systemd script
This commit is contained in:
parent
3457a5f675
commit
07f2e89c77
2
core
2
core
|
@ -1 +1 @@
|
|||
Subproject commit ad2b82afa454a6c329953bb256e692691e5fd471
|
||||
Subproject commit 7962fea2442ec51c1e1b30b2822b11959bbbf7d6
|
|
@ -8,8 +8,6 @@ local Util = require 'Util'
|
|||
local __string_match = string.match
|
||||
local __string_gmatch = string.gmatch
|
||||
|
||||
local STATS_FILE = '/tmp/.conky_pacman'
|
||||
|
||||
local _TEXT_SPACING_ = 20
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
|
@ -40,11 +38,11 @@ local info = _G_Widget_.TextColumn{
|
|||
|
||||
_TEXT_SPACING_ = nil
|
||||
|
||||
local update = function(cr)
|
||||
local stats = __string_match(Util.read_file(STATS_FILE), '%d+%s+(.*)$')
|
||||
local update = function(cr, pacman_stats)
|
||||
local stats = __string_match(pacman_stats, '%d+%s+[^%s]+%s+[^%s]+%s+(.*)$')
|
||||
if stats then
|
||||
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)
|
||||
i = i + 1
|
||||
end
|
||||
|
@ -61,9 +59,8 @@ local draw_static = function(cr)
|
|||
TextColumn.draw(labels, cr)
|
||||
end
|
||||
|
||||
local draw_dynamic = function(cr, log_is_changed)
|
||||
if log_is_changed then update(cr) end
|
||||
|
||||
local draw_dynamic = function(cr, pacman_stats)
|
||||
update(cr, pacman_stats)
|
||||
TextColumn.draw(info, cr)
|
||||
end
|
||||
|
||||
|
|
|
@ -50,16 +50,15 @@ local draw_static = function(cr)
|
|||
TextColumn.draw(labels, cr)
|
||||
end
|
||||
|
||||
local draw_dynamic = function(cr, log_is_changed)
|
||||
local draw_dynamic = function(cr, pacman_stats)
|
||||
TextColumn.set(info, cr, 2, Util.conky('$uptime'))
|
||||
|
||||
if log_is_changed then
|
||||
TextColumn.set(info, cr, 3, extract_date("sed -n "..
|
||||
"'/ starting full system upgrade/p' /var/log/pacman.log | tail -1"))
|
||||
TextColumn.set(info, cr, 4, extract_date("sed -n "..
|
||||
"'/ synchronizing package lists/p' /var/log/pacman.log | tail -1"))
|
||||
|
||||
if pacman_stats then
|
||||
local last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*")
|
||||
TextColumn.set(info, cr, 3, last_update)
|
||||
TextColumn.set(info, cr, 4, last_sync)
|
||||
end
|
||||
|
||||
|
||||
TextColumn.draw(info, cr)
|
||||
end
|
||||
|
||||
|
|
30
main.lua
30
main.lua
|
@ -172,26 +172,20 @@ local using_ac = function()
|
|||
return Util.read_file('/sys/class/power_supply/AC/online', nil, '*n') == 1
|
||||
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
|
||||
--
|
||||
local updates = -2 -- this accounts for the first few spazzy iterations
|
||||
local __collectgarbage = collectgarbage
|
||||
|
||||
local STATS_FILE = '/tmp/.conky_pacman'
|
||||
|
||||
function conky_main()
|
||||
local _cw = conky_window
|
||||
if not _cw then return end
|
||||
|
||||
-- local time = os.clock()
|
||||
|
||||
local cs = __cairo_xlib_surface_create(_cw.display, _cw.drawable,
|
||||
_cw.visual, 1920, 1080)
|
||||
local cr = __cairo_create(cs)
|
||||
|
@ -203,25 +197,17 @@ function conky_main()
|
|||
|
||||
local t1 = updates % (UPDATE_FREQUENCY * 10)
|
||||
|
||||
local t2
|
||||
local is_using_ac = using_ac()
|
||||
if is_using_ac then
|
||||
t2 = updates % (UPDATE_FREQUENCY * 60)
|
||||
else
|
||||
t2 = updates % (UPDATE_FREQUENCY * 300)
|
||||
end
|
||||
local pacman_stats = Util.read_file(STATS_FILE)
|
||||
|
||||
local log_is_changed = false
|
||||
if t2 == 0 then log_is_changed = check_if_log_changed() end
|
||||
|
||||
System.draw_dynamic(cr, log_is_changed)
|
||||
System.draw_dynamic(cr, pacman_stats)
|
||||
Graphics.draw_dynamic(cr)
|
||||
Processor.draw_dynamic(cr)
|
||||
|
||||
ReadWrite.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)
|
||||
Power.draw_dynamic(cr, UPDATE_FREQUENCY, is_using_ac)
|
||||
Memory.draw_dynamic(cr)
|
||||
|
@ -229,4 +215,6 @@ function conky_main()
|
|||
__cairo_surface_destroy(cs)
|
||||
__cairo_destroy(cr)
|
||||
__collectgarbage()
|
||||
|
||||
-- print(os.clock() - time)
|
||||
end
|
||||
|
|
|
@ -3,14 +3,24 @@
|
|||
stat_file=/tmp/.conky_pacman
|
||||
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() {
|
||||
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)
|
||||
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"
|
||||
echo "$now" "$last_upgrade" "$last_sync" "$tot" "$exp" "$out" \
|
||||
"$orp" "$loc" > "$stat_file"
|
||||
}
|
||||
|
||||
if [[ -f "$stat_file" ]]; then
|
||||
|
|
Loading…
Reference in New Issue