Archive for November 16th, 2009

Today’s Business: 2009-11-16

Monday, November 16th, 2009

Today’s Chores

  • Cat duty
  • Showering
  • Checking for adequate supplies of Mom’s meds and reordering any we’re low on.  She needs none this week.

Log 

07:30 AM:  I’m up.  A bit sore in my legs and lower back from all the twisting and squatting yesterday building the ramp, overall, I feel great.

12:30 PM: Worked the   household organization    effort.

02:30 PM: Went on a   Thanksgiving shopping trip   today.

03:05 PM: Worked the   Thanksgiving dinner, 2009   effort.

04:55 PM: Worked   Garrett’s computer problem

06:00 PM: Worked the   household organization    effort again today.

07:30 PM: Watched today’s episode of  The Young and the Restless.

01:10 AM: Worked tonight on adding four new categories to this blog.  Click   here   for details.   I also classified (probably) a hundred posts into various categories.  Click   here   for details.

03:00 AM: Added the   Oatmeal and Parmesan Cheese   post to   this   blog.

03:10 AM: A busy day it was and I’m feeling the results.  *yawn*  So I’m off to bed.  Take care and I’ll write more later today.

Tom Hesley

Related Posts

Diary Revisions: 2009-11-16

Monday, November 16th, 2009

Today, I either added or modified the following posts in this blog for improved clarity, appearance, indexing, and search-ability:

http://TomsDiary.com/2002/01/12/transportation-in-altoona/
http://TomsDiary.com/2002/01/30/wpsbc-tid-bits/
http://TomsDiary.com/2002/03/28/updating-kc/
http://TomsDiary.com/2004/11/01/wpsbc-alumni-raffle/
http://TomsDiary.com/2005/11/27/getting-on-wpsbcs-web-site/
http://TomsDiary.com/2005/11/27/getting-on-wpsbc-web-site/
http://TomsDiary.com/2007/02/19/wpsbc-alumni-deaths/
http://TomsDiary.com/2007/04/24/wpsbc-alumni-web-site-9/
http://TomsDiary.com/2007/04/28/kc-retiring/
http://TomsDiary.com/2009/04/23/wpsbc-alumni-raffle-winners-2/
http://TomsDiary.com/2009/05/11/wpsbc-alumni-raffle-winners-3/
http://TomsDiary.com/2009/09/12/wpsbc-alumni-social/

 

Tom Hesley

Folder Sync Program

Monday, November 16th, 2009

I wrote this program in PERL several years ago to automate syncronization of the hard drives that hold my music library.  It works well, not only for music files, but any files that you might wish to copy from one hard drive to another.  See the comments in the code for more details.

#
# Author: Tommy’s Tunes Software
#
# Description:
#
# This program synchronizes a pair of directories.  One is called the source, and
# the other is called the destination directory.  The act of syncronizing
# accomplishes the following steps:
# 1) Creates any directories and subdirectories in the destination
#  directory which are found in the source directory but not the
#  destination.
# 2) Deletes any directories and subdirectories found in the destination
#  directory but not found in the source directory.
# 3) Copies any files from the source to the destination directory
#  (including files in subdirectories) that, either
#     a)   are found in the source but not the destination, or
#     b)  have differing modification time stamps.  That is, any
#   modified files since the last synchronization in the source
#   are copied to the destination.
#

# Set the source and destination directories.  Make sure that each of these has
# a trailing slash.
$gSrcDir =      ‘h:\\’;         # Source Directory
$gDestDir =     ‘g:\\’;         # Destination Directory
# Read the contents of the source and destination directories into lists.
print “Reading source directory: $gSrcDir . . . “;
my $srcFileListRef = {};
ReadDirectory($gSrcDir, $gSrcDir, $srcFileListRef);
print “Done.\n”;

print “Reading destination directory: $gDestDir . . . “;
my $destFileListRef = {};
ReadDirectory($gDestDir, $gDestDir, $destFileListRef);
print “Done.\n”;

# Compare the directories and note any files (or directories) that exist
# in one but not the other.
print “Synchronizing the source and destination directories. . .\n”;
SyncDirectories($gSrcDir, $srcFileListRef, $gDestDir, $destFileListRef);
print “Done.\n”;
exit 0;
################################
# Copies a directory or a file (whose complete path is supplied in the $itemToCopy
# parameter) to the destination directory as specified in the $destDir parameter.
#
sub CopyItem
{
my $srcDir  = shift;
my $itemToCopy = shift;
my $itemMode = shift;
my $destDir  = shift;

# If the item is a file, then copy the file.  If it’s a directory, then
# copy the directory.
my $destItemPath = $destDir . “\\” . $itemToCopy;
my $entryType = $itemMode & 040000;
if($entryType)
{
print “Making directory $destItemPath\n”;
system(“mkdir”, “$destItemPath”);
}
else
{
my $srcItemPath = $srcDir . “\\” . $itemToCopy;
print “Copying file $srcItemPath to $destDir\n”;
system(“copy”, $srcItemPath, $destItemPath);
}
}

################################
# Deletes a directory or a file (whose relative path is supplied in the
# $itemToDelete parameter) fromthe destination directory as specified in the
# $destDir parameter.
#
sub DeleteItem
{
my $destDir  = shift;
my $itemToDelete = shift;
my $itemMode = shift;

# If the item is a file, then delete the file.  If it’s a directory, then
# remove the directory.

# Also, if the destination directory is the root directory of a drive
# (its path ends with a \ character), then do not include a backslash
# between the destination directory and the relative path to the file
# to delete.  Otherwise, include the backslash.
my $destItemPath;
my $ch = substr($destDir, ((length $destDir) – 1));
if($ch eq “\\”)
{
$destItemPath = $destDir . $itemToDelete;
}
else
{
$destItemPath = $destDir . “\\” . $itemToDelete;
}
my $entryType = $itemMode & 040000;
if($entryType)
{
print “Deleting directory $destItemPath\n”;
# Remove the directory using rmdir with /S to remove all subdirectories
# and files in the target directory, and /Q to keep rmdir from asking
# whether or not to delete a particular item.
system(‘rmdir’, “/S/Q”, $destItemPath);
}
else
{
print “Deleting file $destItemPath from $destDir\n”;
system(“del”, “\”$destItemPath\”");
}
}

##################################
#
sub SyncDirectories
{
my $srcDir  = shift;
my $srcFileListRef = shift;
my $destDir  = shift;
my $destFileListRef = shift;

my $item;
my $key;

# Check for any files in the destination list but not in the src list, and
# delete those files from the destination directory.  We use the ‘reverse’
# command here so that the files in a directory are deleted first, and then
# the directory itself.  This step should come before new files are
# copied to the destination, to assure that the most space will be
# available for the new files (that vacated by the old files).
print “Deleting old items from the destination directory.\n”;
foreach $key (reverse sort keys %$destFileListRef)
{
if(!exists $srcFileListRef->{$key})
{
# Delete the file.
DeleteItem($destDir, $key, $destFileListRef->{$key}->{MODE});
delete $destFileListRef->{$key};
}
} # for(…)
# Check for
# - Any files in the src list but not in the destination list  OR
# - Files that do exist in both lists but whose modification time stamps
#   differ.
#
# copy those that meet either of the above conditions from the source to the
# destination directory.
#
print “Copying new items from source to destination directory.\n”;
foreach $key (sort keys %$srcFileListRef)
{
#       print “Key = $key\n”;
# If the file does not exist in the destination directory, then
# copy if there from the source directory.
if(!exists($destFileListRef->{$key}))
{
# Copy the file, if a file, or create the directory in the
# destination, if a directory.
$item = $srcFileListRef->{$key}->{RPATH};
CopyItem($srcDir,
$item,
$srcFileListRef->{$key}->{MODE},
$destDir);
$destFileListRef->{$key}->{MODE} = $srcFileListRef->{$key}->{MODE};
$destFileListRef->{$key}->{MTIME} = $srcFileListRef->{$key}->{MTIME};
$destFileListRef->{$key}->{RPATH} = $srcFileListRef->{$key}->{RPATH};
$destFileListRef->{$key}->{SIZE} = $srcFileListRef->{$key}->{SIZE};
}
} # for(…)

# Check for any files in the src directory whose modification timestamp or
# size differs from the corresponding file in the destination directory, and
# copy the file from the source to the destination if a difference is found.
print “Copying modified items from source to destination directory.\n”;
foreach $key (sort keys %$srcFileListRef)
{
if($key =~ /RECYCLER/)
{
next;
}

my $entryType = $srcFileListRef->{$key}->{MODE} & 040000;
if( ($srcFileListRef->{$key}->{MTIME} != $destFileListRef->{$key}->{MTIME})  &&
(!$entryType))
{
# Copy the file, if a file,
$item = $destFileListRef->{$key}->{RPATH};
CopyItem($srcDir,
$item,
$srcFileListRef->{$key}->{MODE},
$destDir);
$destFileListRef->{$key}->{MODE} = $srcFileListRef->{$key}->{MODE};
$destFileListRef->{$key}->{MTIME} = $srcFileListRef->{$key}->{MTIME};
$destFileListRef->{$key}->{RPATH} = $srcFileListRef->{$key}->{RPATH};
$destFileListRef->{$key}->{SIZE} = $srcFileListRef->{$key}->{SIZE};
}
} # for(…)
}

#############################
#
sub ReadDirectory
{
# Open the directory.
my $dir   = shift;
my $baseDir  = shift;
my $fileListRef  = shift;

my $currentFile;
my $dirHandle;
my $filePath;
my $listEntry;
opendir $dirHandle, $dir ||
die “Unable to open directory: $dir\n”;

while($currentFile = readdir $dirHandle)
{
if(($currentFile eq “.”)           or
($currentFile eq “..”)          or
($currentFile =~ /RECYCLER/))
{
next;
}

$filePath = $dir . “\\” . $currentFile;
# Get information about each file read.
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) =
stat $filePath;

# Remove the base directory (if any) from the file path, making it
# a relative path.
my $relativeFilePath = substr($filePath, (length $baseDir) + 1);
my $key = lc $relativeFilePath;
#       print “$key\n”;
$fileListRef->{$key}->{MODE} = $mode;
$fileListRef->{$key}->{MTIME} = $mtime;
$fileListRef->{$key}->{RPATH} = $relativeFilePath;
$fileListRef->{$key}->{SIZE} = $size;
#       print “Relative path: $fileListRef->{$key}->{RPATH} \n”;

my $entryType = $mode & 040000;
if($entryType)
{
#           print “===== Processing subdirectory: $filePath ===========\n”;
ReadDirectory($filePath, $baseDir, $fileListRef);
}
else
{
#           print “===== Processing file: $filePath with type: “;
#           printf “%o”, $entryType;
#           print ” =====\n”;
}
#       print “=============== Done ====================\n”;
}  # End while
closedir $dirHandle;
}  # End ReadDirectory()
__END__

 

Tom Hesley

Related Posts

WPSBC Category Beefed Up

Monday, November 16th, 2009

I added tens of posts to the   WPSBC   category in the   Tom’s Diary    blog.   Check them out.

Tom Hesley

Related Posts

New Categories: 2009-11-16

Monday, November 16th, 2009

Tonight, I added the following new categories to the    Tom’s Diary   blog:

I’ve applied these to the relevant posts as well.

Tom Hesley

Related Posts

Thanksgiving Shopping Trip

Monday, November 16th, 2009

Sister Mary Ann and I made this trip today to purchase food and other essentials for the   Thanksgiving dinner, 2009   project.  We purchased the following:

  • Vanity Fair white napkins (1 pack of 40)
  • Yams (5 pounds)
  • Lestoil (48 Oz. bottle)
  • Idaho potatoes (10 pounds)
  • Wright’s silver polish (1 container)
  • Bruce cut yams (1 can)
  • Marshmallow cream (1 small jar) (for the yams)
  • Del Monte whole kernel corn (4 cans)
  • Sargento thin-sliced Swiss cheese (1 bag)
  • Idahoin instant mashed potatoes (1 box)
  • Cranberry (jellied) Sauce (4 cans)
  • Altoona Mirror newspaper (1 copy) (for Mom)

 

Total cost: $37.11

Tom Hesley

Related Posts

Mom’s Status: 2009-11-16

Monday, November 16th, 2009

Log

07:00 AM: Blood sugar: 151.  Covered this and two slices of toast and a glass of orange juice with 12 units of log insulin.

12:00 PM: Blood sugar: 231.  Covered with 14 units of log insulin.

01:00 PM: She ate lunch.

05:30 PM: Blood sugar: 139.

10:00 PM: Blood sugar: 109.

Tom Hesley

Related Posts