February 6th, 2010
I wanted to copy some files from one directory to another while I am working on my wordpress blog-in-blog plugin. Basically I needed to copy the files checked out from svn, from the working directory, to the root of the web directory on my local machine.
Feature requirements:
- Should only move a file if it has been edited. (we assume that the filesize will have changed by at least 1 byte!)
- Should not just sit there copying all the time.
- Should find out about all files in the specified directory.
- Should report when it updated the file and which file was updated
- First run should copy all files to the destination directory. (assumes I have updated my working copy from svn)
So after several attempts, here is a more polished version which stores the filename and the last size of the file in a ‘bash hash’. OK bash doesn’t have hashes (mores the pity) but reading around on the web I found this post with a comment from Scott Mcdermott which does the job nicely (once I had stripped offending characters from the file names).
So here is the full code of the deployment assistant:
#!/bin/bash
# script to deploy code from SOURCEDIR to DELIVERDIR
PROJECTNAME="blog-in-blog"
SOURCEDIR=blog-in-blog/trunk
DELIVERDIR=/var/www/wordpress/wp-content/plugins/blog-in-blog/
FILENAMES=blog-in-blog/trunk/*
LASTFILESIZE=0
COUNTER=1
echo "======================================================"
echo -e "delivering changes \n\tin \033[1m$SOURCEDIR\033[0m \n\tto \033[1m$DELIVERDIR\033[0m"
echo "======================================================"
if [ -z $1 ]
then
echo "usage$ $0 "
exit 1
fi
hash_insert ()
{
local name=$1 key=$2 val=$3
eval __hash_${name}_${key}=$val
}
hash_find ()
{
local name=$1 key=$2
local var=__hash_${name}_${key}
echo -n ${!var}
}
while true
do
for FILE in $FILENAMES
do
FILESIZE=$(stat -c%s "$FILE")
#tidy up file to avoid problems in variable name
FILE=`basename $FILE`
FILEORIG=$FILE
FILE=`echo "$FILE" | sed 's/[\.\_-]//g'`
LASTFILESIZE=`hash_find fileHash $FILE`
#echo "filesize:"$FILESIZE
#echo "lastfilesize:"$LASTFILESIZE
if [ "$FILESIZE" != "$LASTFILESIZE" ]
then
echo "--- $COUNTER ---------------------------------------"
date
echo -e "deploying \033[1m$FILEORIG\033[0m from project $PROJECTNAME"
echo "Size was $LASTFILESIZE bytes, now $FILESIZE bytes."
cp $SOURCEDIR/$FILEORIG $DELIVERDIR
hash_insert fileHash $FILE $FILESIZE
UPDATE=1
elif [ "$UPDATE" -ne "1" ]
then
UPDATE=0
fi
done
if [ "$UPDATE" = 1 ]
then
echo "======================================================"
let COUNTER+=1
UPDATE=0
fi
sleep $1
done
#ends
Posted in Everyday Life | No Comments »
January 30th, 2010
This animation is a test using a DV camera and a little script I wrote to control it.
Basically I wanted to be able to use my DV camera to take single frames, which could then be rolled into a finished video.
A little shell script follows, which does just what I need, using dvgrab and ffplay.
#!/bin/bash
# script to take a shot with DV camera
count=1
calldir=`pwd`
wrapdir='wraps'
function help_me
{
echo -e "HELP!"
echo -e "h - shows this help!"
echo -e "s - takes a shot"
echo -e "p - shows a preview of all the shots so far"
echo -e "w - writes the shots to a wrap file in ./$wrapdir"
echo -e "q - quits\n"
}
help_me
if [ ! -d $calldir/$wrapdir ] ; then
mkdir $calldir/$wrapdir || exit
fi
while [ "$ans" != "q" ]
do
echo -e "I'm waiting for instructions:(h|s|p|w|q)"
read -sn1 ans
if [ "$ans" = "h" ] ; then
help_me
elif [ "$ans" = "s" ] ; then
echo -e "grabbing a frame"
dvgrab --every 25 --duration 1 2>/dev/null
echo -e "grabbed $count\n\a"
count=$(($count+1))
elif [ "$ans" = "p" ] ; then
echo -e "Preview"
cat $calldir/*.dv | ffplay -
echo -e "Preview ended"
elif [ "$ans" = "w" ] ; then
echo -e "Wrapping up"
echo -e "Creating in in $calldir/$wrapdir"
echo -e "Enter filename for wrap:"
read filename
cd $calldir/$wrapdir || exit
cat $calldir/*.dv | dvgrab -stdin --format dv2 $filename 2>/dev/null
clear
# reset count after wrapping file
count=1
echo -e "Tidying up last wrap: deleting $calldir/*.dv"
rm $calldir/*.dv
echo -e "Preview wrap"
ffplay $calldir/$wrapdir/$filename*
echo -e "Preview wrap ended"
cd $calldir || exit
elif [ "$ans" = "q" ] ; then
echo -e "Quitting...\n"
exit
fi
done
Posted in Interupted, Technology, video | No Comments »
January 30th, 2010
A Day In The Life.
Posted in Everyday Life, video | No Comments »
December 30th, 2009
Do you remember those plastic floppy records? The ones that were sent with your new Hornby Train set? Well I found this one the other day in a 1979 Hornby Railways Catalogue. So I have recorded it for your delectation.
New Hornby train set – Bernard Cribbins
Posted in Everyday Life | Comments Off
November 18th, 2009
I have spent quite some time recently playing with audio on my ubuntu desktop.
Last time I tried Audio on linux I found it to be a sorely disappointing affair. That was some 6 to 12 months ago.
On my old Windows box I had an E-mu 1820, but when I bought it I didn’t know that Creative didn’t like to help out by open sourcing their drivers. (How many people have bought M-Audio cards now, knowing that they can get Open Source drivers for it!) On my old Windows box I thought that card was going to stay, until week before last…
I had had some recent successes with getting jack and pulseaudio playing nicely. I had had a play with Ardour and loved it. So I bit the bullet and gave it a go.
I now have glorious multi channel playback and recording via my E-mu audiodock, so I have taken the opportunity to throw together a few recordings of my poetry. The first couple were straight recordings with a bit of reverberation added for ambience.
Virility
The Tree I Wish I’d Been
The most recent is a full on four and a half minutes of sequenced sound and samples
A Rude Awakening
If you are viewing this on the site you’ll see the above links as little embedded mp3 players, courtesy of the very smart wpaudio plugin.
Posted in Everyday Life, Interupted, Technology | Comments Off