Initial commit - cleaned repository
This commit is contained in:
62
services/pipeline/fix_imports.py
Normal file
62
services/pipeline/fix_imports.py
Normal file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fix import statements in all pipeline services"""
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
def fix_imports(filepath):
|
||||
"""Fix import statements in a Python file"""
|
||||
with open(filepath, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Pattern to match the old import style
|
||||
old_pattern = r"# 상위 디렉토리의 shared 모듈 import\nsys\.path\.append\(os\.path\.join\(os\.path\.dirname\(__file__\), '\.\.', 'shared'\)\)\nfrom ([\w, ]+) import ([\w, ]+)"
|
||||
|
||||
# Replace with new import style
|
||||
def replace_imports(match):
|
||||
modules = match.group(1)
|
||||
items = match.group(2)
|
||||
|
||||
# Build new import statements
|
||||
imports = []
|
||||
if 'models' in modules:
|
||||
imports.append(f"from shared.models import {items}" if 'models' in modules else "")
|
||||
if 'queue_manager' in modules:
|
||||
imports.append(f"from shared.queue_manager import QueueManager")
|
||||
|
||||
return "# Import from shared module\n" + "\n".join(filter(None, imports))
|
||||
|
||||
# Apply the replacement
|
||||
new_content = re.sub(old_pattern, replace_imports, content)
|
||||
|
||||
# Also handle simpler patterns
|
||||
new_content = new_content.replace(
|
||||
"sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'shared'))\nfrom models import",
|
||||
"from shared.models import"
|
||||
)
|
||||
new_content = new_content.replace(
|
||||
"\nfrom queue_manager import",
|
||||
"\nfrom shared.queue_manager import"
|
||||
)
|
||||
|
||||
# Write back if changed
|
||||
if new_content != content:
|
||||
with open(filepath, 'w') as f:
|
||||
f.write(new_content)
|
||||
print(f"Fixed imports in {filepath}")
|
||||
return True
|
||||
return False
|
||||
|
||||
# Files to fix
|
||||
files_to_fix = [
|
||||
"monitor/monitor.py",
|
||||
"google-search/google_search.py",
|
||||
"article-assembly/article_assembly.py",
|
||||
"rss-collector/rss_collector.py",
|
||||
"ai-summarizer/ai_summarizer.py"
|
||||
]
|
||||
|
||||
for file_path in files_to_fix:
|
||||
full_path = os.path.join(os.path.dirname(__file__), file_path)
|
||||
if os.path.exists(full_path):
|
||||
fix_imports(full_path)
|
||||
Reference in New Issue
Block a user