Added tools/generateLensList Bash4 script to make updating lens ID from exiftool for rtexif/* easy

This commit is contained in:
Morgan Hardwood 2015-08-23 21:58:35 +02:00
parent b3a12b699a
commit 1f76af5ba9

56
tools/generateLensList Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# This Bash4 script generates lens ID lists for rtexif/*.cc files using
# the exiftool version installed on the host system, so make sure you have
# the latest version of exiftool installed before running this script.
# It uses xmlstarlet to parse exiftool's output so make sure you have that.
#
# Run the script from the project root:
# ./tools/generateLensList
#
# Manually replace old code in rtexif/* with new from /tmp/rt-generateLensList/*
#
# Blame DrSlony
# Please report bugs or enhancements to https://github.com/Beep6581/RawTherapee
hash exiftool 2>/dev/null || { echo >&2 "Exiftool not found, install it first."; exit 1; }
hash xmlstarlet 2>/dev/null || { echo >&2 "XMLStarlet not found, install it first."; exit 1; }
unset cam cams
cams=("canon" "olympus" "pentax" "sony")
tmpdir="/tmp/rt-generateLensList"
head -n 15 "$0" | tail -n 14
printf '%s\n' "exiftool version: $(exiftool -ver)" "" "XMLStarlet version: $(xmlstarlet --version)" | sed 's/^/# /'
if [[ -d ${tmpdir} ]]; then
printf '%s\n' "" "Removing temp folder: $tmpdir"
rm -rvI "$tmpdir" || exit 1
fi
mkdir -p "$tmpdir" || { printf '%s\n' "Error creating $tmpdir" ""; exit 1; }
echo
for cam in "${cams[@]}"; do
printf '%s\n' "Saving ${tmpdir}/${cam}"
xmlstarlet sel -T -t -m "taginfo/table/tag[@name='LensType']/values/key" -v "concat(@id,' ',val)" -n < <(exiftool -listx -"$cam":all) > "${tmpdir}/cam" || { printf '%s\n' "Saving failed: ${tmpdir}/cam"; exit 1; }
sort -fuV "${tmpdir}/cam" > "${tmpdir}/${cam}"
rm -f "${tmpdir}/cam"
case $cam in
canon) sed -r -i -e '/-1\tn\/a/d' -e 's/([0-9]+)[0-9.]*\t/\1, "/' -e 's/^/ choices.insert(p_t(/' -e 's/$/"));/' "${tmpdir}/canon" ;;
olympus) sed -i -e '/0 00 00\tNone/d' -e 's/^/ lenses["0/' -e 's/\t/"] = "/' -e 's/$/";/' "${tmpdir}/olympus" ;;
pentax) sed -r -i -e 's/^/ choices.insert(p_t(256 * /' -e 's/([0-9]+) ([0-9]+)([0-9.]*)/\1 + \2/' -e 's/\t/, "/' -e 's/$/"));/' "${tmpdir}/pentax" ;;
sony)
# Sony has more lenses under the LensType2 tag
printf '%s\n' "Saving ${tmpdir}/sony-lenstype2"
xmlstarlet sel -T -t -m "taginfo/table/tag[@name='LensType2']/values/key" -v "concat(@id,' ',val)" -n < <(exiftool -listx -sony:all) > "${tmpdir}/cam" || { printf '%s\n' "Saving failed: ${tmpdir}/cam"; exit 1; }
sort -fuV "${tmpdir}/cam" > "${tmpdir}/sony-lenstype2"
rm -f "${tmpdir}/cam"
# Pad IDs shorter than 5 digits with 0s
sed -r -i -e 's/^[0-9]/0000&/' -e 's/0*([0-9]{5,})/\1/' "${tmpdir}/sony-lenstype2"
sed -r -i -e '/255\tTamron Lens (255)/d' -e 's/([0-9]+)[0-9.]*\t/\1, "/' -e 's/^/ choices.insert(p_t(/' -e 's/$/"));/' ${tmpdir}/sony ${tmpdir}/sony-lenstype2
;;
esac
done