updates+uptimes: Add --hist and --osnames options.

Signed-off-by: James Antill <james@and.org>
This commit is contained in:
James Antill
2025-12-26 13:12:25 -05:00
parent c127602949
commit 982818878e

View File

@@ -993,11 +993,11 @@ def _usage(short=False):
hosts/-u [host*] [host*]...
info [host*] [backup] [backup]...
list [host*] [backup] [host*]...
list-n [host*] [host*]...
list [host*]...
old-list duration
oslist [os*] [backup] [os*]...
oslist-n [os*] [os*]...
stats [backup] [host*] [host*]...
oslist [os*]...
stats [host*]...
update
update-host host
uptime/-min/-max duration [backup]
@@ -1011,24 +1011,28 @@ def _usage(short=False):
= Shows before/after instead of modified (like diff -u).
history
--osnames os*
= Show summary of current data, and how it changed over time.
history-keep [days]
= Cleanup old history.
hosts/-u [host*] [host*]...
--osnames os*
= See the history of a host(s).
info [host*] [backup] [backup]...
= See the current state, in long form, can be filtered by name.
list [host*] [backup] [host*]...
list-n [host*] [host*]...
list [host*]...
--hist backup
--osnames os*
= See the current state, can be filtered by name.
old-list duration
= See the current state of hosts with data older than duration.
oslist [os*] [backup] [os*]...
oslist-n [os*] [os*]...
oslist [os*]...
--hist backup
= See the current state, can be filtered by OS.
stats [backup] [host*] [host*]...
stats [host*]...
--hist backup
= Show general stats.
update
@@ -1183,6 +1187,8 @@ def _cmd_history(args):
last_name = "main"
last_data = list(sorted(fname_datas()))
last_data = list(filter_name_datas(last_data, args.hosts))
last_data = list(filter_osname_datas(last_data, args.osnames))
last_suff = ""
hl, ul, rl = _hist_lengths()
@@ -1197,6 +1203,8 @@ def _cmd_history(args):
for backup in reversed(backups):
data = list(sorted(lines2datas(bfname2lines(backup))))
data = list(filter_name_datas(data, args.hosts))
data = list(filter_osname_datas(data, args.osnames))
updates = sum(d.rpms for d in last_data)
less_updates = False
if updates < sum(d.rpms for d in data):
@@ -1554,7 +1562,7 @@ def _cmd_uptime(args):
age = args.dur
data = fname1()
if cmd == "uptime-max":
if cmd == "uptime-max" or cmd in _cmds_als["uptime-max"]:
data = list(filter_uptime_max_datas(data, age))
else:
data = list(filter_uptime_min_datas(data, age))
@@ -1712,6 +1720,8 @@ def _cmd_diff(args):
data1 = list(sorted(data1))
data2 = list(sorted(data2))
hosts = _ui_int(len(data2))
data1 = list(filter_osname_datas(data1, args.osnames))
data2 = list(filter_osname_datas(data2, args.osnames))
updates = _ui_int(sum(d.rpms for d in data2))
ul = len(updates)
cmpds = _ui_diffstats(data1, data2)
@@ -1719,7 +1729,8 @@ def _cmd_diff(args):
_max_update(data2)
_max_update_correct(' ')
_diff_hosts(data1, data2, show_both=cmd == "diff-u", show_utf8=cmd == "diff")
_cmdn_du = cmd in ("difference-u", "diff-u")
_diff_hosts(data1, data2, show_both=_cmdn_du, show_utf8=not _cmdn_du)
_print_diffstats(hosts, updates, cmpds)
_explain_ui_name()
@@ -1735,6 +1746,7 @@ def _cmd_host(args):
print("Hosts history:")
last_name = "main"
last_data = list(sorted(filter_name_datas(fname_datas(), hosts)))
last_data = list(filter_osname_datas(last_data, args.osnames))
hbackups = list(reversed(backups))
if len(hbackups) > 1 and _backup_today_identical():
@@ -1745,6 +1757,7 @@ def _cmd_host(args):
for backup in hbackups:
data = filter_name_datas(lines2datas(bfname2lines(backup)), hosts)
data = list(sorted(data))
data = list(filter_osname_datas(data, args.osnames))
_max_update(data)
_max_update_correct(' ')
@@ -1758,6 +1771,7 @@ def _cmd_host(args):
for backup in hbackups:
data = filter_name_datas(lines2datas(bfname2lines(backup)), hosts)
data = list(sorted(data))
data = list(filter_osname_datas(data, args.osnames))
if done and skipped_num < 1:
print("")
@@ -1857,16 +1871,14 @@ def _cmdline_arg_hist(oval):
_cmds_als = {
"created" : ["installed", "reinstalled"],
"difference" : ("diff", "diff-u"),
"difference" : ("diff", "diff-u", "difference-u"),
"history-keep" : [],
"history" : ["hist"],
"hosts" : ("host", "host-u", "hosts-u"),
"information" : ["info"],
"list" : [],
"list-n" : [],
"list" : ["list-n"],
"old-list" : ["olist"],
"oslist" : [],
"oslist-n" : [],
"oslist" : ["oslist-n"],
"statistics" : ["stats"],
"update" : [],
"update-daily" : [],
@@ -1922,6 +1934,7 @@ forever.
elif _eq_cmd("difference"):
print(f"""\
Usage: {prog} {args.hcmd} [backup1] [backup2]
{' '*len(prog)} {' '*len(args.hcmd)} --osnames os*
See the difference between the current state and backups.
The -u variant shows before/after instead of modified.
@@ -1937,12 +1950,13 @@ utf8: {conf_utf8}
{_hlp_als("difference")}
Eg. {prog} {args.hcmd}
{prog} {args.hcmd} yesterday
{prog} {args.hcmd} 2025-08-16 main
{prog} {args.hcmd} --osnames 42 2025-08-16 main
""", end='')
elif _eq_cmd("history"):
print(f"""\
Usage: {prog} {args.hcmd}
{' '*len(prog)} {' '*len(args.hcmd)} --osnames os*
Show summary of current data, and how it changed over time.
@@ -1970,6 +1984,7 @@ if you pass "1".
elif _eq_cmd("hosts"):
print(f"""\
Usage: {prog} {args.hcmd}
{' '*len(prog)} {' '*len(args.hcmd)} --osnames os*
See the history of a host(s). A cross between looking at diff and history.
The -u variants show before/after instead of modified.
@@ -2007,31 +2022,23 @@ utf8: {conf_utf8}
elif _eq_cmd("list"):
print(f"""\
Usage: {prog} {args.hcmd} [host*] [backup] [host*]...
Usage: {prog} {args.hcmd} [host*] [host*]...
{' '*len(prog)} {' '*len(args.hcmd)} --hist backup
{' '*len(prog)} {' '*len(args.hcmd)} --osnames os*
See the current state of the hosts, can be filtered by name.
{_hlp_als("list")}
Eg. {prog} {args.hcmd}
{prog} {args.hcmd} 'batcave*'
{prog} {args.hcmd} 'noc*' yesterday '*-test.*'
""", end='')
elif _eq_cmd("list-n"):
print(f"""\
Usage: {prog} {args.hcmd} [host*] [host*]...
See the current state of the hosts, can be filtered by name.
{_hlp_als("list-n")}
Eg. {prog} {args.hcmd}
{prog} {args.hcmd} 'batcave*'
{prog} {args.hcmd} 'batcave*' 'noc*'
{prog} {args.hcmd} --osnames '4?' '*stg*' '*test*'
""", end='')
elif _eq_cmd("old-list"):
print(f"""\
Usage: {prog} {args.hcmd} duration
{' '*len(prog)} {' '*len(args.hcmd)} --osnames os*
See the current state of hosts, with data older than duration.
@@ -2039,35 +2046,27 @@ utf8: {conf_utf8}
{_hlp_als("old-list")}
Eg. {prog} {args.hcmd} 2d
{prog} {args.hcmd} --osnames 42 2d
""", end='')
elif _eq_cmd("oslist"):
print(f"""\
Usage: {prog} {args.hcmd} [os*] [backup] [os*]...
Usage: {prog} {args.hcmd} [os*] [os*]...
{' '*len(prog)} {' '*len(args.hcmd)} --hist backup
See the current state, can be filtered by OS.
{_hlp_als("oslist")}
Eg. {prog} {args.hcmd}
{prog} {args.hcmd} RedHat
{prog} {args.hcmd} 10 yesterday 41
""", end='')
elif _eq_cmd("oslist-n"):
print(f"""\
Usage: {prog} {args.hcmd} [os*] [os*]...
See the current state, can be filtered by OS.
{_hlp_als("oslist-n")}
Eg. {prog} {args.hcmd}
{prog} {args.hcmd} RedHat
{prog} {args.hcmd} F 10
{prog} {args.hcmd} 10 --hist yesterday 41
""", end='')
elif _eq_cmd("statistics"):
print(f"""\
Usage: {prog} {args.hcmd} [backup] [host*] [host*]...
{' '*len(prog)} {' '*len(args.hcmd)} --hist backup
Show general statistics.
@@ -2075,8 +2074,8 @@ utf8: {conf_utf8}
{_hlp_als("statistics")}
Eg. {prog} {args.hcmd}
{prog} {args.hcmd} yesterday
{prog} {args.hcmd} newest '*.stg.*' '*-test.*'
{prog} {args.hcmd} --host yesterday
{prog} {args.hcmd} '*.stg.*' '*-test.*'
""", end='')
elif _eq_cmd("update"):
@@ -2227,6 +2226,7 @@ def _main():
# diff/diff-u commands
als = _cmds_als["difference"]
cmd = subparsers.add_parser("difference", aliases=als, help="diff")
cmd.add_argument("--osnames", action='append', default=[], help="wildcard OSname(s)")
cmd.add_argument("hists", nargs='*', type=_cmdline_arg_hist, help="history file")
__defs(func=_cmd_diff)
@@ -2234,12 +2234,15 @@ def _main():
als = _cmds_als["hosts"]
hlp = "show history data about specific hosts"
cmd = subparsers.add_parser("hosts", aliases=als, help=hlp)
cmd.add_argument("--osnames", action='append', default=[], help="wildcard OSname(s)")
cmd.add_argument("hosts", nargs='*', help="wildcard hostname(s)")
__defs(func=_cmd_host)
# history command
als = _cmds_als["history"]
cmd = subparsers.add_parser("history", aliases=als, help="show history")
cmd.add_argument("--osnames", action='append', default=[], help="wildcard OSname(s)")
cmd.add_argument("hosts", nargs='*', help="wildcard hostname(s)")
__defs(func=_cmd_history)
# history-keep command
@@ -2260,38 +2263,30 @@ def _main():
# list/list-n/old-list/olist/oslist/oslist-n commands
cmd = subparsers.add_parser("list", help="list hosts")
cmd.add_argument("host", nargs='?', help="wildcard hostname")
cmd.add_argument("hists", nargs='?',
cmd.add_argument("--osnames", action='append', default=[], help="wildcard OSname(s)")
cmd.add_argument("--hist",
type=_cmdline_arg_hist, help="history file")
cmd.add_argument("hosts", nargs='*', help="wildcard hostname(s)")
__defs(func=_cmd_list)
cmd = subparsers.add_parser("list-n", help="list hosts")
cmd.add_argument("hosts", nargs='*', help="wildcard hostname(s)")
__defs(func=_cmd_list)
als = _cmds_als["old-list"]
cmd = subparsers.add_parser("old-list", aliases=als, help="list hosts")
cmd.add_argument("--osnames", action='append', default=[], help="wildcard OSname(s)")
cmd.add_argument("dateage", type=_cmdline_arg_duration,
help="data age minimum duration")
__defs(func=_cmd_list)
cmd = subparsers.add_parser("oslist", help="list hosts")
cmd.add_argument("osname", nargs='?', help="wildcard OSname")
cmd.add_argument("hists", nargs='?',
cmd.add_argument("--hist",
type=_cmdline_arg_hist, help="history file")
cmd.add_argument("osnames", nargs='*', help="wildcard OSname(s)")
__defs(func=_cmd_list)
cmd = subparsers.add_parser("oslist-n", help="list hosts")
cmd.add_argument("osnames", nargs='*', help="wildcard OSname(s)")
__defs(func=_cmd_list)
# stats commands
hlp = "show stats information"
cmd = subparsers.add_parser("statistics", aliases=['stats'], help=hlp)
cmd.add_argument("hist", nargs='?', type=_cmdline_arg_hist, default="main",
help="history file")
cmd.add_argument("--hist", type=_cmdline_arg_hist, default="main",
help="history file")
cmd.add_argument("hosts", nargs='*', help="wildcard hostname(s)")
__defs(func=_cmd_stats)