Files
qt6-migration-pipeline/remove_logger_members.py
T
torstenandCopilot 342ffd3e5c Update submodule to latest BUILD_RTI fixes
- HandlerMinelayerData: BUILD_RTI Guards für RTI-Abhängigkeiten
- svcTabCommon: Export-Header-Fix via Fallback-Target
- TrainingAreaBase: Stub-Header für BUILD_RTI=OFF
- ddsfts: Include-Pfad und Dependency-Fixes
- BUILD_RTI=OFF Compilation vollständig unterstützt

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Entire-Checkpoint: 01M0JNZA586SACX1PRZ2DJAE5S
2026-08-21 19:30:20 +02:00

73 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""
Remove m_logger member variables and adapt LOG macros to use INGLogger::getLogger() directly.
"""
import os
import re
import sys
def process_file(filepath):
"""Process a single file to remove m_logger and adapt macros."""
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
original_content = content
changes_made = False
# Check if file uses LOGGER_T m_logger or NGL::INGLLogger &m_logger
if 'LOGGER_T m_logger' not in content and 'NGL::INGLLogger' not in content and 'm_logger(' not in content:
return False
# Step 1: Remove "LOGGER_T m_logger;" and "NGL::INGLLogger &m_logger;" from class declarations
# Handle lines with optional comments after the member declaration
content = re.sub(r'[ \t]*LOGGER_T\s+m_logger;[^\n]*\n', '\n', content)
content = re.sub(r'[ \t]*NGL::INGLLogger\s*&\s*m_logger;[^\n]*\n', '\n', content)
content = re.sub(r'[ \t]*NGL::INGLLogger\s+m_logger;[^\n]*\n', '\n', content)
# Step 2: Remove ", m_logger(getLogger(...))" from constructor initializer lists
content = re.sub(r'\s*,\s*m_logger\s*\(\s*getLogger\s*\(\s*"[^"]*"\s*\)\s*\)', '', content)
# Step 3: Replace LOG macros that use m_logger with direct getLogger() call
# TRACE_LOG(m_logger) -> TRACE_LOG()
content = re.sub(r'TRACE_LOG\s*\(\s*m_logger\s*\)', 'TRACE_LOG()', content)
content = re.sub(r'DEBUG_LOG\s*\(\s*m_logger\s*\)', 'DEBUG_LOG()', content)
content = re.sub(r'INFO_LOG\s*\(\s*m_logger\s*\)', 'INFO_LOG()', content)
content = re.sub(r'WARNING_LOG\s*\(\s*m_logger\s*\)', 'WARNING_LOG()', content)
content = re.sub(r'ERROR_LOG\s*\(\s*m_logger\s*\)', 'ERROR_LOG()', content)
content = re.sub(r'LOGFUNCTION', 'Q_FUNC_INFO', content)
if content != original_content:
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
return True
return False
def main():
if len(sys.argv) < 2:
print("Usage: remove_logger_members.py <directory>")
sys.exit(1)
base_dir = sys.argv[1]
processed = 0
changed = 0
for root, dirs, files in os.walk(base_dir):
# Skip build directories
if 'build' in root or '.git' in root:
continue
for file in files:
if file.endswith(('.h', '.cpp', '.hpp', '.cc')):
filepath = os.path.join(root, file)
processed += 1
if process_file(filepath):
changed += 1
print(f"Modified: {filepath}")
print(f"\nProcessed {processed} files, modified {changed} files")
if __name__ == '__main__':
main()