1
0
Fork 0
forked from infra/ansible

updates-uptimes: Add update-daily-refresh. Tweak terminal UI.

Signed-off-by: James Antill <james@and.org>
This commit is contained in:
James Antill 2025-08-08 16:20:34 -04:00
commit 9f3ece551e

View file

@ -30,6 +30,7 @@ import sys
import fnmatch
import glob
import shutil
import time
# If we try to update this seconds since the file changed, flush the
@ -63,7 +64,7 @@ if len(sys.argv) >= 2:
cmd = "diff"
if len(sys.argv) >= 2:
if sys.argv[1] in ("backups", "backups-keep", "diff", "diff-u", "help", "host", "info", "list", "stats", "update", "update-fast", "update-flush", "update-daily", "uptime",):
if sys.argv[1] in ("backups", "backups-keep", "diff", "diff-u", "help", "host", "info", "list", "stats", "update", "update-fast", "update-flush", "update-daily", "update-daily-refresh", "uptime",):
cmd = sys.argv.pop(1)
_tm_d = {'d' : 60*60*24, 'h' : 60*60, 'm' : 60, 's' : 1,
@ -156,7 +157,7 @@ def line2data(line):
osinfo_small = 'F/' + osvers
# This is the primary key for diff.
updates = name + ' ' + rpms
update_info = name + ' ' + rpms + ' ' + osinfo
rpms = int(rpms)
uptime = int(uptime)
@ -178,9 +179,15 @@ def _reset_ui_name():
# Explain if we used any suffix subs.
def _explain_ui_name():
done = False
pre = "* NOTE:"
for suffix in sorted(_suffix_dns_replace):
if _suffix_dns_replace[suffix]:
print("* NOTE: %12s = %s" %(conf_suffix_dns_replace[suffix],suffix))
print("%s %12s = %s" % (pre,conf_suffix_dns_replace[suffix],suffix))
pre = " :"
done = True
if done:
print(" : Use -v to show full names.")
def fname2lines(fname):
return [x.strip() for x in open(fname).readlines()]
@ -197,7 +204,7 @@ _max_len_name = 0
_max_len_rpms = 0
_max_len_updur = 0
_max_len_date = 0 # 4+1+2+1+2
_max_terminal_width = os.get_terminal_size().columns
_max_terminal_width = shutil.get_terminal_size().columns
if _max_terminal_width < 20:
_max_terminal_width = 80
_max_terminal_width -= 10
@ -263,6 +270,8 @@ def _usage():
= Create the file, after flushing ansible caches.
update-daily
= update-flush and do backups.
update-daily-refresh
= update-daily with new main file.
uptime [duration] [backup]
= See the current state, can be filtered for uptime >= duration.
@ -285,7 +294,7 @@ if cmd == "backups-keep":
sys.exit(1)
while keep < len(backups):
# We just keep the newest N
fn = fname + '.' + backups.pop()
fn = fname + '.' + backups.pop(0)
os.unlink(fn)
if cmd == "update":
@ -305,6 +314,10 @@ if cmd == "update-flush": # Get the latest uptime.
if cmd == "update-fast": # Use ansible FACT cache for uptime.
os.chdir("/srv/web/infra/ansible/playbooks")
os.system("ansible-playbook generate-updates-uptimes-per-host-file.yml -t updates")
if cmd == "update-daily-refresh": # Also recreate the main file.
if os.path.exists(fname):
os.unlink(fname)
cmd = "update-daily"
if cmd == "update-daily": # Also create backup file.
os.chdir("/srv/web/infra/ansible/playbooks")
os.system("ansible-playbook generate-updates-uptimes-per-host-file.yml --flush-cache")
@ -497,7 +510,7 @@ if cmd in ("diff", "diff-u"):
data2.pop(0)
continue
if d1['updates'] == d2['updates']:
if d1['update_info'] == d2['update_info']:
_print_line(' ', d2)
data1.pop(0)
data2.pop(0)