import re import sys import hashlib from pathlib import Path def clean_string(s): """Remove 'http://' and ':10010' from a string.""" return s.replace('http://', '').replace(':10010', '') def extract_value(pattern, content): match = re.search(pattern, content, re.IGNORECASE | re.DOTALL) return match.group(1) if match else "" def calculate_sha1(file_path): """Calculate SHA1 hash of a file and return uppercase hex digest.""" try: sha1 = hashlib.sha1() with open(file_path, 'rb') as f: while chunk := f.read(65536): sha1.update(chunk) return sha1.hexdigest().upper() except Exception as e: print(f"Error calculating SHA1 for {file_path}: {e}", file=sys.stderr) return "ERROR" def main(): base_dir = Path.cwd() xml_dir = base_dir / "XML" log_path = base_dir / "log_VERSXMLS.txt" if log_path.exists(): log_path.unlink() counter = 0 xml_files = list(xml_dir.rglob("*.XML")) with log_path.open("w", encoding="utf-8") as log: # Add header log.write("CDNPATH\tSCENEVERS\tCHECKVER\tSHA1\n") for xml_path in xml_files: counter += 1 try: content = xml_path.read_text(encoding="utf-8") except Exception as e: print(f"Error reading {xml_path}: {e}") continue cdnpath = clean_string(extract_value(r'urlName="(.*?)"', content)) scenevers = clean_string(extract_value(r'