touch_files.pl 1.59 KB
Newer Older
1 2
#! /usr/bin/perl

Josip Rodin's avatar
Josip Rodin committed
3 4 5 6
# this script finds new files and touches old ones so that the list of
# languages at the bottom is updated to include the new file.
# or something like that. made by Joey.

7 8
%config = (
	   'wmldir'  => '/org/www.debian.org/webwml',
Josip Rodin's avatar
Josip Rodin committed
9
	   'datadir' => '/org/www.debian.org/cron/datafiles',
10 11 12 13 14 15 16 17 18 19 20 21
	   );

sub make_listing
{
    unlink ("$config{'datadir'}/wmlfiles.old") if (-f "$config{'datadir'}/wmlfiles.old");
    rename ("$config{'datadir'}/wmlfiles", "$config{'datadir'}/wmlfiles.old") if (-f "$config{'datadir'}/wmlfiles");
    system ("find . -type f -name '*.wml' | sort > $config{'datadir'}/wmlfiles");
}

sub obtain_files
{
    my @list;
22 23
    return unless -s "$config{'datadir'}/wmlfiles.old";
    return unless -s "$config{'datadir'}/wmlfiles";
24
    if (open (IN, "diff $config{'datadir'}/wmlfiles.old $config{'datadir'}/wmlfiles|")) {
25
	while (<IN>) {
26 27
	    next until (/^[<>] \.\//);
	    s/^[<>] \.\///;
28 29 30 31 32 33 34 35
	    chomp ();
	    push (@list, $_);
	}
	close (IN);
    }
    return @list;
}

36 37 38 39 40 41 42 43
chdir ($config{'wmldir'}) || die;

use Getopt::Std;
$opt_d = 0;
unless (getopts('d')) {
	print <<_END_;
Usage: $0 [-d]

44 45 46
This script finds new translations and translations that have been
removed and touches the translations so they rebuild and include a
link to the new ones and remove links to old ones.
47 48 49 50 51

  -d  Remove files, just not report.
_END_
	exit;
}
52 53 54

make_listing ();

55
@files = obtain_files ();
56

57
foreach $file (@files) {
58 59
    @components = split (/\//, $file);
    shift @components;
60 61 62 63 64
    my $cmd = "touch */" . join '/', @components;
    printf "$cmd\n";
    if ($opt_d) {
      system($cmd) == 0 or die;
    }
65
}