"""Windows command tables against SPEC section 3 / 6 (character for character) + ASCII check.""" import re, sys sys.dont_write_bytecode = True sys.path.insert(0, sys.argv[1]) import plat, model spec = open(sys.argv[2], encoding='utf-8').read() ticks = spec.replace('\\|', '|') ok = True def has(name, s): global ok good = ('`' + s + '`') in ticks or s in ticks and len(s) > 40 ok &= good print(('ok ' if good else 'DIFF ') + name + ('' if good else f'\n {s}')) for k, v in plat.CMD.items(): has('CMD ' + k, v) has('cleanup', plat.CLEANUP) for k, v in plat.POWER.items(): has('power ' + k, v) for label, cmd, flags in plat.PROC_ACTIONS: has('proc ' + label, cmd) for k, v in plat.PRIORITIES.items(): has('priority ' + k, plat.PRIORITY_CMD.replace('{v}', str(v)).replace('{v}', '') if False else plat.PRIORITY_CMD.replace('{v}', '')) for k, v in plat.SERVICE_VERBS.items(): has('service ' + k, v) has('service logs', plat.SERVICE_LOGS) for label, cmd in plat.QUICK: has('quick ' + label, cmd) for label, cmd in plat.ACTIONS: has('action ' + label, cmd) has('PS_ARGS', ' '.join(plat.PS_ARGS).split(' -EncodedCommand ')[1]) print('labels quick:', [l for l, _ in plat.QUICK]); print('labels actions:', [l for l, _ in plat.ACTIONS]) print('rule actions:', [a[0] for a in model.RULE_ACTIONS]); print('rule metrics:', [m[0] for m in model.RULE_METRICS]) w = plat.wrap('CMD', True, True) print('wrap ok:', w.replace('CMD', '').strip() in spec) texts = [plat.COLLECTOR, plat.CLEANUP, plat.SERVICE_LOGS, plat.PRIORITY_CMD, w, plat.collector(3)] + list(plat.CMD.values()) + list(plat.POWER.values()) + [c for _, c in plat.QUICK + plat.ACTIONS] + [c for _, c, _ in plat.PROC_ACTIONS] + list(plat.SERVICE_VERBS.values()) print('all scripts ASCII:', all(t.isascii() for t in texts)) print('collector stdin starts:', repr(plat.collector(3)[:34])) print('filled:', model.command(plat.SERVICE_LOGS, "MSSQL$SQL'X", 300)[:120]); print('filled:', model.command(plat.CMD['restart_service'], "it's")); print('filled:', model.command(plat.CMD['kill_pid'], '1234; rm x')) print('ALL MATCH' if ok else 'MISMATCHES')