0
+ − 1 #!/usr/bin/perl
+ − 2 #
+ − 3 # CleanupGallery v0.1 for BINS
+ − 4 # Copyright (C) 2003 by Jochen Schaeuble <psionic@psionic.de>
+ − 5 #
+ − 6 # $Id: bins_cleanupgallery,v 1.3 2003/04/08 18:29:46 jerome Exp $
+ − 7 #
+ − 8 # This program is free software; you can redistribute it and/or modify
+ − 9 # it under the terms of the GNU General Public License as published by
+ − 10 # the Free Software Foundation; either version 2 of the License, or
+ − 11 # (at your option) any later version.
+ − 12 #
+ − 13 # This program is distributed in the hope that it will be useful,
+ − 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ − 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ − 16 # GNU General Public License for more details.
+ − 17 #
+ − 18 # You should have received a copy of the GNU General Public License
+ − 19 # along with this program; see the file COPYING. If not, write to
+ − 20 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 21 # Boston, MA 02111-1307, USA.
+ − 22
+ − 23 use File::Glob ':glob' ;
+ − 24
+ − 25 @knownImageExtentions = ( "jpg" , "jpeg" , "gif" , "png" , "tiff" ,
+ − 26 "bmp" , "tga" , "ps" , "eps" , "fit" , "pcx" ,
+ − 27 "miff" , "pix" , "pnm" , "rgb" , "im1" , "xcf" ,
+ − 28 "xwd" , "xpm" , "avs" , "dcm" , "dcx" , "dib" ,
+ − 29 "dps" , "dpx" , "epdf" , "epi" , "ept" , "fpx" ,
+ − 30 "icb" , "mat" , "mtv" , "pbm" , "pcd" , "pct" ,
+ − 31 "pdb" , "ppm" , "ptif" , "pwp" , "ras" , "thm" ,
+ − 32 );
+ − 33
+ − 34 $imageExts = join ( '|' , @knownImageExtentions );
+ − 35
+ − 36 @webFormats = ( "jpg" , "jpeg" , "gif" , "png" );
+ − 37 $webExts = join ( '|' , @webFormats );
+ − 38
+ − 39
+ − 40 sub ProcessDir
+ − 41 {
+ − 42 local * DIR ;
+ − 43 ( local $curdir , local $dstdir , local $srcdir ) = @_ ;
+ − 44
+ − 45 opendir ( DIR , "$dstdir/$curdir" );
+ − 46 while ( $file = readdir ( DIR )) {
+ − 47 $file = "$curdir/$file" ;
+ − 48
+ − 49 if ( - d "$dstdir/$file" && $file !~ m/\.\.?$/ && $file !~ m/static\.\w*$/ ) {
+ − 50 if ( - d "$srcdir/$file" ) {
+ − 51 # Directory exists in src and dest, process it
+ − 52 & ProcessDir ( $file , $dstdir , $srcdir );
+ − 53 } else {
+ − 54 # Directory only available in dest remove it
+ − 55 print "## Removing dir: $dstdir/$file\n" ;
+ − 56 `rm -Ri \"$dstdir/$file\"` ;
+ − 57 }
+ − 58 } elsif (( - f "$dstdir/$file" || - l "$dstdir/$file" ) &&
+ − 59 $file =~ m/.*\.($webExts)$/i ) {
+ − 60
+ − 61 my @srcfiles = bsd_glob ( "$srcdir/$curdir/*" ,
+ − 62 GLOB_NOCASE |
+ − 63 GLOB_QUOTE |
+ − 64 GLOB_TILDE );
+ − 65 $filefound = 0 ;
+ − 66 FILESEARCH:
+ − 67 foreach $curfile ( @srcfiles ) {
+ − 68 # remove trailing .xml
+ − 69 if ( $curfile =~ m/.*\.xml$/i ) {
+ − 70 $curfile =~ s/(.*)\.xml$/$1/i ;
+ − 71 }
+ − 72
+ − 73 # remove file extension
+ − 74 $curfile =~ s/.*\/([^\/]*)\.($imageExts)$/$1/i ;
+ − 75 if (( $curfile ne "" ) && ( $file =~ m/$curfile.*\.($webExts)$/i )) {
+ − 76 $filefound = 1 ;
+ − 77 last FILESEARCH ;
+ − 78 }
+ − 79 }
+ − 80 if ( $filefound == 0 ) {
+ − 81 $file =~ s/(.*)_\w+\.($webExts)$/$1/i ;
+ − 82 print "## Removing file: $dstdir/$file*\n" ;
+ − 83 `rm -v \"$dstdir/$file\"*` ;
+ − 84 }
+ − 85 }
+ − 86 }
+ − 87 closedir ( DIR )
+ − 88 }
+ − 89
+ − 90 sub usage
+ − 91 {
+ − 92 print "CleanupGallery v0.1 (c) 2003 by Jochen Schaeuble <psionic\@psionic.de\n" ;
+ − 93 print "\n" ;
+ − 94 print "This is free software with ABSOLUTELY NO WARRANTY.\n" ;
+ − 95 print "See COPYING file for details.\n\n" ;
+ − 96 print "Usage:\n\n" ;
+ − 97 print "cleanupgallery <Gallery Source Directory> <Destination Directory>\n" ;
+ − 98 print "\n" ;
+ − 99 exit ( 0 );
+ − 100 }
+ − 101
+ − 102 if ( $#ARGV != 1 || !- d $ARGV [ 0 ] || !- d $ARGV [ 1 ]) {
+ − 103 & usage ;
+ − 104 }
+ − 105 ( $srcdir , $dstdir ) = @ARGV ;
+ − 106
+ − 107 ProcessDir ( "" , $dstdir , $srcdir );