Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial version #1

Merged
merged 21 commits into from
Oct 16, 2023
51 changes: 51 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Test and lint

on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- name: Set up PDM
uses: pdm-project/setup-pdm@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
pdm sync -dG lint -dG format -dG test
- name: Run Lint
run: |
make lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
fail-fast: false

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set up PDM
uses: pdm-project/setup-pdm@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pdm sync -dG test
- name: Run Tests
run: |
pdm run -v pytest tests
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,13 @@ dmypy.json

# Pyre type checker
.pyre/

# PDM
.pdm-python
.pdm-build

# vscode
.vscode

#
/typings
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-added-large-files # Prevent giant files from being committed.
- id: end-of-file-fixer # Makes sure files end in a newline and only a newline.
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: ["--keep-percent-format", "--py38-plus"]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.0
hooks:
- id: black
- repo: https://github.com/PyCQA/bandit
rev: "1.7.5"
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]
- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.1
hooks:
- id: gitleaks
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
hooks:
- id: ruff
63 changes: 63 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.DEFAULT_GOAL := all
sources = src tests

.PHONY: .pdm # Check that pdm is installed
.pdm:
@pdm -V || echo 'Please install pdm https://pdm.fming.dev/latest/'

.PHONY: .pre-commit # Check that pre-commit is installed
.pre-commit:
@pdm run pre-commit -V || echo 'Please install pre-commit: https://pre-commit.com/'

.PHONY: .install-project
.install-project: .pdm # Install the package, dependencies, and pre-commit for local development
pdm install

.PHONY: .install-pre-commit
.install-pre-commit: .pdm # Install the package, dependencies, and pre-commit for local development
pdm run pre-commit install

.PHONY: format
format: .pdm # Auto-format Python source files
pdm run black $(sources)
pdm run ruff --select I001 --fix --show-fixes $(sources)

.PHONY: lint
lint: .pdm # Lint python source files
pdm run black $(sources) --check --diff
pdm run mypy $(sources)
pdm run ruff $(sources)

.PHONY: pre-commit
pre_commit: .pdm # Run pre-commit for all files
pdm run pre-commit run --all-files

.PHONY: test
test: .pdm .clean-coverage # Build packages for different versions of Python and run tests for each package
pdm run tox

.PHONY: .clean-coverage # Remove coverage reports and files
.clean-coverage:
@[ -f .coverage ] && rm .coverage || echo ".coverage doesn't exist"
@rm -rf htmlcov

.PHONY: .clean-build
.clean-build:
@rm -rf dist

PHONY: build
build: .pdm .clean-build # Build the package
pdm build

.PHONY: clean
clean: .clean-coverage .clean-build # Clean repository
@rm -rf .tox
@rm -rf .mypy_cache

.PHONY: help # Show this help message (author @dwmkerr: https://dwmkerr.com/makefile-help-command/)
help: # List all available commands
@grep -E '^[a-zA-Z0-9 -]+:.*#' Makefile | sort | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done

.PHONY : install, install-cicd, all
install : .install-project .install-pre-commit # Install the package, dependencies, and pre-commit for local development
all : clean install format lint pre-commit test build # (default) Run all commands
78 changes: 77 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,78 @@

# organize-photos
The Python CLI tool utilizes metadata to efficiently organize and group photos within a specified folder by renaming them based on their metadata attributes

The `organize-photos` is a Python CLI program that allows you to organize your photos into subfolders based on their EXIF metadata. You can define a custom pattern to create new paths for your photos, making it easy to sort and categorize your image collection.

## Features

- Organize photos based on EXIF metadata such as date and time taken.
- Customize the path structure using a template with placeholders for year, month, day, hour, minute, and second.
- Copy and rename images to the destination directory, maintaining the folder structure specified by the template.
- Supports UNIX-style glob patterns for selecting files in the source directory.

## Installation

### Development
Prerequisites: [pdm](https://pdm.fming.dev/latest/) for environment management
1. Clone this repository.

```bash
git clone https://github.com/ohmycoffe/organize-photos.git
```

2. Navigate to the project directory.

```bash
cd organize-photos
```

3. Install the required dependencies using pdm.

```bash
pdm install -G dev
```
Install pre-commit.
```bash
pdm run pre-commit install
```

4. Run tests.

```bash
pdm run pytest
```
> **_NOTE:_** This repository supports also GNU Make commands
```bash
make help
```

## Usage

You can easily install the latest released version using binary installers from the Python Package Index (PyPI):

```sh
pip install organize-photos --user
```

- `source-dir`: The source directory containing the photos you want to organize.
- `-d, --dest-dir`: The destination directory where copied and renamed images will be saved. If not provided, the default is the current working directory.
- `-t, --template`: The template for generating new file paths. Customize the path structure using placeholders such as `${year}`, `${month}`, `${day}`, `${hour}`, `${minute}`, and `${second}`.
- `-p, --file-pattern`: The pattern for selecting files in the source directory. Use UNIX-style glob patterns to filter which files will be processed. The default is to process all files.

## Example

```bash
organize-photos /path/to/source/photos -d /path/to/output -t "${year}/${year}${month}${day}${hour}${minute}${second}" -p "**/*.jpg"
```

This command will organize the photos in the source directory based on the specified template and file pattern and save the organized photos in the destination directory.
For instance, if you have a file located at `/path/to/source/photos/image1.jpeg`, which was created on `January 3, 2019, at 20:54:12`, the program will create a copy of the file at `/path/to/output/2019/20190103205412.jpeg` following the specified pattern.

## License

This organize-photos is released under the [MIT License](LICENSE).

## Author

- ohmycoffe
- GitHub: [ohmycoffe](https://github.com/ohmycoffe)
Loading
Loading