Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Path to the Python virtual environment's Python executable (adjust if needed)
- PYTHON_EXEC="python"
- # Path to the code_context.py script (relative to the script's location)
- SCRIPT_PATH="./code_context.py" # Assuming script and code_context.py are in the same directory
- # Directory to process (passed as first argument)
- TARGET_DIRECTORY="$1"
- # Output file
- OUTPUT_FILE="output.txt"
- # Define folders and files to exclude
- EXCLUDES=(
- "venv/" # Exclude virtual environment directory
- ".git/" # Exclude Git metadata
- "__pycache__/" # Exclude Python cache files
- "build/" # Exclude build artifacts
- "dist/" # Exclude distribution artifacts
- "*.egg-info/" # Exclude package metadata
- ".idea/" # Exclude IDE metadata
- ".vscode/" # Exclude VSCode metadata
- "*.swp" # Exclude temporary files
- "*.swo" # Exclude temporary files
- ".DS_Store" # Exclude macOS system file
- )
- # Create the `rsync`-compatible exclude list
- EXCLUDE_PARAMS=()
- for EXCLUDE in "${EXCLUDES[@]}"; do
- EXCLUDE_PARAMS+=(--exclude="$EXCLUDE")
- done
- # Use rsync to copy only relevant files into a filtered directory
- FILTERED_DIR="./filtered_directory"
- mkdir -p "$FILTERED_DIR"
- echo "Filtering files into $FILTERED_DIR..."
- rsync -a "${EXCLUDE_PARAMS[@]}" --include="*/" --include="*.py" --exclude="*" "$TARGET_DIRECTORY" "$FILTERED_DIR"
- # Run the Python script to combine files in the filtered directory
- echo "Running Python script..."
- $PYTHON_EXEC $SCRIPT_PATH "$FILTERED_DIR" -o "$OUTPUT_FILE"
- # Notify user
- if [ $? -eq 0 ]; then
- echo "Context generated successfully. Output saved to $OUTPUT_FILE."
- else
- echo "Failed to generate context. Please check for errors."
- fi
- # Cleanup
- rm -rf "$FILTERED_DIR"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement