Skip to content

Commit 6b65ff8

Browse files
authored
Merge pull request #10 from mattpopovich/5-unit-tests
Organize unit tests and make scripts less destructive
2 parents a0716b6 + 0947112 commit 6b65ff8

8 files changed

Lines changed: 178 additions & 79 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ jobs:
3939
printf -- "\n\n-Unmounting the DMG file\n"
4040
hdiutil detach /Volumes/DNGConverter_17_5
4141
42-
- name: Run reset.sh
42+
- name: Test organizeGoProDNG.sh
4343
run: |
44-
chmod +x ./reset.sh
45-
./reset.sh
44+
chmod +x tests/test_organizeGoProDNG.sh
45+
bash tests/test_organizeGoProDNG.sh
4646
47-
- name: Run organizeGoProDNG.sh
47+
- name: Test compare_AdobeDNGConverter_arguments.sh
4848
run: |
49-
chmod +x ./organizeGoProDNG.sh
50-
./organizeGoProDNG.sh
49+
chmod +x tests/test_compare_AdobeDNGConverter_arguments.sh
50+
bash tests/test_compare_AdobeDNGConverter_arguments.sh

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.autoSave": "onFocusChange",
3+
"editor.rulers": [80, 120],
4+
"files.trimTrailingWhitespace": true
5+
}

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# Adobe DNG Converter Scripts
22
A collection of scripts I made that utilize [Adobe Digital Negative (DNG) Converter](https://helpx.adobe.com/camera-raw/using/adobe-dng-converter.html)'s command line interface (CLI). Read my [blog post](https://mattpopovich.com/posts/how-to-use-adobe-dng-converter-from-the-command-line/) for additional details.
3-
* [reset.sh](reset.sh)
4-
* A script used while testing the other scripts in this repo. This script "resets" the folder to what it normally looks like coming fresh off of a GoPro.
5-
* Should be ran before running [compare_AdobeDNGConverter_arguments.sh](compare_AdobeDNGConverter_arguments.sh) or [organizeGoProDNG.sh](organizeGoProDNG.sh)
3+
64
* [compare_AdobeDNGConverter_arguments.sh](compare_AdobeDNGConverter_arguments.sh)
7-
* Runs the *Adobe DNG Converter* from the CLI with a bunch of different arguments to compare their runtime and size of the converted files
8-
* Expects [reset.sh](reset.sh) to be ran first to clean things up
5+
* Runs the *Adobe DNG Converter* from the CLI with a bunch of different arguments to compare the arguments' runtime and size of the converted files
96
* [organizeGoProDNG.sh](organizeGoProDNG.sh)
107
* A script to convert a folder coming fresh off of a GoPro from
118
* `GOPR0000.GPR`
Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,80 @@
11
# This script runs Adobe DNG Converter CLI with a bunch of different arguments
22
# and compares their runtime and output file sizes
3-
4-
# WARNING: This script will be creating (and destroying) a .DNG folder
5-
3+
#
64
# This script is expecting to be ran in a folder that has a bunch of *.GPR files:
75
# $ ls
86
# GOPR0000.GPR
97
# GOPR0001.GPR
108
# compare_AdobeDNGConverter_arguments.sh
11-
# $ ./compare_AdobeDNGConverter_arguments.sh
12-
9+
# $ bash compare_AdobeDNGConverter_arguments.sh
10+
#
1311
# Author: Matt Popovich (mattpopovich.com)
1412

1513
# Stop running script if any command fails
1614
set -e
1715

18-
# Create a (hidden) .DNG folder to store our converted files
19-
mkdir .DNG
16+
# Constants
17+
gpr_extension="GPR"
18+
dng_dir=".DNG"
19+
adobeDNGconverter="/Applications/Adobe DNG Converter.app/Contents/MacOS/Adobe DNG Converter"
2020

2121
# Will pass the argument given to Adobe DNG Converter
2222
function test_flags(){
23-
/Applications/Adobe\ DNG\ Converter.app/Contents/MacOS/Adobe\ DNG\ Converter $1 -d .DNG *.GPR
23+
"$adobeDNGconverter" $1 -d "$dng_dir" *."$gpr_extension"
2424
}
2525

2626
# Flag explanation: https://helpx.adobe.com/content/dam/help/en/camera-raw/digital-negative/jcr_content/root/content/flex/items/position/position-par/download_section/download-1/dng_converter_commandline.pdf
2727
flags_array=(
28-
"-c -p1 -cr7.1 -dng1.7.1" # Default values for AdobeDNGConverter 16.2.0 (lossless + compressed DNG files + medium JPEG preview)
29-
"-u -p1 -cr7.1 -dng1.7.1" # Output uncompressed DNG files
30-
"-l -p1 -cr7.1 -dng1.7.1" # Output linear DNG files
31-
"-c -p1 -e -cr7.1 -dng1.7.1" # Embed original raw file inside DNG files
32-
"-c -p0 -cr7.1 -dng1.7.1" # Set JPEG preview size to none
33-
"-c -p2 -cr7.1 -dng1.7.1" # Set JPEG preview size to full size
34-
"-c -p1 -fl -cr7.1 -dng1.7.1" # Embed fast load data inside DNG files
35-
"-c -p1 -lossy -cr7.1 -dng1.7.1" # Use lossy compression
36-
"-c -p1 -mp -cr7.1 -dng1.7.1" # Process multiple files in parallel
37-
"-c -p1 -mp -lossy -cr7.1 -dng1.7.1" # Use lossy compression while processing in parallel
28+
"-c -p1 -cr7.1 -dng1.7.1" # Default values for AdobeDNGConverter 16.2.0 (lossless + compressed DNG files + medium JPEG preview)
29+
"-u -p1 -cr7.1 -dng1.7.1" # Output uncompressed DNG files
30+
"-l -p1 -cr7.1 -dng1.7.1" # Output linear DNG files
31+
"-c -p1 -e -cr7.1 -dng1.7.1" # Embed original raw file inside DNG files
32+
"-c -p0 -cr7.1 -dng1.7.1" # Set JPEG preview size to none
33+
"-c -p2 -cr7.1 -dng1.7.1" # Set JPEG preview size to full size
34+
"-c -p1 -fl -cr7.1 -dng1.7.1" # Embed fast load data inside DNG files
35+
"-c -p1 -lossy -cr7.1 -dng1.7.1" # Use lossy compression
36+
"-c -p1 -mp -cr7.1 -dng1.7.1" # Process multiple files in parallel
37+
"-c -p1 -mp -cr11.2 -dng1.7.1" # Upgrade minimum camera raw compatibility version
38+
"-c -p1 -mp -cr12.4 -dng1.7.1" # ''
39+
"-c -p1 -mp -cr13.2 -dng1.7.1" # ''
40+
"-c -p1 -mp -cr14.0 -dng1.7.1" # ''
41+
"-c -p1 -mp -cr15.3 -dng1.7.1" # ''
42+
"-c -p1 -mp -lossy -cr7.1 -dng1.7.1" # Use lossy compression while processing in parallel
3843
)
3944

45+
# Prevent this script from overwriting folders
46+
if [ -d "$dng_dir" ]; then # Shell is not case sensitive
47+
echo "ERROR: $dng_dir folder was found." \
48+
"Please remove it (so that we don't mess it up) before running this script"
49+
exit 1
50+
fi
51+
52+
# Make sure we have the expected *.GPR files in this folder
53+
if ! ls *."$gpr_extension" 1> /dev/null 2>&1; then
54+
printf "%s\n" \
55+
"ERROR: Did not find *.$gpr_extension files in this folder" \
56+
"Are you running this script in the right folder?" \
57+
"Extensions must be capitalized"
58+
exit 2
59+
fi
60+
61+
# Make sure the Adobe DNG Converter executable exists
62+
if [ ! -x "$adobeDNGconverter" ]; then
63+
echo "ERROR: Could not find executable: $adobeDNGconverter"
64+
exit 3
65+
fi
66+
67+
# Create a (hidden) .DNG folder to store our converted files
68+
mkdir "$dng_dir"
69+
4070
# Get default statistics
4171
start_time=$(ruby -e 'puts Time.now.to_f') # Alternatives: https://serverfault.com/a/423642/453183
4272
test_flags "${flags_array[0]}" > /dev/null 2>/dev/null
4373
end_time=$(ruby -e 'puts Time.now.to_f')
4474
default_run_time=$(echo "${end_time} - ${start_time}" | bc)
45-
default_file_sizes=$(ls -l .DNG | awk '{sum += $5} END {print sum}')
75+
default_file_sizes=$(ls -l "$dng_dir" | awk '{sum += $5} END {print sum}')
4676
echo "Default = ${default_file_sizes}B, ${default_run_time}s"
47-
rm .DNG/*
77+
rm "$dng_dir"/*
4878

4979
# Get statistics for flags
5080
for flags in "${flags_array[@]}"; do
@@ -63,7 +93,7 @@ for flags in "${flags_array[@]}"; do
6393
fi
6494

6595
# Calculate file size differences
66-
file_size=$(ls -l .DNG | awk '{sum += $5} END {print sum}')
96+
file_size=$(ls -l "$dng_dir" | awk '{sum += $5} END {print sum}')
6797
size_difference=$(echo "${file_size} - ${default_file_sizes}" | bc)
6898
percent_size_difference=$(echo "100 * ${size_difference} / ${default_file_sizes}" | bc)
6999
if (( $(echo "$size_difference >= 0" | bc -l) )); then
@@ -73,8 +103,8 @@ for flags in "${flags_array[@]}"; do
73103

74104
# Output statistics
75105
echo "Using flags ${flags} = ${time_difference}s (${percent_time_difference}%), ${size_difference}B (${percent_size_difference}%) vs default"
76-
rm .DNG/*
106+
rm "$dng_dir"/*
77107
done
78108

79109
# Remove temporary folder
80-
rm -r .DNG
110+
rm -r "$dng_dir"

organizeGoProDNG.sh

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
# A script to convert a folder coming fresh off of a GoPro from
2-
# `GOPR0000.GPR`
3-
# `GOPR0000.JPG`
4-
# `GOPR0001.GPR`
5-
# `GOPR0001.JPG`
6-
# `organizeGoProDNG.sh`
7-
# to
8-
# `GPR/`
9-
# `GOPR0000.GPR`
10-
# `GOPR0001.GPR`
11-
# `JPG/`
12-
# `GOPR0000.JPG`
13-
# `GOPR0001.JPG`
14-
# `dng/`
15-
# `GOPR0000.dng`
16-
# `GOPR0001.dng`
17-
# `organizeGoProDNG.sh`
18-
1+
# A script to convert a folder coming fresh off of a GoPro containing raw photos
2+
# (with .GPR extensions) into a more organized folder structure, while also
3+
# converting the .GPR files into .DNG files using Adobe DNG Converter.
4+
# Ex.
5+
# $ ls
6+
# GOPR0000.GPR
7+
# GOPR0000.JPG
8+
# GOPR0001.GPR
9+
# GOPR0001.JPG
10+
# organizeGoProDNG.sh
11+
# $ bash organizeGoProDNG.sh
12+
# $ ls *
13+
# GPR:
14+
# GOPR0000.GPR GOPR0001.GPR
15+
16+
# JPG:
17+
# GOPR0000.JPG GOPR0001.JPG
18+
#
19+
# dng:
20+
# GOPR0000.dng GOPR0001.dng
21+
#
22+
# organizeGoProDNG.sh
23+
#
1924
# Author: Matt Popovich (mattpopovich.com)
2025

2126
# Stop running script if any command fails

reset.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This script copies GoPro DNG files from the examples/ folder
2+
# into the current folder, then runs compare_AdobeDNGConverter_arguments.sh
3+
#
4+
# This script should be run from the root of the repository Ex.
5+
# $ bash tests/test_compare_AdobeDNGConverter_arguments.sh
6+
#
7+
# Author: Matt Popovich (mattpopovich.com)
8+
9+
# Stop running script if any command fails
10+
set -e
11+
12+
# Copy the examples from the examples folder
13+
cp examples/* tests/
14+
15+
# Confirm the expected files were copied
16+
ls tests/GOPR0000.GPR
17+
ls tests/GOPR0000.JPG
18+
ls tests/GOPR0001.GPR
19+
ls tests/GOPR0001.JPG
20+
21+
# Copy the organize script to be tested into the current folder
22+
cp compare_AdobeDNGConverter_arguments.sh tests/
23+
24+
# Change to the tests folder
25+
cd tests
26+
27+
# Run the compare script
28+
./compare_AdobeDNGConverter_arguments.sh
29+
30+
# Clean up the copied files
31+
rm GOPR0000.GPR
32+
rm GOPR0000.JPG
33+
rm GOPR0001.GPR
34+
rm GOPR0001.JPG
35+
rm compare_AdobeDNGConverter_arguments.sh
36+
37+
# Change back to the original folder
38+
cd ..
39+
40+
# End of test
41+
echo "organizeGoProDNG.sh test passed"

tests/test_organizeGoProDNG.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This script copies GoPro DNG files from the examples/ folder
2+
# into the current folder, then runs organizeGoProDNG.sh
3+
#
4+
# This script should be run from the root of the repository Ex.
5+
# $ bash tests/test_organizeGoProDNG.sh
6+
#
7+
# Author: Matt Popovich (mattpopovich.com)
8+
9+
# Stop running script if any command fails
10+
set -e
11+
12+
# Copy the examples from the examples folder
13+
cp examples/* tests/
14+
15+
# Confirm the expected files were copied
16+
ls tests/GOPR0000.GPR
17+
ls tests/GOPR0000.JPG
18+
ls tests/GOPR0001.GPR
19+
ls tests/GOPR0001.JPG
20+
21+
# Copy the organize script to be tested into the current folder
22+
cp organizeGoProDNG.sh tests/
23+
24+
# Change to the tests folder
25+
cd tests
26+
27+
# Run the organize script
28+
./organizeGoProDNG.sh
29+
30+
# Confirm the expected results
31+
ls dng
32+
ls JPG
33+
ls GPR
34+
ls dng/GOPR0000.DNG
35+
ls JPG/GOPR0000.JPG
36+
ls GPR/GOPR0000.GPR
37+
ls dng/GOPR0001.DNG
38+
ls JPG/GOPR0001.JPG
39+
ls GPR/GOPR0001.GPR
40+
41+
# Change back to the original folder
42+
cd ..
43+
44+
# Clean up the created files
45+
rm -r tests/GPR tests/JPG tests/dng tests/organizeGoProDNG.sh
46+
47+
# End of test
48+
echo "organizeGoProDNG.sh test passed"

0 commit comments

Comments
 (0)