diff options
author | Grigory Bazilevich <g.bazilevich@ispras.ru> | 2025-03-05 12:57:52 +0300 |
---|---|---|
committer | Grigory Bazilevich <g.bazilevich@ispras.ru> | 2025-03-05 12:57:52 +0300 |
commit | 10883847b5ebcb37d3299f712ac2a8a8cc307e5a (patch) | |
tree | d678f8c84d27b8321fcfe000d771e945de1456ce | |
parent | 2d17b7ae38ed640417e9c5f5fe7db4b4dde45e03 (diff) |
feat: short diff report in csv format
-rw-r--r-- | main.py | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -50,6 +50,8 @@ def manager_write_state(mgr, method, new_state): file = os.path.join(dir, f"{method}.state") if not os.path.exists(file): os.close(os.open(file, os.O_CREAT)) + with open(os.path.join(dir, f"{method}.diff"), "w") as f: + f.write("time,not_changed,new,removed\n") old_state = [] with open(file, "r") as f: @@ -63,15 +65,9 @@ def manager_write_state(mgr, method, new_state): file = os.path.join(dir, f"{method}.diff") time = datetime.now().isoformat() with open(file, "a") as f: - f.write("Time: {}\n\n".format(time)) - if len(diff["not_changed"]) != 0: - f.write("Not changed: {}\n".format(len(diff["not_changed"]))) - if len(diff["new"]) != 0: - f.write("New: {}\n".format(len(diff["new"]))) - if len(diff["removed"]) != 0: - f.write("Removed: {}\n".format(len(diff["removed"]))) - - f.write("===\n") + f.write( + f"{time},{len(diff['not_changed'])},{len(diff['new'])},{len(diff['removed'])}\n" + ) file = f"{file}.detail" with open(file, "a") as f: @@ -148,7 +144,9 @@ def main(): try: data = do_get(manager["http_url"], endpoint["http_uri"]) except Exception as e: - print(f"Failed to get information from manager {manager['name']} using endpoint {endpoint['name']}") + print( + f"Failed to get information from manager {manager['name']} using endpoint {endpoint['name']}" + ) print(e) continue @@ -159,13 +157,17 @@ def main(): data = parse_crashes(manager["name"], data) state = data.split("\n") except: - print(f"Failed to parse information from manager {manager['name']}, endpoint: {endpoint['name']}") + print( + f"Failed to parse information from manager {manager['name']}, endpoint: {endpoint['name']}" + ) continue try: manager_write_state(manager["name"], endpoint["name"], state) except: - print(f"Failed to log manager {manager['name']} state, endpoint: {endpoint['name']}") + print( + f"Failed to log manager {manager['name']} state, endpoint: {endpoint['name']}" + ) continue time.sleep(config["timeout"]) |