|
import sys |
|
from pathlib import Path |
|
from config.settings import Settings |
|
from core.git_manager import GitManager |
|
from core.file_scanner import FileScanner |
|
from utils.file_writer import FileWriter |
|
|
|
def main(): |
|
|
|
if len(sys.argv) != 2: |
|
print("Usage: python main.py <github_url or directory_path>") |
|
return 1 |
|
|
|
target_path = sys.argv[1] |
|
timestamp = Settings.get_timestamp() |
|
output_file = Settings.get_output_file(timestamp) |
|
|
|
|
|
is_github = target_path.startswith(('http://', 'https://')) and 'github.com' in target_path |
|
|
|
try: |
|
if is_github: |
|
|
|
clone_dir = Settings.get_clone_dir(timestamp) |
|
print(f"Cloning repository: {target_path}") |
|
|
|
git_manager = GitManager(target_path, clone_dir) |
|
git_manager.clone_repository() |
|
|
|
scanner = FileScanner(clone_dir) |
|
cleanup_needed = True |
|
else: |
|
|
|
target_dir = Path(target_path) |
|
if not target_dir.exists(): |
|
print(f"Error: Directory not found: {target_dir}") |
|
return 1 |
|
|
|
scanner = FileScanner(target_dir) |
|
cleanup_needed = False |
|
|
|
|
|
print("Scanning files...") |
|
files = scanner.scan_files() |
|
|
|
print(f"Writing contents to {output_file}") |
|
writer = FileWriter(output_file) |
|
writer.write_contents(files) |
|
|
|
print(f"Found {len(files)} files") |
|
print(f"Results saved to {output_file}") |
|
|
|
except Exception as e: |
|
print(f"Error: {e}") |
|
return 1 |
|
|
|
finally: |
|
|
|
if is_github and cleanup_needed and 'git_manager' in locals(): |
|
try: |
|
git_manager.cleanup() |
|
print("Cleanup completed") |
|
except Exception as e: |
|
print(f"Cleanup error: {e}") |
|
|
|
return 0 |
|
|
|
if __name__ == "__main__": |
|
exit(main()) |