import sys import os def standardize_file(file_path): try: with open(file_path, 'r', encoding='utf-8') as f: lines = f.readlines() except Exception as e: print(f"Error reading {file_path}: {e}") return new_lines = [] for line in lines: stripped = line.lstrip(' ') space_count = len(line) - len(stripped) if space_count > 0 and space_count % 4 == 0: new_space_count = space_count // 4 new_lines.append(' ' * new_space_count + stripped) else: new_lines.append(line) try: with open(file_path, 'w', encoding='utf-8') as f: f.writelines(new_lines) print(f"Standardized {file_path}") except Exception as e: print(f"Error writing {file_path}: {e}") if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python scripts/standardize_indent.py ...") sys.exit(1) for path in sys.argv[1:]: if os.path.isfile(path): standardize_file(path) else: print(f"Skipping {path}: Not a file")