A Python script to efficiently sort desktop wallpapers by resolution and aspect ratio, designed to run in a Podman container for portability and isolation. The project includes a Bash wrapper for simplified execution, supporting dry-run simulations and modern development practices.
- Fast and Efficient: Uses parallel processing with Python's
ThreadPoolExecutorto sort large collections of JPEG files quickly. - Containerized: Runs in a lightweight Podman container based on
python:3.11-slim. - User-Friendly: Bash script (
sort-wallpapers.sh) simplifies execution with intuitive--input,--output, and--dry-runoptions. - Modern Standards: Adheres to PEP 8, Clean Code principles, and includes type hints for maintainability.
- Robust: Handles corrupt files, invalid JPEGs, and permission issues with detailed logging.
- Dry Run Support: Simulate sorting operations without modifying files using the
--dry-runflag.
-
Podman: Required to build and run the container. Install with:
sudo dnf install podman # On Fedora sudo apt install podman # On Ubuntu
-
Bash: For running the
sort-wallpapers.shscript (available on most Linux systems). -
JPEG Files: The script processes
.jpgand.jpegfiles (case-insensitive).
-
Clone the repository:
git clone https://github.com/your-username/wallpaper-sorter.git cd wallpaper-sorter -
Ensure the Bash script is executable:
chmod +x sort-wallpapers.sh
The sort-wallpapers.sh script simplifies running the sorter. It builds the Podman container if needed and processes JPEG files from an input directory, sorting them into an output directory by aspect ratio (e.g., 16x9, 16x10, 4x3) and resolution (e.g., 1920x1080).
-
Dry Run (simulate sorting):
./sort-wallpapers.sh --input /path/to/unsorted --output /path/to/sorted --dry-run
-
Actual Run (sort files):
./sort-wallpapers.sh --input /path/to/unsorted --output /path/to/sorted
To sort wallpapers from /home/stan/Pictures/unsort-wp to /home/stan/Pictures/wallpapers:
./sort-wallpapers.sh --input /home/stan/Pictures/unsort-wp --output /home/stan/Pictures/wallpapersThis creates a structure like:
/home/stan/Pictures/wallpapers/
├── 16x9/
│ ├── 1920x1080/
│ │ ├── image1.jpg
├── 4x3/
│ ├── 1024x768/
│ │ ├── image2.jpg
├── broke_and_unsort/
│ ├── non_jpeg.png
--input <dir>: Directory containing unsorted wallpapers (required).--output <dir>: Directory for sorted wallpapers (required).--dry-run: Simulate operations without moving or deleting files (optional).
-
Python Script (
wallpapers.py):- Reads JPEG headers to determine resolution.
- Classifies images by aspect ratio (
16x9,16x10,4x3, orbroke_and_unsortfor unknown/invalid files). - Moves files to the output directory in parallel for speed.
- Cleans up empty directories in the input path.
-
Bash Wrapper (
sort-wallpapers.sh):- Builds the Podman container if it doesn’t exist.
- Maps local directories to container paths (
/data/wallpapersfor input,/data/sortedfor output). - Passes arguments to the Python script.
-
Podman Container (
Dockerfile):- Uses a lightweight
python:3.11-slimbase image. - Installs minimal dependencies (e.g., Pillow for potential future use).
- Runs the Python script with default paths for simplicity.
- Uses a lightweight
-
Logs: Detailed logs show each file’s movement or errors, e.g.:
2025-05-01 12:00:00,000 - INFO - Starting wallpaper sorting: input=/data/wallpapers, output=/data/sorted, dry_run=False 2025-05-01 12:00:00,100 - INFO - Moved /data/wallpapers/image1.jpg to /data/sorted/16x9/1920x1080 -
Directory Structure: Organized by aspect ratio and resolution, with non-JPEG or invalid files in
broke_and_unsort.
-
Podman Not Found: Install Podman (see Prerequisites).
-
Permission Denied: Ensure read/write permissions:
chmod -R u+rw /path/to/unsorted /path/to/sorted
-
No Files Processed: Verify the input directory contains
.jpgor.jpegfiles. -
Build Fails: Ensure
wallpapers.pyandDockerfileare in the same directory assort-wallpapers.sh.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit changes (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/your-feature). - Open a pull request.
Please ensure code follows PEP 8 and includes tests where applicable.
This project is licensed under the MIT License. See the LICENSE file for details.
For issues or feature requests, open an issue on GitHub or contact [your-username]@example.com.