UserPreferences

makePyroDevices.bash


#!/bin/bash

# makePyroDevices.bash
# Create a Pyro device file for each fake camera.

BASEPATH="/mnt/uba1/FakeCameras"

cd FakeCameras
DIRS=$(ls)

for DIR in $DIRS
do
  cd $DIR
  SUBDIRS=$(ls)

  for SUBDIR in $SUBDIRS
  do
    cd $SUBDIR

    DEVFILE=$DIR"_"$SUBDIR".py"
    if [ -e $DEVFILE ]
    then
      rm $DEVFILE
    fi

    FILES=$(ls)
    FIRST=$(echo $FILES | cut -f1 -d' ')
    STARTNUM=$(expr 0 + $(echo $FIRST | cut -f3 -d'_' | cut -f1 -d'.'))
    LAST=$(echo $FILES | cut -f6 -d' ')
    STOPNUM=$(expr 0 + $(echo $LAST | cut -f3 -d'_' | cut -f1 -d'.'))

    echo "# FakeCamrea device for " $DIR/$SUBDIR > $DEVFILE
    echo "from pyrobot.camera.fake import FakeCamera" >> $DEVFILE
    echo "from pyrobot.vision.cvision import VisionSystem" >> $DEVFILE
    echo "" >> $DEVFILE
    echo "def INIT(robot):" >> $DEVFILE
    echo "    return {'camera': FakeCamera(" >> $DEVFILE

    IMGNAME=$(echo $FIRST | cut -f2 -d'_')
    PATTERN=$BASEPATH"/"$DIR"/"$SUBDIR"/"$SUBDIR"_"$IMGNAME"_???.ppm"

    echo "    pattern='"$PATTERN"'," >> $DEVFILE
    echo "    start="$STARTNUM"," >> $DEVFILE
    echo "    stop="$STOPNUM"," >> $DEVFILE
    echo "    interval=1," >> $DEVFILE
    echo "    visionSystem = VisionSystem())" >> $DEVFILE
    echo "    }" >> $DEVFILE

    cd ..

  done
  cd ..
done