1707
|
1 #!/bin/sh
|
1651
|
2
|
|
3 # FIXME TODO:
|
|
4 # improve the default ufraw configuration
|
|
5 # localization?
|
|
6
|
|
7
|
|
8 # matches raw file names, used as case insensitive
|
1653
|
9 RAW_REGEX='.*\.(arw|srf|sr2|crw|cr2|kdc|dcr|k25|raf|mef|mos|mrw|nef|orf|pef|ptx|dng|x3f|raw|r3d|3fr|erf)$'
|
1651
|
10
|
1657
|
11 # matches output file names, used as case insensitive
|
|
12 OUT_REGEX='.*\.(jpg|jpeg|png|tif|tiff|ppm)$'
|
|
13
|
1651
|
14 # matches ufraw id file names, used as case sensitive
|
|
15 ID_REGEX='.*\.ufraw$'
|
|
16
|
1657
|
17 # matches xmp sidecar file names, used as case insensitive
|
|
18 XMP_REGEX='.*\.xmp$'
|
|
19
|
|
20 # extract output file from ufraw id file
|
1651
|
21 get_output_from_id ()
|
|
22 {
|
|
23 grep "<OutputFilename>.*</OutputFilename>" "$1" |sed -e 's|.*<OutputFilename>\(.*\)</OutputFilename>.*|\1|'
|
|
24 }
|
|
25
|
1657
|
26 # extract input file from ufraw id file
|
|
27 get_input_from_id ()
|
|
28 {
|
|
29 grep "<InputFilename>.*</InputFilename>" "$1" |sed -e 's|.*<InputFilename>\(.*\)</InputFilename>.*|\1|'
|
|
30 }
|
|
31
|
|
32 add_xmp_from_sidecar ()
|
|
33 {
|
|
34 idfile=$1
|
|
35 input=`get_input_from_id "$idfile"`
|
|
36 [ -f "$input" ] || return 1
|
|
37
|
|
38 basename=${input%.*}
|
|
39 dirname=${basename%/*}
|
|
40 xmp=`find "$dirname" -maxdepth 1 -path "$basename.*" -regextype posix-egrep -iregex "$XMP_REGEX" -print | head -n 1`
|
|
41 [ -f "$xmp" ] || return 1
|
|
42
|
|
43 output=`get_output_from_id "$idfile"`
|
|
44
|
|
45 [ -f "$output" ] || return 1
|
|
46 xmpext=.${xmp##*.}
|
|
47
|
|
48 # passing the source file to exiv2 is unnecessary complicated
|
|
49 # do not change the orientation, ufraw resets it to 1
|
|
50 exiv2 insert -ixX -l "$dirname" -S "$xmpext" "$output"
|
|
51 exiv2 -M "set Xmp.tiff.Orientation 1" "$output"
|
|
52 }
|
|
53
|
1651
|
54 # test if the id file has changed and the output needs to be refreshed
|
|
55 id_file_changed ()
|
|
56 {
|
|
57 idfile=$1
|
|
58 output=`get_output_from_id "$idfile"`
|
|
59 [ ! -f "$output" -o "$idfile" -nt "$output" ]
|
|
60 }
|
|
61
|
|
62 # refresh the output file specified by given id file, if necessary
|
|
63 process_ufraw_id_file ()
|
|
64 {
|
|
65 idfile=$1
|
|
66 if id_file_changed "$idfile" ; then
|
|
67 ufraw-batch --overwrite "$idfile"
|
1657
|
68 add_xmp_from_sidecar "$idfile"
|
1651
|
69 fi
|
|
70 }
|
|
71
|
|
72 # test for newly added raw files that were never processed
|
|
73 raw_file_not_processed ()
|
|
74 {
|
|
75 rawfile=$1
|
|
76 basename=${rawfile%.*}
|
1657
|
77 dirname=${basename%/*}
|
|
78 outfiles=`find "$dirname" -maxdepth 1 -path "$basename.*" -regextype posix-egrep \( -iregex "$OUT_REGEX" -o -regex "$ID_REGEX" \) -print `
|
|
79 [ -z "$outfiles" ] # return true if no possible output file exists
|
|
80
|
|
81 # raw+jpeg pair created by the camera is considered processed,
|
|
82 # - this function returns false, the jpeg from camera is preserved and id file is not created
|
1651
|
83 }
|
|
84
|
|
85 # process raw file for the first time
|
|
86 process_raw_file_default ()
|
|
87 {
|
|
88 rawfile=$1
|
|
89 if raw_file_not_processed "$rawfile" ; then
|
|
90 ufraw-batch --create-id=also \
|
|
91 --wb=camera \
|
|
92 --exposure=auto \
|
|
93 --out-type=jpeg \
|
|
94 --compression=96 \
|
|
95 "$rawfile"
|
1657
|
96 idfile=${rawfile%.*}.ufraw
|
|
97 add_xmp_from_sidecar "$idfile"
|
1651
|
98 fi
|
|
99 }
|
|
100
|
|
101 # process all files listed in file $1
|
|
102 # if $2 is not empty, produce output for zenity --progress
|
|
103 process_list ()
|
|
104 {
|
|
105 list=$1
|
|
106 use_zenity=$2
|
1657
|
107
|
1651
|
108 count=`wc -l <$list`
|
|
109 n=0
|
|
110 [ -n "$use_zenity" ] && echo 0
|
|
111
|
|
112 if [ "$count" -gt 0 ] ; then
|
|
113 while read file; do
|
|
114 [ -f "$file" ] || continue
|
1653
|
115 if echo "$file"|grep -E -q -i "$RAW_REGEX" ; then
|
1651
|
116 process_raw_file_default "$file"
|
1653
|
117 elif echo "$file"|grep -E -q "$ID_REGEX" ; then
|
1651
|
118 process_ufraw_id_file "$file"
|
|
119
|
|
120 fi
|
|
121
|
|
122 n=$((n + 1))
|
1657
|
123
|
1651
|
124 # the function can end at the 'echo' command with broken pipe
|
|
125 # if it is cancelled via zenity
|
|
126 [ -n "$use_zenity" ] && echo $((n * 100 / count))
|
|
127
|
|
128 done <$list
|
|
129 fi
|
|
130 [ -n "$use_zenity" ] && echo 100
|
|
131 }
|
|
132
|
1657
|
133 # process all files in directories $@, including subdirectories
|
1651
|
134 # processing is controlled by zenity dialogs if $DISPLAY is set
|
|
135 process_tree ()
|
|
136 {
|
|
137 list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1
|
|
138
|
1657
|
139 find "$@" -regextype posix-egrep -iregex "$RAW_REGEX" -print | while read rawfile ; do
|
1651
|
140 raw_file_not_processed "$rawfile" && echo "$rawfile"
|
|
141 done >>$list
|
|
142
|
|
143 #refresh output from changed id files
|
1657
|
144 find "$@" -regextype posix-egrep -regex "$ID_REGEX" -print | while read idfile ; do
|
1651
|
145 id_file_changed "$idfile" && echo "$idfile"
|
|
146 done >>$list
|
|
147
|
|
148 if [ -n "$DISPLAY" ] ; then
|
|
149 if [ -s $list ] && \
|
|
150 zenity --list --title "Files to proceed" --text "Files to proceed" --column "Files" <$list ; then
|
|
151 process_list $list with_zenity | zenity --progress --auto-close
|
1657
|
152 else
|
|
153 zenity --info --title "All files are up-to-date" --text "All files are up-to-date"
|
1651
|
154 fi
|
|
155 else
|
|
156 # no DISPLAY
|
|
157 process_list $list
|
|
158 fi
|
|
159 rm $list
|
|
160 }
|
|
161
|
1657
|
162 print_help ()
|
|
163 {
|
|
164 cat << EOT
|
1651
|
165
|
1657
|
166 RAW file collection maintenance tool
|
|
167
|
|
168 Usage:
|
|
169
|
|
170 geeqie-ufraw [raw file | id file] ...
|
|
171 geeqie-ufraw --recursive [dir] ...
|
|
172 geeqie-ufraw -h | --help
|
|
173
|
|
174 This script searches for new RAW files or for modified UFRaw
|
|
175 ID files and process them with ufraw-batch. It can work either
|
|
176 on individual files or on whole directory.
|
|
177 The functions are designed to be usable from Geeqie menu.
|
|
178
|
|
179 EOT
|
|
180 }
|
|
181
|
|
182 #parse commandline
|
1651
|
183
|
1657
|
184 while true ; do
|
|
185 case "$1" in
|
|
186 -v|--verbose)
|
|
187 verbose=yes #fixme: not used yet
|
|
188 shift ;;
|
|
189 -R|--recursive)
|
|
190 recursive=yes
|
|
191 shift ;;
|
|
192 -h|-help|--help|-*)
|
|
193 print_help
|
|
194 exit ;;
|
|
195 *)
|
|
196 break ;;
|
|
197 esac
|
|
198 done
|
|
199
|
|
200 if [ $# -lt 1 ] ; then
|
|
201 print_help
|
|
202 exit
|
|
203 fi
|
|
204
|
|
205 if [ -n "$recursive" ] ; then
|
|
206 # recursive processing of directories
|
|
207 process_tree "$@"
|
1651
|
208 else
|
|
209 list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1
|
|
210 for file in "$@" ; do
|
1657
|
211 echo "$file" |sed -e "s|^\([^/]\)|$PWD/\1|"
|
1651
|
212 done >>$list
|
|
213 process_list $list
|
|
214 rm $list
|
|
215 fi
|