archive_stp_dxf_pdf_any_year.sh 4.13 KB
Newer Older
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
#!/bin/sh
#**
#** -----------------------------------------------------------------------------**
#** archive_stp_dxf.sh
#** Preparing Varicad output files output for uploadig to wiki.elphel.com:
#** 1 - adding license information to *.stp files output
#** 2 - compressing *.dwb, *.dxf and *.stp files
#** 3 - cropping and converting *.bmp renderings to JPEG
#**
#** Copyright (C) 2010-2011 Elphel, Inc.
#**
#** -----------------------------------------------------------------------------**
#**
#**  focus_tuning.java is free software: you can redistribute it and/or modify
#**  it under the terms of the GNU General Public License as published by
#**  the Free Software Foundation, either version 3 of the License, or
#**  (at your option) any later version.
#**
#**  This program is distributed in the hope that it will be useful,
#**  but WITHOUT ANY WARRANTY; without even the implied warranty of
#**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#**  GNU General Public License for more details.
#**
#**  You should have received a copy of the GNU General Public License
#**  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#** -----------------------------------------------------------------------------**

#Replacing description and organization tags in STEP 3D files.
#Varicad outputs them as:
#...
#FILE_DESCRIPTION(
#/* description */ ('VariCAD 2010-3.03 AP-214'),
#/* implementation_level */ '2;1');
#
#FILE_NAME(
#/* name */ '0353-22-10-test-load-saved',
#/* time_stamp */ '2011-10-13T17:21:56-06:00',
#/* author */ (''),
#/* organization */ (''),
YEAR=`date +"%Y"`
DESCRIPTION="(C) Elphel, Inc. $YEAR. Licensed under CERN OHL v.1.1 or later, see http://ohwr.org/cernohl";
ORGANIZATION="Elphel, Inc";
process_step_files() {
#  DESCRIPTION="(C) Elphel, Inc. 2013. Licensed under CERN OHL v.1.1 or later, see http://ohwr.org/cernohl";
#  ORGANIZATION="Elphel, Inc";
  echo "Adding >$DESCRIPTION< and >$ORGANIZATION< to >$1<"
  mv $1 $1.original
  cat $1.original | sed -e "s#\* description \*/ [(]'[^']*'[)]#* description */ ('$DESCRIPTION')#g" | sed -e "s#\* organization \*/ [(]'[^']*'[)]#* organization */ ('$ORGANIZATION')#g" > $1
  tar -czvf $1.tar.gz $1
  mv $1.original $1
}
process_pdf_files() {
  if [ -z "`which pdftk`" ] ; then
    echo "pdftk is not installed, pdf metadata will not be edited. You may install pdftk with"
    echo "sudo apt-get install pdftk"
  else
   fullname=$(basename $1)
   filename=${fullname%.*}
   echo $filename
#cat  << EOF
cat >pdfmeta << EOF
InfoKey: Author
InfoValue: Elphel, Inc.
InfoKey: Title
InfoValue: $filename (C) Elphel, Inc. $YEAR
InfoKey: Subject
InfoValue: $DESCRIPTION
InfoKey: Producer
InfoValue: Qt 4.7.0 (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
EOF
  mv $1 $1~
  pdftk $1~ update_info pdfmeta output $1
  rm pdfmeta
  fi
}

if [ -n "$1" ]; then
  $@
  #  DESCRIPTION="(C) Elphel, Inc. 2013. Licensed under CERN OHL v.1.1 or later, see http://ohwr.org/cernohl";
  #  ORGANIZATION="Elphel, Inc";
  #  echo "Adding >$DESCRIPTION< and >$ORGANIZATION< to >$1<"
  #  mv $1 $1.original
  #  cat $1.original | sed -e "s#\* description \*/ [(]'[^']*'[)]#* description */ ('$DESCRIPTION')#g" | sed -e "s#\* organization \*/ [(]'[^']*'[)]#* organization */ ('$ORGANIZATION')#g" > $1
  #  tar -czvf $1.tar.gz $1
  #  mv $1.original $1
else
  #find . -maxdepth 1 -iname '*.stp' -exec $0 '{}' \;
  find . -maxdepth 1 -iname '*.stp' -exec $0 process_step_files '{}' \;
  find . -maxdepth 1 -iname '*.pdf' -exec $0 process_pdf_files '{}' \;
  find . -maxdepth 1 -iname '*.dxf' -exec tar '-czvf' '{}'.tar.gz '{}' \;
  find . -maxdepth 1 -iname '*.igs' -exec tar '-czvf' '{}'.tar.gz '{}' \;
  find . -maxdepth 1 -iname '*.dwb' -exec tar '-czvf' '{}'.tar.gz '{}' \;
  
  # Process all bmps
  # b - border size in pixels
  b=20
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
97
  for f in *.bmp *.jpg *.png
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
98 99 100 101 102 103
  do
    #if there are no *.bmp it still runs once?!
    if [ -f $f ]; then 
      filename=$(basename $f)
      name=${filename%.*}
      crop=`convert -trim -format %[fx:w+2*$b]x%[fx:h+2*$b]+%[fx:page.X-$b]+%[fx:page.Y-$b] $f info:`
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
104 105
      convert $f -crop $crop "$name.jpeg";
      convert "$name.jpeg" -resize 250 $name"_resized.jpeg"
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
106 107 108 109 110 111
    fi
  done
    
 exit 0
fi
#