diff options
author | Denis Barbier <barbier> | 2001-09-04 00:29:32 +0000 |
---|---|---|
committer | Denis Barbier <barbier> | 2001-09-04 00:29:32 +0000 |
commit | 4b58eedc85da5eb101a4eb00a8c85d2021cb9a0e (patch) | |
tree | 09940aaf899d7808e9ef65469e2cc4f4e6eda8d8 /Perl/Webwml | |
parent | 02a1da72b4c48ca8732e67cf1a4c978adbe74f75 (diff) |
Read .transignore files in subdirectories and return list of files which
must not be considered when looking for outdated translations.
CVS version numbers
Perl/Webwml/TransIgnore.pm: INITIAL -> 1.1
Diffstat (limited to 'Perl/Webwml')
-rw-r--r-- | Perl/Webwml/TransIgnore.pm | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/Perl/Webwml/TransIgnore.pm b/Perl/Webwml/TransIgnore.pm new file mode 100644 index 00000000000..fd3f8e907b2 --- /dev/null +++ b/Perl/Webwml/TransIgnore.pm @@ -0,0 +1,184 @@ +#!/usr/bin/perl -w + +## Copyright (C) 2001 Denis Barbier <barbier@debian.org> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. + +=head1 NAME + +Webwml::TransIgnore - get list of files to ignore for translation + +=head1 SYNOPSIS + + use Webwml::TransIgnore; + my $ti = Webwml::TransIgnore->new("foo/bar"); + my @ignore = $ti->list(); + +=head1 DESCRIPTION + +This module searches for F<.transignore> files in directories and returns +files listed within. If a F<.transignore> file is found in top-level +directory, it contains files which must be ignored in all languages. + +=head1 METHODS + +=over 4 + +=cut + +package Webwml::TransIgnore; +use Carp; +use strict; +use Local::Cvsinfo; + +=item new + +This is the constructor. If called with an argument, it tells where to +find top-level webwml directory. Otherwise it is automatically +determined by parsing F<CVS/Repository>. + + my $ti = Webwml::TransIgnore->new("foo/bar"); + +=cut + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $dir = shift + or croak "Missing argument in Webwml::TransIgnore->new"; + my $self = { + GLOBAL => [], + LOCAL => [], + FOUND => 0, + }; + bless ($self, $class); + my $root; + if (@_) { + $root = shift; + } else { + my $cvs = Local::Cvsinfo->new(); + $cvs->readinfo('.'); + $root = $cvs->topdir() + or croak "Unable to determine top-level directory"; + } + # Read global .transignore file + $self->_read($root); + for (0 .. $#{$self->{LOCAL}}) { + ${$self->{LOCAL}}[$_] =~ s{^$root/}{}; + } + $self->{GLOBAL} = $self->{LOCAL}; + # reinitialize $self->{LOCAL} + $self->{LOCAL} = []; + # and read $dir/.transignore + $self->{FOUND} = $self->_read($dir); + return $self; +} + +sub _read { + my $self = shift; + my $dir = shift; + $dir .= "/"; + my $status = 0; + my $file = $dir . ".transignore"; + my $line; + splice (@{$self->{LOCAL}}, 0); + open(FILE, "< $file") or return 0; + while (<FILE>) { + next if m/^#/; + next if m/^\s*$/; + chomp; + push (@{$self->{LOCAL}}, $dir.$_); + } + close(FILE); + return 1; +} + +=item found + +Return 1 if .transignore file was found, 0 otherwise. + +=cut + +sub found { + my $self = shift; + return $self->{FOUND}; +} + +=item local + +Return the list of files found in F<.transignore> file. + + my @ignore = $ti->local(); + +=cut + +sub local { + my $self = shift; + return $self->{LOCAL}; +} + +=item global + +Return the list of files defined + + my @ignore = $ti->global(); + +=cut + +sub global { + my $self = shift; + return $self->{GLOBAL}; +} + +=item is_local + +Return 1 if argument is listed in .transignore, 0 otherwise + + my $rc = $ti->is_local("/foo/bar.wml"); + +=cut + +sub is_local { + my $self = shift; + my $entry = shift; + foreach (@{$self->{LOCAL}}) { + return 1 if $_ eq $entry; + } + return 0; +} + +=item is_global + +Return 1 if argument has been defined, 0 otherwise. + + my $rc = $ti->is_global("/foo/bar.wml"); + +=cut + +sub is_global { + my $self = shift; + my $entry = shift; + foreach (@{$self->{GLOBAL}}) { + return 1 if $_ eq $entry; + } + return 0; +} + +=back + +=head1 AUTHOR + +Copyright (C) 2001 Denis Barbier <barbier@debian.org> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +=cut + +1; + |