comparison plugins/ufraw/geeqie-ufraw @ 1651:65ebc00c3780

various geeqie-ufraw improvements - handle xmp sidecars - commandline options, help
author nadvornik
date Sat, 20 Jun 2009 23:15:11 +0000
parents 70277ff12cfc
children
comparison
equal deleted inserted replaced
1650:890eca727486 1651:65ebc00c3780
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # FIXME TODO: 3 # FIXME TODO:
4 # restore XMP in output files from input sidecars
5 # getopt, verbosity levels
6 # improve the default ufraw configuration 4 # improve the default ufraw configuration
7 # localization? 5 # localization?
8 # help
9 6
10 7
11 # matches raw file names, used as case insensitive 8 # matches raw file names, used as case insensitive
12 RAW_REGEX='.*\.(arw|srf|sr2|crw|cr2|kdc|dcr|k25|raf|mef|mos|mrw|nef|orf|pef|ptx|dng|x3f|raw|r3d|3fr|erf)$' 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)$'
13 10
11 # matches output file names, used as case insensitive
12 OUT_REGEX='.*\.(jpg|jpeg|png|tif|tiff|ppm)$'
13
14 # matches ufraw id file names, used as case sensitive 14 # matches ufraw id file names, used as case sensitive
15 ID_REGEX='.*\.ufraw$' 15 ID_REGEX='.*\.ufraw$'
16 16
17 # matches xmp sidecar file names, used as case insensitive
18 XMP_REGEX='.*\.xmp$'
19
20 # extract output file from ufraw id file
17 get_output_from_id () 21 get_output_from_id ()
18 { 22 {
19 grep "<OutputFilename>.*</OutputFilename>" "$1" |sed -e 's|.*<OutputFilename>\(.*\)</OutputFilename>.*|\1|' 23 grep "<OutputFilename>.*</OutputFilename>" "$1" |sed -e 's|.*<OutputFilename>\(.*\)</OutputFilename>.*|\1|'
24 }
25
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"
20 } 52 }
21 53
22 # test if the id file has changed and the output needs to be refreshed 54 # test if the id file has changed and the output needs to be refreshed
23 id_file_changed () 55 id_file_changed ()
24 { 56 {
31 process_ufraw_id_file () 63 process_ufraw_id_file ()
32 { 64 {
33 idfile=$1 65 idfile=$1
34 if id_file_changed "$idfile" ; then 66 if id_file_changed "$idfile" ; then
35 ufraw-batch --overwrite "$idfile" 67 ufraw-batch --overwrite "$idfile"
68 add_xmp_from_sidecar "$idfile"
36 fi 69 fi
37 } 70 }
38 71
39 # test for newly added raw files that were never processed 72 # test for newly added raw files that were never processed
40 raw_file_not_processed () 73 raw_file_not_processed ()
41 { 74 {
42 rawfile=$1 75 rawfile=$1
43 basename=${rawfile%.*} 76 basename=${rawfile%.*}
44 [ ! -f "$basename.ufraw" ] 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
45 } 83 }
46 84
47 # process raw file for the first time 85 # process raw file for the first time
48 process_raw_file_default () 86 process_raw_file_default ()
49 { 87 {
53 --wb=camera \ 91 --wb=camera \
54 --exposure=auto \ 92 --exposure=auto \
55 --out-type=jpeg \ 93 --out-type=jpeg \
56 --compression=96 \ 94 --compression=96 \
57 "$rawfile" 95 "$rawfile"
96 idfile=${rawfile%.*}.ufraw
97 add_xmp_from_sidecar "$idfile"
58 fi 98 fi
59 } 99 }
60 100
61 # process all files listed in file $1 101 # process all files listed in file $1
62 # if $2 is not empty, produce output for zenity --progress 102 # if $2 is not empty, produce output for zenity --progress
63 process_list () 103 process_list ()
64 { 104 {
65 list=$1 105 list=$1
66 use_zenity=$2 106 use_zenity=$2
67 107
68 count=`wc -l <$list` 108 count=`wc -l <$list`
69 n=0 109 n=0
70 [ -n "$use_zenity" ] && echo 0 110 [ -n "$use_zenity" ] && echo 0
71 111
72 if [ "$count" -gt 0 ] ; then 112 if [ "$count" -gt 0 ] ; then
78 process_ufraw_id_file "$file" 118 process_ufraw_id_file "$file"
79 119
80 fi 120 fi
81 121
82 n=$((n + 1)) 122 n=$((n + 1))
83 123
84 # the function can end at the 'echo' command with broken pipe 124 # the function can end at the 'echo' command with broken pipe
85 # if it is cancelled via zenity 125 # if it is cancelled via zenity
86 [ -n "$use_zenity" ] && echo $((n * 100 / count)) 126 [ -n "$use_zenity" ] && echo $((n * 100 / count))
87 127
88 done <$list 128 done <$list
89 fi 129 fi
90 [ -n "$use_zenity" ] && echo 100 130 [ -n "$use_zenity" ] && echo 100
91 } 131 }
92 132
93 # process all files in directory $1, including subdirectories 133 # process all files in directories $@, including subdirectories
94 # processing is controlled by zenity dialogs if $DISPLAY is set 134 # processing is controlled by zenity dialogs if $DISPLAY is set
95 process_tree () 135 process_tree ()
96 { 136 {
97 list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1 137 list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1
98 138
99 find "$1" -regextype posix-egrep -iregex "$RAW_REGEX" -print | while read rawfile ; do 139 find "$@" -regextype posix-egrep -iregex "$RAW_REGEX" -print | while read rawfile ; do
100 raw_file_not_processed "$rawfile" && echo "$rawfile" 140 raw_file_not_processed "$rawfile" && echo "$rawfile"
101 done >>$list 141 done >>$list
102 142
103 #refresh output from changed id files 143 #refresh output from changed id files
104 find "$1" -regextype posix-egrep -regex "$ID_REGEX" -print | while read idfile ; do 144 find "$@" -regextype posix-egrep -regex "$ID_REGEX" -print | while read idfile ; do
105 id_file_changed "$idfile" && echo "$idfile" 145 id_file_changed "$idfile" && echo "$idfile"
106 done >>$list 146 done >>$list
107 147
108 if [ -n "$DISPLAY" ] ; then 148 if [ -n "$DISPLAY" ] ; then
109 if [ -s $list ] && \ 149 if [ -s $list ] && \
110 zenity --list --title "Files to proceed" --text "Files to proceed" --column "Files" <$list ; then 150 zenity --list --title "Files to proceed" --text "Files to proceed" --column "Files" <$list ; then
111 process_list $list with_zenity | zenity --progress --auto-close 151 process_list $list with_zenity | zenity --progress --auto-close
152 else
153 zenity --info --title "All files are up-to-date" --text "All files are up-to-date"
112 fi 154 fi
113 else 155 else
114 # no DISPLAY 156 # no DISPLAY
115 process_list $list 157 process_list $list
116 fi 158 fi
117 rm $list 159 rm $list
118 } 160 }
119 161
120 162 print_help ()
121 163 {
122 if [ -d "$1" ] ; then 164 cat << EOT
123 # $1 is a directory 165
124 process_tree "$1" 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
183
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 "$@"
125 else 208 else
126 list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1 209 list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1
127 for file in "$@" ; do 210 for file in "$@" ; do
128 echo $file 211 echo "$file" |sed -e "s|^\([^/]\)|$PWD/\1|"
129 done >>$list 212 done >>$list
130 process_list $list 213 process_list $list
131 rm $list 214 rm $list
132 fi 215 fi