#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import hashlib import posixpath import unicodedata import pymysql import time # ========================= # CONFIG # ========================= HOST_TO_CHECK = "Tower" WINDOWS_UNC_BASE = r"\\tower" DB_CONFIG = { "host": "192.168.1.50", "port": 3306, "user": "root", "password": "Vlado9674+", "database": "torrents", "charset": "utf8mb4", } PRINT_FIRST_CHANGES = 20 LOG_EVERY = 5000 # ========================= # CANONICAL # ========================= def canonical_path(path_str): path_str = path_str.replace("\\", "/") path_str = posixpath.normpath(path_str) path_str = unicodedata.normalize("NFC", path_str) return path_str def md5_bytes(path_str): return hashlib.md5(path_str.encode("utf-8")).digest() # ========================= # PATH MAP # ========================= def linux_to_windows_unc(linux_path): rel = linux_path[len("/mnt/user/"):] return os.path.join(WINDOWS_UNC_BASE, *rel.split("/")) # ========================= # MAIN # ========================= def main(): print("=" * 70) print("šŸ” Tower Canonical Path SMB Verification") print(f"Host: {HOST_TO_CHECK}") print(f"UNC Base: {WINDOWS_UNC_BASE}") print("=" * 70) db = pymysql.connect(**DB_CONFIG) cur = db.cursor(pymysql.cursors.SSCursor) cur.execute(""" SELECT id, full_path, path_hash FROM file_md5_index WHERE host_name = %s """, (HOST_TO_CHECK,)) total = 0 needs_change = 0 exists_ok = 0 missing = 0 printed_changes = 0 start = time.time() for rec_id, full_path, stored_hash in cur: total += 1 new_path = canonical_path(full_path) new_hash = md5_bytes(new_path) # Already canonical if new_path == full_path and new_hash == stored_hash: continue needs_change += 1 win_path = linux_to_windows_unc(new_path) exists = os.path.exists(win_path) if exists: exists_ok += 1 else: missing += 1 # ---- Print first examples ---- if printed_changes < PRINT_FIRST_CHANGES: print("\nšŸ”§ CHANGE DETECTED") print(f"ID : {rec_id}") print(f"DB PATH : {full_path}") print(f"NEW PATH : {new_path}") print(f"WIN PATH : {win_path}") print(f"Exists : {exists}") printed_changes += 1 # ---- Progress ---- if total % LOG_EVERY == 0: elapsed = time.time() - start rate = total / elapsed if elapsed else 0 print( f"šŸ“Š Checked {total:,} rows | " f"Needs change {needs_change:,} | " f"Exists {exists_ok:,} | " f"Missing {missing:,} | " f"{rate:,.0f} rows/sec" ) # ========================= # SUMMARY # ========================= elapsed = time.time() - start print("\n" + "=" * 70) print("āœ… FINAL SUMMARY") print("=" * 70) print(f"Total scanned : {total:,}") print(f"Needs change : {needs_change:,}") print(f"Exists on Tower : {exists_ok:,}") print(f"Missing on Tower : {missing:,}") print(f"Runtime : {elapsed:.1f}s") print("=" * 70) cur.close() db.close() if __name__ == "__main__": main()