various geeqie-ufraw improvements
authorVladimir Nadvornik <nadvornik@suse.cz>
Sat, 20 Jun 2009 23:15:11 +0000 (23:15 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Sat, 20 Jun 2009 23:15:11 +0000 (23:15 +0000)
- handle xmp sidecars
- commandline options, help

plugins/ufraw/geeqie-ufraw
plugins/ufraw/geeqie-ufraw-recursive.desktop.in
plugins/ufraw/geeqie-ufraw.desktop.in

index c878f56..080e0cc 100755 (executable)
@@ -1,24 +1,56 @@
 #!/bin/bash
 
 # FIXME TODO:
-# restore XMP in output files from input sidecars
-# getopt, verbosity levels
 # improve the default ufraw configuration
 # localization?
-# help
 
 
 # matches raw file names, used as case insensitive
 RAW_REGEX='.*\.(arw|srf|sr2|crw|cr2|kdc|dcr|k25|raf|mef|mos|mrw|nef|orf|pef|ptx|dng|x3f|raw|r3d|3fr|erf)$'
 
+# matches output file names, used as case insensitive
+OUT_REGEX='.*\.(jpg|jpeg|png|tif|tiff|ppm)$'
+
 # matches ufraw id file names, used as case sensitive
 ID_REGEX='.*\.ufraw$'
 
+# matches xmp sidecar file names, used as case insensitive
+XMP_REGEX='.*\.xmp$'
+
+# extract output file from ufraw id file
 get_output_from_id ()
 {
     grep "<OutputFilename>.*</OutputFilename>" "$1" |sed -e 's|.*<OutputFilename>\(.*\)</OutputFilename>.*|\1|'
 }
 
+# extract input file from ufraw id file
+get_input_from_id ()
+{
+    grep "<InputFilename>.*</InputFilename>" "$1" |sed -e 's|.*<InputFilename>\(.*\)</InputFilename>.*|\1|'
+}
+
+add_xmp_from_sidecar ()
+{
+    idfile=$1
+    input=`get_input_from_id "$idfile"`
+    [ -f "$input" ] || return 1
+
+    basename=${input%.*}
+    dirname=${basename%/*}
+    xmp=`find "$dirname" -maxdepth 1 -path "$basename.*" -regextype posix-egrep -iregex "$XMP_REGEX" -print | head -n 1`
+    [ -f "$xmp" ] || return 1
+
+    output=`get_output_from_id "$idfile"`
+
+    [ -f "$output" ] || return 1
+    xmpext=.${xmp##*.}
+
+    # passing the source file to exiv2 is unnecessary complicated
+    # do not change the orientation, ufraw resets it to 1
+    exiv2 insert -ixX -l "$dirname" -S "$xmpext" "$output"
+    exiv2 -M "set Xmp.tiff.Orientation 1" "$output"
+}
+
 # test if the id file has changed and the output needs to be refreshed
 id_file_changed ()
 {
@@ -33,6 +65,7 @@ process_ufraw_id_file ()
     idfile=$1
     if id_file_changed "$idfile" ; then
         ufraw-batch --overwrite "$idfile"
+        add_xmp_from_sidecar "$idfile"
     fi
 }
 
@@ -41,7 +74,12 @@ raw_file_not_processed ()
 {
     rawfile=$1
     basename=${rawfile%.*}
-    [ ! -f "$basename.ufraw" ]
+    dirname=${basename%/*}
+    outfiles=`find "$dirname" -maxdepth 1 -path "$basename.*" -regextype posix-egrep \( -iregex "$OUT_REGEX" -o -regex "$ID_REGEX" \) -print `
+    [ -z "$outfiles" ] # return true if no possible output file exists
+
+    # raw+jpeg pair created by the camera is considered processed, 
+    # - this function returns false, the jpeg from camera is preserved and id file is not created
 }
 
 # process raw file for the first time
@@ -55,6 +93,8 @@ process_raw_file_default ()
                     --out-type=jpeg \
                     --compression=96 \
                     "$rawfile"
+        idfile=${rawfile%.*}.ufraw
+        add_xmp_from_sidecar "$idfile"
     fi
 }
 
@@ -64,7 +104,7 @@ process_list ()
 {
     list=$1
     use_zenity=$2
-    
+
     count=`wc -l <$list`
     n=0
     [ -n "$use_zenity" ] && echo 0
@@ -80,7 +120,7 @@ process_list ()
             fi
 
             n=$((n + 1))
-            
+
             # the function can end at the 'echo' command with broken pipe
             # if it is cancelled via zenity
             [ -n "$use_zenity" ] && echo $((n * 100 / count))
@@ -90,18 +130,18 @@ process_list ()
     [ -n "$use_zenity" ] && echo 100
 }
 
-# process all files in directory $1, including subdirectories
+# process all files in directories $@, including subdirectories
 # processing is controlled by zenity dialogs if $DISPLAY is set
 process_tree ()
 {
     list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1
 
-    find "$1" -regextype posix-egrep -iregex "$RAW_REGEX" -print | while read rawfile ; do
+    find "$@" -regextype posix-egrep -iregex "$RAW_REGEX" -print | while read rawfile ; do
         raw_file_not_processed "$rawfile" && echo "$rawfile" 
     done >>$list
     
     #refresh output from changed id files
-    find "$1" -regextype posix-egrep -regex "$ID_REGEX" -print | while read idfile ; do
+    find "$@" -regextype posix-egrep -regex "$ID_REGEX" -print | while read idfile ; do
         id_file_changed "$idfile" && echo "$idfile"
     done >>$list
 
@@ -109,6 +149,8 @@ process_tree ()
         if [ -s $list ] && \
            zenity --list --title "Files to proceed" --text "Files to proceed" --column "Files" <$list ; then
             process_list $list with_zenity | zenity --progress --auto-close
+        else
+           zenity --info --title "All files are up-to-date" --text "All files are up-to-date"
         fi
     else 
         # no DISPLAY
@@ -117,15 +159,56 @@ process_tree ()
     rm $list
 }
 
+print_help ()
+{
+    cat << EOT
+
+    RAW file collection maintenance tool
+
+    Usage:
 
+    geeqie-ufraw [raw file | id file] ...
+    geeqie-ufraw --recursive [dir] ...
+    geeqie-ufraw -h | --help
+
+    This script searches for new RAW files or for modified UFRaw 
+    ID files and process them with ufraw-batch. It can work either 
+    on individual files or on whole directory.
+    The functions are designed to be usable from Geeqie menu.
+
+EOT
+}
 
-if [ -d "$1" ] ; then
-    # $1 is a directory
-    process_tree "$1"
+#parse commandline
+
+while true ; do
+    case "$1" in
+        -v|--verbose)
+            verbose=yes #fixme: not used yet
+            shift ;;
+        -R|--recursive)
+            recursive=yes
+            shift ;;
+        -h|-help|--help|-*) 
+            print_help
+            exit  ;;
+        *)
+            break ;;
+    esac
+done
+
+if [ $# -lt 1 ] ; then
+    print_help
+    exit
+fi 
+
+if [ -n "$recursive" ] ; then
+    # recursive processing of directories
+    process_tree "$@"
 else
     list=`mktemp /tmp/geeqie-ufraw-list.XXXXXXXXXX` || exit 1
     for file in "$@" ; do
-        echo $file
+        echo "$file" |sed -e "s|^\([^/]\)|$PWD/\1|"
     done >>$list
     process_list $list
     rm $list
index 0a02e83..ce8577e 100644 (file)
@@ -1,10 +1,13 @@
 [Desktop Entry]
 Version=1.0
 Type=Application
-_Name=Process folder with UFRaw Batch
+_Name=UFRaw Batch recursive
 
 # call the helper script with current directory as an argument
-Exec=geeqie-ufraw .
+Exec=geeqie-ufraw --recursive .
+
+# show only if ufraw is installed
+TryExec=ufraw
 
 # Desktop files that are usable only in Geeqie should be marked like this:
 Categories=X-Geeqie;
@@ -16,3 +19,4 @@ X-Geeqie-Menu-Path=EditMenu
 # It can be made verbose
 # X-Geeqie-Verbose=true
 
+Icon=ufraw
index 35c76cd..466fe4f 100644 (file)
@@ -7,6 +7,9 @@ _Name=UFRaw Batch
 # - this allows a better controll over processing
 Exec=geeqie-ufraw %f
 
+# show only if ufraw is installed
+TryExec=ufraw
+
 # Desktop files that are usable only in Geeqie should be marked like this:
 Categories=X-Geeqie;
 OnlyShowIn=X-Geeqie;
@@ -18,3 +21,5 @@ X-Geeqie-Menu-Path=EditMenu
 X-Geeqie-Verbose=true
 
 MimeType=application/x-ufraw;image/x-dcraw;
+
+Icon=ufraw