[Bins] bins-1.29 album injection feature implemented
Corporate Gadfly
corporate_gadfly at hotmail.com
Mon Feb 19 21:52:45 GMT 2007
Hi bins users,
Today I would like to solicit some feedback regarding the attached patch.
The patch implements an "injection" feature so that the entire album is not
rebuilt from scratch if you are only trying to inject a subdirectory. I have
gotten good results from it so far. An album with ~1600 pictures used to
take around 7 minutes to build. Now with the inject feature the album with a
newly injected directory is built in less than 2 minutes.
* Patch is against 1.29 with the memory leak patch applied already (previous
post)
* Typical usage is:
bins -j ~/inject_originals/a1/a2/b3 ~/inject_originals
~/inject_albums
where -j specifies the album to inject into the album tree
* It will generate from scratch at least the following files:
* all files related to the inject directory itself
* imagelist.html for 1-level up
* index.html for 1-level up and 2-level up
* thumb*.html for 1-level up
* tree.html
* Anything else in the above list is not touched (it assumes they are there)
* All files that are untouched will have the old "generated on" timestamp
There are various places in generateImagesInAlbum() where I couldn't quite
skip all the scaling/sizing operations. Perhaps someone more knowledgable
can chime in.
Feedback and comments are welcome.
--
Haroon
Here is the patch inline as well:
--- /home/haroon/sbin/bins-1.29 2007/02/12 19:47:00 1.3
+++ /home/haroon/sbin/bins-1.29 2007/02/19 21:32:00
@@ -399,6 +399,10 @@
# strings on console and to
# convert strings from .po
# files.
+
+ injectDir => '', # directory to be injected
+ # without rebuilding complete
+ # album
);
my $codeset;
@@ -975,7 +979,7 @@
Getopt::Long::Configure("bundling");
die "Invalid options\n"
if (!GetOptions(\%option, "h", "p", "r:s", "e", "o:s", "t=s",
"d=s", "s=s",
- "c=s", "v:i", "i=s", "n=s", "f=s"));
+ "c=s", "v:i", "i=s", "n=s", "f=s", "j=s"));
if (defined($option{v})) {
$verbose = $option{v};
@@ -1131,6 +1135,25 @@
die "albumdir_dir ($albumdir) can't be a subdirectory of picdir_dir
($picdir)"
if ($albumdir2 =~ m/^$picdir2\//);
+
+ if( defined $option{j} ) {
+ my $injectDir = $option{j};
+ my $injectExists = 1;
+
+ chdir $injectDir or warn "Can't chdir $injectDir: $!" and
$injectExists = 0;
+
+ if( $injectExists ) {
+ $injectDir = File::Spec->rel2abs(".") unless -l $option{j};
+ chdir $pwd;
+ }
+
+ die "inject_dir (specified via -j parameter) $option{j} must be
a subdirectory of pic_dir ($picdir)"
+ unless $injectDir =~ m#^$picdir2/.*#;
+
+ $configHash->{injectDir}
+ = File::Spec->rel2abs(File::Spec->canonpath($injectDir));
+ $configHash->{injectDir} .= '/'; # add trailing slash
+ }
}
$picdir = File::Spec->rel2abs(File::Spec->canonpath($picdir));
@@ -2162,6 +2185,16 @@
sub generateImageListPage{
my ($album, $albumHashRef, $imageDataRef, $xlinksRef, $configHash) =
@_;
+ if( $configHash->{injectDir} ne '' ) {
+ my $injectDir = $configHash->{injectDir};
+ my $oneDirUp;
+ # drop the last subdirectory
+ ( $oneDirUp = $configHash->{injectDir} ) =~ s#(.*/).*?/$#$1#o;
+ my $dir = $picdir . $album;
+ # Only generate imagelist page during injection
+ # for 1-level-up or injected album itself
+ return unless $dir =~ m#($oneDirUp|$injectDir)$#;
+ }
my %albumHash = %{$albumHashRef};
my @imageData = @{$imageDataRef};
my $pwd;
@@ -2372,6 +2405,18 @@
sub generateLongSubAlbumPage{
my ($album, $albumHashRef, $configHash) = @_;
+ if( $configHash->{injectDir} ne '' ) {
+ my $injectDir = $configHash->{injectDir};
+ my( $oneDirUp, $twoDirUp );
+ # drop the last subdirectory
+ ( $oneDirUp = $configHash->{injectDir} ) =~ s#(.*/).*?/$#$1#o;
+ # drop the last subdirectory
+ ( $twoDirUp = $oneDirUp ) =~ s#(.*/).*?/$#$1#o;
+ my $dir = $picdir . $album;
+ # Only generate subalbum page during injection for
+ # 1-level-up or 2-level-up or injected album itself
+ return unless $dir =~ m#($oneDirUp|$twoDirUp|$injectDir)$#;
+ }
my %albumHash = %{$albumHashRef};
# hash for final subsitutions
@@ -2652,6 +2697,18 @@
my ($album, $albumHashRef, $firstIsIndex, $configHash,
$xlinkListRef,
@imageData) = @_;
+
+ if( $configHash->{injectDir} ne '' ) {
+ my $injectDir = $configHash->{injectDir};
+ my $oneDirUp;
+ # drop the last subdirectory
+ ( $oneDirUp = $configHash->{injectDir} ) =~ s#(.*/).*?/$#$1#o;
+ my $dir = $picdir . $album;
+ # Only generate thumbnail page during injection for
+ # 1-level-up or injected album itself
+ return unless $dir =~ m#($oneDirUp|$injectDir)$#;
+ }
+
my @xlinkList=@$xlinkListRef;
my %albumHash = %{$albumHashRef};
my $numImages = scalar(@imageData); #element count
@@ -3067,6 +3124,13 @@
my ($album, $albumHashRef, $firstIsIndex,
$configHash, @imagesToDisplay) = @_;
+ my $skipDueToInjection = 0;
+
+ if( $configHash->{injectDir} ne '' ) {
+ # skip processing of images unless processing injected directory
+ $skipDueToInjection = 1 unless $picdir . $album eq
$configHash->{injectDir};
+ }
+
# an array of references to hashes storing information about each image
my @imageData;
@@ -3322,10 +3386,12 @@
$imageData[$i]{'detailsLink'} =
generateSecondaryFieldsPage($imageData[$i], $album,
$albumHashRef,
$crntImageBase.$crntImageType,
- $configHash);
+ $configHash)
+ unless $skipDueToInjection;
if ( $configHash->{searchEngine}) {
writeSearchString($imageData[$i], $configHash, $albumHashRef,
- $album);
+ $album)
+ unless $skipDueToInjection;
}
}
@@ -3333,6 +3399,7 @@
# now generate html
for ($i=0; $i<$numImages; $i++) {
+ last if $skipDueToInjection;
for (my $j=0; $j <= $imageData[$i]->{maxSize}; $j++) {
my $lastImageURL =
getHTMLImagePageLink($imageData[$numImages-1],
$j, $numImages-1);
_________________________________________________________________
The average US Credit Score is 675. The cost to see yours: $0 by Experian.
http://www.freecreditreport.com/pm/default.aspx?sc=660600&bcd=EMAILFOOTERAVERAGE
-------------- next part --------------
--- /home/haroon/sbin/bins-1.29 2007/02/12 19:47:00 1.3
+++ /home/haroon/sbin/bins-1.29 2007/02/19 21:32:00
@@ -399,6 +399,10 @@
# strings on console and to
# convert strings from .po
# files.
+
+ injectDir => '', # directory to be injected
+ # without rebuilding complete
+ # album
);
my $codeset;
@@ -975,7 +979,7 @@
Getopt::Long::Configure("bundling");
die "Invalid options\n"
if (!GetOptions(\%option, "h", "p", "r:s", "e", "o:s", "t=s",
"d=s", "s=s",
- "c=s", "v:i", "i=s", "n=s", "f=s"));
+ "c=s", "v:i", "i=s", "n=s", "f=s", "j=s"));
if (defined($option{v})) {
$verbose = $option{v};
@@ -1131,6 +1135,25 @@
die "albumdir_dir ($albumdir) can't be a subdirectory of picdir_dir
($picdir)"
if ($albumdir2 =~ m/^$picdir2\//);
+
+ if( defined $option{j} ) {
+ my $injectDir = $option{j};
+ my $injectExists = 1;
+
+ chdir $injectDir or warn "Can't chdir $injectDir: $!" and
$injectExists = 0;
+
+ if( $injectExists ) {
+ $injectDir = File::Spec->rel2abs(".") unless -l $option{j};
+ chdir $pwd;
+ }
+
+ die "inject_dir (specified via -j parameter) $option{j} must be
a subdirectory of pic_dir ($picdir)"
+ unless $injectDir =~ m#^$picdir2/.*#;
+
+ $configHash->{injectDir}
+ = File::Spec->rel2abs(File::Spec->canonpath($injectDir));
+ $configHash->{injectDir} .= '/'; # add trailing slash
+ }
}
$picdir = File::Spec->rel2abs(File::Spec->canonpath($picdir));
@@ -2162,6 +2185,16 @@
sub generateImageListPage{
my ($album, $albumHashRef, $imageDataRef, $xlinksRef, $configHash) =
@_;
+ if( $configHash->{injectDir} ne '' ) {
+ my $injectDir = $configHash->{injectDir};
+ my $oneDirUp;
+ # drop the last subdirectory
+ ( $oneDirUp = $configHash->{injectDir} ) =~ s#(.*/).*?/$#$1#o;
+ my $dir = $picdir . $album;
+ # Only generate imagelist page during injection
+ # for 1-level-up or injected album itself
+ return unless $dir =~ m#($oneDirUp|$injectDir)$#;
+ }
my %albumHash = %{$albumHashRef};
my @imageData = @{$imageDataRef};
my $pwd;
@@ -2372,6 +2405,18 @@
sub generateLongSubAlbumPage{
my ($album, $albumHashRef, $configHash) = @_;
+ if( $configHash->{injectDir} ne '' ) {
+ my $injectDir = $configHash->{injectDir};
+ my( $oneDirUp, $twoDirUp );
+ # drop the last subdirectory
+ ( $oneDirUp = $configHash->{injectDir} ) =~ s#(.*/).*?/$#$1#o;
+ # drop the last subdirectory
+ ( $twoDirUp = $oneDirUp ) =~ s#(.*/).*?/$#$1#o;
+ my $dir = $picdir . $album;
+ # Only generate subalbum page during injection for
+ # 1-level-up or 2-level-up or injected album itself
+ return unless $dir =~ m#($oneDirUp|$twoDirUp|$injectDir)$#;
+ }
my %albumHash = %{$albumHashRef};
# hash for final subsitutions
@@ -2652,6 +2697,18 @@
my ($album, $albumHashRef, $firstIsIndex, $configHash,
$xlinkListRef,
@imageData) = @_;
+
+ if( $configHash->{injectDir} ne '' ) {
+ my $injectDir = $configHash->{injectDir};
+ my $oneDirUp;
+ # drop the last subdirectory
+ ( $oneDirUp = $configHash->{injectDir} ) =~ s#(.*/).*?/$#$1#o;
+ my $dir = $picdir . $album;
+ # Only generate thumbnail page during injection for
+ # 1-level-up or injected album itself
+ return unless $dir =~ m#($oneDirUp|$injectDir)$#;
+ }
+
my @xlinkList=@$xlinkListRef;
my %albumHash = %{$albumHashRef};
my $numImages = scalar(@imageData); #element count
@@ -3067,6 +3124,13 @@
my ($album, $albumHashRef, $firstIsIndex,
$configHash, @imagesToDisplay) = @_;
+ my $skipDueToInjection = 0;
+
+ if( $configHash->{injectDir} ne '' ) {
+ # skip processing of images unless processing injected directory
+ $skipDueToInjection = 1 unless $picdir . $album eq
$configHash->{injectDir};
+ }
+
# an array of references to hashes storing information about each image
my @imageData;
@@ -3322,10 +3386,12 @@
$imageData[$i]{'detailsLink'} =
generateSecondaryFieldsPage($imageData[$i], $album,
$albumHashRef,
$crntImageBase.$crntImageType,
- $configHash);
+ $configHash)
+ unless $skipDueToInjection;
if ( $configHash->{searchEngine}) {
writeSearchString($imageData[$i], $configHash, $albumHashRef,
- $album);
+ $album)
+ unless $skipDueToInjection;
}
}
@@ -3333,6 +3399,7 @@
# now generate html
for ($i=0; $i<$numImages; $i++) {
+ last if $skipDueToInjection;
for (my $j=0; $j <= $imageData[$i]->{maxSize}; $j++) {
my $lastImageURL =
getHTMLImagePageLink($imageData[$numImages-1],
$j, $numImages-1);
More information about the Bins
mailing list