Development Guide¶
This guide covers development setup, testing procedures, debugging techniques, and troubleshooting for qbit-guard.
Development Setup¶
Prerequisites¶
- Python 3.8+ with standard library
- Docker and Docker Compose for testing
- qBittorrent instance for testing (can be containerized)
- Access to Sonarr/Radarr instances (optional, for integration testing)
Local Development¶
Clone the repository:
Set up environment variables for testing:
Run the script directly:
Or test the watcher:
Container Development¶
Build local image:
Bash Test with docker-compose:
Testing Procedures¶
Unit Testing¶
The project uses Python's built-in testing capabilities:
Bash | |
---|---|
Integration Testing¶
Test qBittorrent Connection:
Test with Dry Run:
Bash Test Pre-air Checking:
Bash
Manual Testing Scenarios¶
- Add a test torrent in qBittorrent with correct category
- Monitor logs for processing behavior
- Test different categories and configuration combinations
- Simulate network issues by using unreachable service URLs
Debugging Techniques¶
Enable Debug Logging¶
Bash | |
---|---|
Debug mode provides detailed information about: - HTTP request/response details - Sonarr/Radarr API communication - File analysis decisions
- Whitelist matching logic - Metadata fetch progress
Key Log Indicators¶
Monitor these log messages:
Success Indicators: - ✅ qB: login OK
- qBittorrent authentication successful - ✅ Started torrent ... after checks
- Normal processing completed - ✅ Torrent allowed
- Torrent passed all checks
Expected Behavior: - ⚠️ Pre-air: BLOCK
- Pre-air blocking working correctly - ⚠️ ISO cleanup: removing
- Disc image cleanup working
Error Indicators: - ❌ Unhandled error
- Configuration or connectivity issue - ❌ qB: login failed
- Authentication problem - ❌ Timeout
- Network connectivity issues
Network Debugging¶
Test API connectivity from the container:
Check DNS resolution:
Verify network connectivity:
Common Development Issues¶
Environment Variable Issues¶
Problem: Variables not being read
Solution: Ensure variables are properly set in docker-compose.yml or environment
qBittorrent Connection Issues¶
Problem: Cannot connect to qBittorrent - Verify QBIT_HOST
is accessible from qbit-guard container - Check qBittorrent WebUI is enabled - Confirm username/password are correct - Test with curl
from inside the container
API Timeout Issues¶
Problem: Sonarr/Radarr API calls timing out - Increase timeout values: SONARR_TIMEOUT_SEC=90
- Use direct container IPs instead of service names - Avoid routing through reverse proxies for API calls - Check network latency between containers
Metadata Fetch Issues¶
Problem: Magnet metadata never loads - Check qBittorrent logs for tracker/DHT issues - Increase METADATA_MAX_WAIT_SEC
or set to 0 for infinite wait - Verify magnet has sufficient seeds/peers - Try reducing METADATA_POLL_INTERVAL
to 0.5 for faster checking
Performance Optimization¶
Resource Limits¶
For production deployments, set appropriate resource limits:
YAML | |
---|---|
Polling Optimization¶
Reduce polling frequency for lower resource usage:
Bash | |
---|---|
Optimize metadata fetching:
Bash | |
---|---|
Contributing Guidelines¶
Code Style¶
- Follow Python PEP 8 style guidelines
- Use meaningful variable names
- Add comments for complex logic
- Keep functions focused and small
Documentation¶
- Update this guide when adding new features
- Include examples in configuration changes
- Document new environment variables
- Update README.md if adding major features
Testing¶
- Test with
QBIT_DRY_RUN=1
first - Verify both container and script modes work
- Test with different qBittorrent versions (4.x and 5.x)
- Test network failure scenarios
Pull Request Process¶
- Test thoroughly with dry-run mode
- Update documentation for any new features
- Include example configurations for new variables
- Test both deployment modes (container and script)
Troubleshooting Development Issues¶
Container Won't Start¶
Bash | |
---|---|
Script Execution Issues¶
Bash | |
---|---|
API Authentication Issues¶
Bash | |
---|---|
Next Steps¶
- Configuration Guide → - Detailed setup instructions
- Troubleshooting → - Production troubleshooting guide
- Examples → - Working development configurations