annotate tools/bins_cleanupgallery @ 5:e8a9408780ff

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