fixed tools/prepare_data to also perform the conversion if the
[laserbrain_demo] / tools / prepare_data
1 #!/bin/sh
2
3 indir=datasrc
4 descfile=$indir/datadesc
5 outdir=data
6 filter=$1
7 force_update=false
8
9 process()
10 {
11     src_path=$1
12     dst_path=$2
13     op=$3
14
15     cmd=$(echo $op | sed 's/<SRC>/$src_path/g;s/<DST>/$dst_path/g')
16     export src_path
17     export dst_path
18     if ! eval $cmd; then
19                 fname=$(basename $src_path)
20                 echo "Failed to process data file $fname" >&2
21                 echo "Command line was: \"$cmd\""
22                 exit 1
23         fi
24 }
25
26 copy()
27 {
28         src_path=$1
29         dst_path=$2
30
31         if ! cp $src_path $dst_path; then
32                 fname=$(basename $src_path)
33                 echo "Failed to copy data file $fname" >&2
34                 exit 1
35         fi
36 }
37
38 for arg; do
39         case "$arg" in
40         -f)
41                 force=true
42                 ;;
43         esac
44 done
45
46 if [ -z "$filter" ]; then
47         filter='.*'
48 fi
49
50 mkdir -p $outdir
51
52 while read line; do
53     line=$(echo $line | sed 's/#.*$//' | grep "$filter")
54     if [ -n "$line" ]; then
55         path=$(echo $line | awk -F : '{ print $1; }')
56         fname=$(basename $path)
57         op=$(echo $line | awk -F : '{ print $2; }' | xargs)
58
59                 infile=$indir/$path
60                 outfile=$outdir/$path
61
62                 if $force_update; then
63                         touch "$infile"
64                 fi
65
66                 if [ \( ! -f "$outfile" \) -o \( "$infile" -nt "$outfile" \) ]; then
67                         if [ "$op" = nop ]; then
68                                 echo copying $fname
69                                 mkdir -p $outdir/$(dirname $path)
70                                 copy $indir/$path $outdir/$path
71                         else
72                                 echo processing $fname
73                                 mkdir -p $outdir/$(dirname $path)
74                                 process $indir/$path $outdir/$path "$op"
75                         fi
76                 fi
77     fi
78 done <$descfile