diff --git a/.github/settings.yml b/.github/settings.yml index bf9c15b..ad2a9f6 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -1,4 +1,4 @@ --- repository: - description: Import and process RAW files. + description: Process images homepage: https://robertdebock.nl/ diff --git a/.gitignore b/.gitignore index feb7cec..822ff41 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ molecule/*/.molecule *.log *.swp molecule/resources/out +.DS_Store diff --git a/.travis.yml b/.travis.yml index 059cfdf..910a135 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,21 +4,21 @@ language: python services: docker env: - - version=">=2.7,<2.8" distro="alpine-latest" expectation="fail" - - version="" distro="alpine-latest" expectation="fail" - - version="devel" distro="alpine-latest" expectation="fail" - - version=">=2.7,<2.8" distro="alpine-edge" expectation="fail" - - version="" distro="alpine-edge" expectation="fail" - - version="devel" distro="alpine-edge" expectation="fail" + - version=">=2.7,<2.8" distro="alpine-latest" + - version="" distro="alpine-latest" + - version="devel" distro="alpine-latest" + - version=">=2.7,<2.8" distro="alpine-edge" + - version="" distro="alpine-edge" + - version="devel" distro="alpine-edge" - version=">=2.7,<2.8" distro="archlinux" - version="" distro="archlinux" - version="devel" distro="archlinux" - - version=">=2.7,<2.8" distro="centos-6" - - version="" distro="centos-6" - - version="devel" distro="centos-6" - - version=">=2.7,<2.8" distro="centos-latest" expectation="fail" - - version="" distro="centos-latest" expectation="fail" - - version="devel" distro="centos-latest" expectation="fail" + - version=">=2.7,<2.8" distro="centos-6" expectation="fail" + - version="" distro="centos-6" expectation="fail" + - version="devel" distro="centos-6" expectation="fail" + - version=">=2.7,<2.8" distro="centos-latest" + - version="" distro="centos-latest" + - version="devel" distro="centos-latest" - version=">=2.7,<2.8" distro="debian-stable" - version="" distro="debian-stable" - version="devel" distro="debian-stable" @@ -31,9 +31,9 @@ env: - version=">=2.7,<2.8" distro="fedora-rawhide" - version="" distro="fedora-rawhide" - version="devel" distro="fedora-rawhide" - - version=">=2.7,<2.8" distro="opensuse-leap" expectation="fail" - - version="" distro="opensuse-leap" expectation="fail" - - version="devel" distro="opensuse-leap" expectation="fail" + - version=">=2.7,<2.8" distro="opensuse-leap" + - version="" distro="opensuse-leap" + - version="devel" distro="opensuse-leap" - version=">=2.7,<2.8" distro="ubuntu-rolling" - version="" distro="ubuntu-rolling" - version="devel" distro="ubuntu-rolling" @@ -46,13 +46,13 @@ env: matrix: allow_failures: - - env: version=">=2.7,<2.8" distro="alpine-edge" expectation="fail" - - env: version="" distro="alpine-edge" expectation="fail" - - env: version="devel" distro="alpine-edge" expectation="fail" - - env: version="devel" distro="alpine-latest" expectation="fail" + - env: version=">=2.7,<2.8" distro="alpine-edge" + - env: version="" distro="alpine-edge" + - env: version="devel" distro="alpine-edge" + - env: version="devel" distro="alpine-latest" - env: version="devel" distro="archlinux" - - env: version="devel" distro="centos-6" - - env: version="devel" distro="centos-latest" expectation="fail" + - env: version="devel" distro="centos-6" expectation="fail" + - env: version="devel" distro="centos-latest" - env: version="devel" distro="debian-stable" - env: version=">=2.7,<2.8" distro="debian-unstable" - env: version="" distro="debian-unstable" @@ -61,7 +61,7 @@ matrix: - env: version=">=2.7,<2.8" distro="fedora-rawhide" - env: version="" distro="fedora-rawhide" - env: version="devel" distro="fedora-rawhide" - - env: version="devel" distro="opensuse-leap" expectation="fail" + - env: version="devel" distro="opensuse-leap" - env: version="devel" distro="ubuntu-rolling" - env: version=">=2.7,<2.8" distro="ubuntu-devel" - env: version="" distro="ubuntu-devel" diff --git a/README.md b/README.md index 8f5fa87..b9784a5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ y Ansible logo Build status -Import and process RAW files. +Process images Example Playbook ---------------- @@ -17,13 +17,12 @@ This example is taken from `molecule/resources/playbook.yml`: become: yes gather_facts: yes - vars: - y_import_from: /data/in - y_export_to: out - y_preset: monochrome - roles: - - robertdebock.y + - role: robertdebock.y + y_import_from: /data/in + y_export_to: out + y_presets: + - name: monochrome ``` The machine you are running this on, may need to be prepared. @@ -39,7 +38,7 @@ The machine you are running this on, may need to be prepared. - robertdebock.epel tasks: - - name: create /data + - name: create directories in container file: path: "{{ item }}" state: directory @@ -48,12 +47,10 @@ The machine you are running this on, may need to be prepared. - /data/in - /data/out - - name: copy samples files to /data + - name: copy samples files to /data/in copy: - src: "{{ item }}" + src: in/ dest: /data/in - with_items: - - sample.RAF ``` Also see a [full explanation and example](https://robertdebock.nl/how-to-use-these-roles.html) on how to use these roles. @@ -66,13 +63,16 @@ These variables are set in `defaults/main.yml`: --- # defaults file for y -y_import_from: /tmp/import -y_export_to: /tmp/export +# y_presets is a list of presets that will be applied to images. +# y_presets: +# - name: monochrome -y_convert_images: yes +# y_import_from defines the path where to pickup files from. +# This could be /dev/sdb1 (for some SD-card) for example. +y_import_from: /tmp/import -y_preset: - - name: monochrome +# y_export_to is the path where the images will be saved. +y_export_to: /tmp/export ``` Requirements @@ -106,22 +106,33 @@ This role has been tested against the following distributions and Ansible versio |distribution|ansible 2.7|ansible 2.8|ansible devel| |------------|-----------|-----------|-------------| -|alpine-edge*|no|no|no*| -|alpine-latest|no|no|no*| +|alpine-edge*|yes|yes|yes*| +|alpine-latest|yes|yes|yes*| |archlinux|yes|yes|yes*| -|centos-6|yes|yes|yes*| -|centos-latest|no|no|no*| +|centos-6|no|no|no*| +|centos-latest|yes|yes|yes*| |debian-stable|yes|yes|yes*| |debian-unstable*|yes|yes|yes*| |fedora-latest|yes|yes|yes*| |fedora-rawhide*|yes|yes|yes*| -|opensuse-leap|no|no|no*| +|opensuse-leap|yes|yes|yes*| |ubuntu-devel*|yes|yes|yes*| |ubuntu-latest|yes|yes|yes*| |ubuntu-rolling|yes|yes|yes*| A single star means the build may fail, it's marked as an experimental build. +Exceptions +---------- + +Some variarations of the build matrix do not work. These are the variations and reasons why the build won't work: + +| variation | reason | +|---------------------------|------------------------| +| CentOS 6 | Somehow ImageMagick creates a different file each run. Not idempotent. | + + + Testing ------- diff --git a/defaults/main.yml b/defaults/main.yml index 59dce0e..96fe3ff 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,10 +1,13 @@ --- # defaults file for y -y_import_from: /tmp/import -y_export_to: /tmp/export +# y_presets is a list of presets that will be applied to images. +# y_presets: +# - name: monochrome -y_convert_images: yes +# y_import_from defines the path where to pickup files from. +# This could be /dev/sdb1 (for some SD-card) for example. +y_import_from: /tmp/import -y_preset: - - name: monochrome +# y_export_to is the path where the images will be saved. +y_export_to: /tmp/export diff --git a/meta/exception.yml b/meta/exception.yml new file mode 100644 index 0000000..4454c3d --- /dev/null +++ b/meta/exception.yml @@ -0,0 +1,4 @@ +--- +exceptions: + - variation: CentOS 6 + reason: Somehow ImageMagick creates a different file each run. Not idempotent. diff --git a/meta/main.yml b/meta/main.yml index 798216b..a0041d6 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -2,7 +2,7 @@ galaxy_info: author: Robert de Bock role_name: y - description: Import and process RAW files. + description: Process images license: Apache-2.0 company: none min_ansible_version: 2.6 diff --git a/molecule/centos-latest/molecule.yml b/molecule/centos-latest/molecule.yml index 9744bbf..ba78635 100644 --- a/molecule/centos-latest/molecule.yml +++ b/molecule/centos-latest/molecule.yml @@ -18,3 +18,5 @@ provisioner: converge: ../resources/playbook.yml scenario: name: centos-latest + converge_sequence: + - converge diff --git a/molecule/resources/in/sample.jpg b/molecule/resources/in/sample.jpg new file mode 100644 index 0000000..3d49669 Binary files /dev/null and b/molecule/resources/in/sample.jpg differ diff --git a/molecule/resources/playbook.yml b/molecule/resources/playbook.yml index 99705ec..67839c9 100644 --- a/molecule/resources/playbook.yml +++ b/molecule/resources/playbook.yml @@ -4,10 +4,9 @@ become: yes gather_facts: yes - vars: - y_import_from: /data/in - y_export_to: out - y_preset: monochrome - roles: - - ansible-role-y + - role: ansible-role-y + y_import_from: /data/in + y_export_to: out + y_presets: + - name: monochrome diff --git a/molecule/resources/prepare.yml b/molecule/resources/prepare.yml index f92e498..0da3f26 100644 --- a/molecule/resources/prepare.yml +++ b/molecule/resources/prepare.yml @@ -9,7 +9,7 @@ - robertdebock.epel tasks: - - name: create /data + - name: create directories in container file: path: "{{ item }}" state: directory @@ -18,9 +18,7 @@ - /data/in - /data/out - - name: copy samples files to /data + - name: copy samples files to /data/in copy: - src: "{{ item }}" + src: in/ dest: /data/in - with_items: - - sample.RAF diff --git a/molecule/resources/sample.RAF b/molecule/resources/sample.RAF deleted file mode 100644 index e20128c..0000000 Binary files a/molecule/resources/sample.RAF and /dev/null differ diff --git a/tasks/image.yml b/tasks/image.yml index 0d42e1b..a539a28 100644 --- a/tasks/image.yml +++ b/tasks/image.yml @@ -1,55 +1,4 @@ --- -- name: save the year - shell: set -o pipefail ; {{ y_exiftool_binary }} {{ image.path }} -d "%Y" | grep "Create Date" | awk '{print $NF}' - args: - creates: nothing - executable: /bin/bash - register: year - changed_when: no - check_mode: no - -- name: save the month - shell: set -o pipefail ; {{ y_exiftool_binary }} {{ image.path }} -d "%m" | grep "Create Date" | awk '{print $NF}' - args: - creates: nothing - executable: /bin/bash - register: month - changed_when: no - check_mode: no - -- name: save the day - shell: set -o pipefail ; {{ y_exiftool_binary }} {{ image.path }} -d "%d" | grep "Create Date" | awk '{print $NF}' - args: - creates: nothing - executable: /bin/bash - register: day - changed_when: no - check_mode: no - -- name: ensure directory structure exists - file: - path: "{{ y_export_path }}" - state: directory - -- name: process images - block: - - name: processing {{ image.path | basename }} - shell: dcraw -c "{{ y_command_options[y_preset] }}" "{{ image.path }}" > "{{ y_export_path }}/{{ (image.path | basename | splitext)[0] }}.pgm" - args: - creates: "{{ y_export_path }}/{{ (image.path | basename | splitext)[0] }}.pgm" - - - name: copying processed image back - fetch: - src: "{{ y_export_path }}/{{ (image.path | basename | splitext)[0] }}.pgm" - dest: "{{ y_export_to }}/{{ (image.path | basename | splitext)[0] }}.pgm" - flat: yes - when: - - y_convert_images | bool - -- name: copying unprocessed image back - fetch: - src: "{{ y_export_path }}/{{ (image.path | basename }}" - dest: "{{ y_export_to }}" - flat: yes - when: - - not y_convert_images | bool +- name: apply presets + include: "{{ item.name }}.yml" + loop: "{{ y_presets }}" diff --git a/tasks/main.yml b/tasks/main.yml index 11b8603..b534d81 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,20 +8,34 @@ until: y_install_requirements is succeeded retries: 3 +- name: create export directory + file: + path: "{{ y_export_to }}" + state: directory + - name: find files to convert {{ y_import_from }} find: path: "{{ y_import_from }}" - excludes: "*.pgm" + patterns: "*.jpg" when: - y_import_from is defined - register: y_files + register: y_find - name: loop over found images include: image.yml - with_items: "{{ y_files.files }}" + loop: "{{ y_find.files }}" loop_control: loop_var: image when: - - y_files is defined - - y_files.files is defined - - y_files.files + - y_find is defined + - y_find.files is defined + - y_find.files + +- name: copy converted images back + fetch: + src: "{{ item.path }}" + dest: "{{ y_export_to }}/{{ item.path | basename }}" + flat: yes + loop: "{{ y_find.files }}" + loop_control: + label: "{{ item.path }}" diff --git a/tasks/monochrome.yml b/tasks/monochrome.yml new file mode 100644 index 0000000..06e4279 --- /dev/null +++ b/tasks/monochrome.yml @@ -0,0 +1,4 @@ +--- +- name: convert to monochrome + command: convert {{ image.path }} -monochrome {{ image.path }} + changed_when: no diff --git a/vars/main.yml b/vars/main.yml index 92f369f..219cffd 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -2,32 +2,20 @@ # vars file for y _y_requirements: default: - - bash - - dcraw - - perl-Image-ExifTool + - imagemagick + Alpine: + - imagemagick Archlinux: - - awk - - bash - - dcraw - - grep - - perl-image-exiftool + - imagemagick + CentOS: + - ImageMagick Debian: - - bash - - dcraw - - libimage-exiftool-perl + - imagemagick + Fedora: + - ImageMagick + openSUSE Leap: + - ImageMagick Ubuntu: - - bash - - dcraw - - libimage-exiftool-perl + - imagemagick y_requirements: "{{ _y_requirements[ansible_distribution] | default(_y_requirements['default']) }}" - -_y_exiftool_binary: - default: exiftool - Archlinux: /usr/bin/vendor_perl/exiftool - -y_exiftool_binary: "{{ _y_exiftool_binary[ansible_distribution] | default(_y_exiftool_binary['default']) }}" -y_command_options: - monochrome: "-d" - -y_export_path: "{{ y_export_to }}/{{ year.stdout }}/{{ month.stdout }}/{{ day.stdout }}"