aboutsummaryrefslogtreecommitdiffstats
path: root/remove_stale.pl
diff options
context:
space:
mode:
authorPeter Karlsson <peterk>2001-03-22 22:22:00 +0000
committerPeter Karlsson <peterk>2001-03-22 22:22:00 +0000
commitc71f6968357774d72189afa23851a4e1f512f475 (patch)
treee535c9f1128f6e019de1c56b412ca9efd66dc4f6 /remove_stale.pl
parent3b69a28584912d7b869b574317c5397301a54b18 (diff)
Added script that goes through all the translation directories and locates
all .lang.html files that have no corresponding WML file, or is not itself directly entered into the CVS. Running this after each CVS update means that removing WML files from the CVS will cause their corresponding HTML files to disappear as well. CVS version numbers remove_stale.pl: INITIAL -> 1.1
Diffstat (limited to 'remove_stale.pl')
-rwxr-xr-xremove_stale.pl137
1 files changed, 137 insertions, 0 deletions
diff --git a/remove_stale.pl b/remove_stale.pl
new file mode 100755
index 00000000000..1157ed996aa
--- /dev/null
+++ b/remove_stale.pl
@@ -0,0 +1,137 @@
+#!/usr/bin/perl -w
+
+# This script searches through all the translation directories for HTML
+# files not having a matching WML file, and removes those HTML files from
+# both the local directory and the install directory. This is needed so that
+# a removing a WML file from CVS causes the corresponding HTML file to go
+# away.
+
+# Written 2001-03-22 by peter karlsson <peterk@debian.org>
+# © Copyright 2001 Software in the public interest, Inc.
+# This program is released under the GNU General Public License, v2.
+
+# $Id$
+
+use strict;
+use vars qw($opt_d);
+use Getopt::Std;
+
+unless (-d 'english' && getopts('d'))
+{
+ print "Usage: $0 [-d]\n\n";
+ print "Run this script from the webwml directory to remove stale HTML files.\n\n";
+ print " -d Remove files, just not report.\n";
+ exit;
+}
+
+# Recurse.
+&recurse('.');
+
+# Done.
+exit;
+
+# The function that does the heavy work, recursing down the directory tree.
+sub recurse
+{
+ # Get parameter.
+ my $directory = shift;
+
+ # Don't try to do anything in the WNPP and l10n directories.
+ return if $directory =~ /wnpp$/ or $directory =~ /l10n$/;
+
+ # Load all entries for this directory.
+ opendir THISDIR, $directory
+ or die "Unable to open directory $directory: $!\n";
+ my @entries =
+ map { $directory . '/' . $_ } grep { !/^\./ } readdir(THISDIR);
+ closedir THISDIR;
+
+ # Read through the CVS/Entries file.
+ open ENTRIES, "$directory/CVS/Entries"
+ or die "Not a CVS directory: $directory\n";
+
+ my @wmlfiles = ();
+ my @htmlfiles = ();
+ while (<ENTRIES>)
+ {
+ if (m'^/([^/]+.wml)/[0-9\.]+/.*/.*/$')
+ {
+ push @wmlfiles, $directory . '/' . $1;
+ }
+ elsif (m'^/([^/]+.html)/[0-9\.]+/.*/.*/$')
+ {
+ push @htmlfiles, $directory . '/' . $1;
+ }
+ }
+
+ # Locate all HTML files, and find out which ones do not correspond
+ # to a WML file, and does not live in the CVS by itself.
+ my @subdirs = ();
+ my $direntry;
+ foreach $direntry (@entries)
+ {
+ if (-f $direntry && $direntry =~ /\.html$/)
+ {
+ my ($haswml, $incvs) = (0, 0);
+
+ # Check for WML file.
+ my $source = $direntry;
+ $source =~ s/\...(-..)?\.html$/.wml/;
+ my $wmlfile;
+ WMLS: foreach $wmlfile (@wmlfiles)
+ {
+ $haswml = 1, last WMLS
+ if $wmlfile eq $source;
+ }
+
+ unless ($haswml)
+ {
+ # Check if HTML file is in CVS by itself.
+ my $htmlfile;
+ HTMLS: foreach $htmlfile (@htmlfiles)
+ {
+ $incvs = 1, last HTMLS
+ if $htmlfile eq $direntry;
+ }
+ }
+
+ unless ($haswml || $incvs)
+ {
+ # File has no reason for being here.
+
+ # Name of file installed by make install.
+ my $installed = $direntry;
+ $installed =~ s(^\./[^/]*/)(../debian.org/);
+
+ # Remove or report.
+ if ($opt_d)
+ {
+ print "$direntry is stale ... removing\n";
+ unlink $direntry
+ or die "Unable to remove $direntry: $!\n";
+ print " also removing $installed\n";
+ unlink $installed
+ or die "Unable to remove $installed: $!\n";
+ }
+ else
+ {
+ print "$direntry is stale (use -d to remove)\n";
+ print " installed file is $installed\n";
+ print " (does not exist)\n"
+ unless -f $installed;
+ }
+ }
+ }
+ elsif (-d $direntry && !($direntry =~ /CVS$/))
+ {
+ push @subdirs, $direntry;
+ }
+ }
+
+ # Recurse into subdirectories.
+ my $subdir;
+ foreach $subdir (@subdirs)
+ {
+ recurse($subdir);
+ }
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy