diff options
author | Thomas Lange <lange@debian.org> | 2022-09-16 00:14:04 +0200 |
---|---|---|
committer | Thomas Lange <lange@debian.org> | 2022-09-16 00:14:04 +0200 |
commit | bd730b5b2fadf68e61565612a9f3a065eed9fa72 (patch) | |
tree | 2c2b9d96993a9ae7d49bc231c4808cd371defa4c /english/international | |
parent | 156c07cf2bbdaa79a9502bad0854a469b4cdc5e6 (diff) |
remove unused script
Diffstat (limited to 'english/international')
-rwxr-xr-x | english/international/l10n/scripts/transmonitor-check2 | 813 |
1 files changed, 0 insertions, 813 deletions
diff --git a/english/international/l10n/scripts/transmonitor-check2 b/english/international/l10n/scripts/transmonitor-check2 deleted file mode 100755 index 59bb9b8e356..00000000000 --- a/english/international/l10n/scripts/transmonitor-check2 +++ /dev/null @@ -1,813 +0,0 @@ -#!/usr/bin/perl -w - -# THIS GILE HAS BEEN RENAMED INTO transmonitor-check PLEASE DO -# NOT WORK ON IT -# -# transmonitor-check2 -- l10n checker script -# -# This script parses Debian source packages and extract l10n stuff -# -# This script is a heavily stripped down version of transmonitor-check -# (originally written by Martin Quinson), which has been rewritten to -# improve its modularity. Missing features will be put back later. -# This is a work in progress, and this file will be renamed into -# transmonitor-check when it is fully usable; in the meantime do -# not use it unless you really know what you are doing. -# -# Copyright (C) 1999-2001 Martin Quinson. -# Copyright (C) 2001 Denis Barbier -# -# 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. - -use strict; -use File::Path; -use Getopt::Long; - -use lib ($0 =~ m|(.*)/|, $1 or ".") ."/../../../../Perl"; -use Locale::Language; -use Locale::Country; -use Debian::L10n::Db; -use Local::Inside::DebSrc; -use Debian::L10n::Debconf; - -my $progname= $0; $progname= $& if $progname =~ m,[^/]+$,; - -$ENV{'LC_ALL'} = 'C'; # reset locale definition -$SIG{'INT'} = \&interrupted; -$SIG{'QUIT'} = \&interrupted; -sub interrupted { - $SIG{$_[0]} = 'DEFAULT'; - print "$progname: Interrupted.\n"; - exit -1; -} - - -####################################### -# Global Variables -####################################### -my $TRANSMONITOR_VERSION = "2.0"; #External Version Number -my $BANNER = "Translation Monitor v$TRANSMONITOR_VERSION"; # Version Banner - text form -my $TMP_DIR = "/tmp/transmonitor"; -my $DB_FILE = "../data/transmonitor"; -my $FROM_FILE = ""; -my $TRANSMONITOR_ROOT = "./"; -my $SYN_FILE = "../data/synonyms"; -my $PO_ROOT = "../po"; -my $TEMPLATES_ROOT = "../templates"; -my $MENU_ROOT ="../menu"; -my $verbose = 0; -my @debug; -my $force = 0; # if true, rescan package even if already in db -my $force_material = 0;# if true, rescan package containing material even if already in db -my $careful = 0; # if true, save the db after each package - -my @pkg_list; #were we put the list of packages we are required to test -my @pkg_errors; # were we put the name of packages with which we had an error -my @ftp_list; #were we put the list of ftp sites we are required to test -my @ftp_errors; # were we put the name of packages with which we had an error - -#---------------------------------------------------------------------------- -# Process Command Line -#---------------------------------------------------------------------------- -####################################### -# Subroutines called by various options -# in the options hash below. These are -# invoked to process the commandline -# options -####################################### -# Display Command Syntax -# Options: -h|--help -sub syntax_msg { - my $msg = shift; - if (defined $msg) { - print STDERR "$progname: $msg\n"; - } else { - print STDERR "$BANNER\n"; - } - print -"Syntax: $0 [action] [options] [--] [package|path to the dist]+ -General options: - -h, --help display short help text - -v, --verbose verbose messages - -V, --version display version and exit - -d, --debug turn debug messages ON - --print-version print unadorned version number and exit -Behaviour options: - --careful save the db file after each package proceeding - -f, --force force the check of packages, even if they are in db - --force-material force the check of packages containing any material -Configuration options: - -F, --files-from=FILE reads dsc filenames from FILE - --db=DB_FILE use DB_FILE as database file - (instead of $DB_FILE) - --tmp=TMP_DIR use TMP_DIR as temp dir - (instead of $TMP_DIR) - (warning, the script do 'rm -rf' on this dir!) - --po=PO_ROOT where to store the po files - (instead of $PO_ROOT) - --templates=DIR where to store the debconf templates files - (instead of $TEMPLATES_ROOT) - --menu=DIR where to store the menu files - (instead of $MENU_ROOT) - --root=ROOTDIR search the libs in ROOTDIR - (instead of $TRANSMONITOR_ROOT) - --syn=SYN_FILE use SYN_FILE as file of synonyms - (instead of $SYN_FILE) - (if no path specified, searched in ROOTDIR) -"; - if (defined $msg) { - exit 1; - } else { - exit 0; - } -} - -# Display Version Banner -# Options: -V|--version, --print-version -sub banner { - if ($_[0] eq 'print-version') { - print STDERR "$TRANSMONITOR_VERSION\n"; - } else { - print STDERR "$BANNER\n"; - } - exit 0; -} - -# Hash used to process commandline options -my %opthash = ( - # ------------------ general options - "help|h" => \&syntax_msg, - "version|V" => \&banner, - "print-version" => \&banner, - - "verbose|v" => \$verbose, - "debug|d" => \@debug, # Count the -d flags - - # ------------------ behaviour options - "careful" => \$careful, - "force|f" => \$force, - "force-material" => \$force_material, - - # ------------------ configuration options - "files-from=s" => \$FROM_FILE, - "db=s" => \$DB_FILE, - "tmp=s" => \$TMP_DIR, - "root=s" => \$TRANSMONITOR_ROOT, - "syn=s" => \$SYN_FILE, - "po=s" => \$PO_ROOT, - "templates=s" => \$TEMPLATES_ROOT, - "menu=s" => \$MENU_ROOT -); - -# init commandline parser -Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev'); - -# process commandline options -Getopt::Long::GetOptions(%opthash) - or syntax_msg("error parsing options"); - -#----------------------------------------------------------------------------- -# The main program -#----------------------------------------------------------------------------- -my %synonym; # developers can't spell sections and priorities... -my $savedb=0; # do we have to save the database? - -### -### Initialization -### -my @args = (); -if ($FROM_FILE ne '') { - if ($FROM_FILE eq '-') { - @args = <STDIN>; - } else { - open(FROM, "< $FROM_FILE") - || die "Unable to read from $FROM_FILE\n"; - @args = <FROM>; - close(FROM); - } -} -push (@args, @ARGV) or syntax_msg("Nothing to do !"); - -push (@INC, $TRANSMONITOR_ROOT); -init_synonym(); - -my $data = Debian::L10n::Db->new(); -$data->read($DB_FILE); -my $date = $data->get_date(); - -# read args to search package files -foreach my $arg (@args) { - chomp $arg; - if (-f $arg) { - $arg =~ /\.dsc$/ - || die "bad package file name $arg (not a .dsc file)"; - push @pkg_list, $arg; - } elsif (-d _) { - # dir ? let's do a `find -name "*.dsc"` on it! - open (LIST,"find $arg -name \"*.dsc\" -type f|") - || die "Can't run find: $!"; - while (<LIST>) { - push @pkg_list, $_; - } - close LIST; - } else { - die "bad argument $arg (neither a .dsc file nor a directory nor an ftp path)"; - } -} - -# -# main loop -# -my $dsc; # the path to the dsc file -my $pkg; # the package name -my $ver; # the package version -my $deb; # instance of Local::Inside::DebSrc -my @errors_pkg; # packages for which we had a problem - -PKG: while ($dsc = shift @pkg_list) { - ### - ### read the name and the version - ### - $pkg = ""; - $ver = ""; - unless (open (DESC, $dsc)) { - warn "Can't read file $dsc, skipped\n"; - next PKG; - } - while (<DESC>) { - if (m/^Source: (.*)$/) { - $pkg = $1; - } elsif (m/^Version: (.*)$/ && $ver eq "") { - $ver = $1; - } - } - close DESC; - if ($pkg eq "") { - warn "Can't read the package name from the desc file $dsc\n"; - push @errors_pkg, $pkg; - next PKG; - } elsif ($ver eq "") { - warn "Can't read the package version from the desc file $dsc\n"; - push @errors_pkg, $pkg; - next PKG; - } - - ### - ### if the package is already in the data, skip it - ### (unless force specified) - if ($data->has_package($pkg)) { - system ("dpkg","--compare-versions", $data->version($pkg), "\>", $ver); - if ((!$force) && $?==0 && $data->version($pkg) ne "" - && !( $force_material && - ($data->has_nls($pkg) - || $data->has_po($pkg) - || $data->has_templates($pkg)))) { - print STDERR "Package $pkg $ver (skipped)\n" - if ($verbose || ($data->version($pkg) ne $ver)); - next PKG; - } else { - # Erase this entry (it's an older version) - $data->clear_pkg($pkg); - foreach (($PO_ROOT,$TEMPLATES_ROOT,$MENU_ROOT)) { - File::Path::rmtree($_."/_tmp") - if -e $_."/_tmp"; - } - } - } else { - foreach (($PO_ROOT,$TEMPLATES_ROOT,$MENU_ROOT)) { - File::Path::rmtree($_."/_tmp") if -e $_."/_tmp"; - } - } - $savedb = 1; #ok, we've done something, we have to save the db - print STDERR "Package $pkg $ver (processing)\n" if $verbose; - - ### - ### unpack it - ### - $deb = parse_tarball($dsc, $pkg, $ver); - if ($deb) { - check_pkg($pkg, $deb); - if ($careful) { - $data->write($DB_FILE); - } else { - # Ok, we've done something, we have to save the db - $savedb = 1; - } - } -} - -$data->write($DB_FILE) if $savedb; -# print with which packages we had problems -if (@errors_pkg > 0) { - print STDERR "Some errors where encountred during the check of this packages\n"; - while ($pkg = shift @errors_pkg) { - print STDERR " $pkg\n"; - } -} - - -############################################################################## -# The subs # -############################################################################## - -sub store_disk_po { - my $pkg = shift; - my $filename = shift; - - my $dirname = $filename; - $dirname =~ s#/+[^/]*$##; - $filename =~ s#.*/##g; - $filename =~ s#:#\%3a#g; - return $dirname.'/'.$pkg.'_'.$data->version($pkg).'_'.$filename; -} - -sub store_disk_menu { - my $pkg = shift; - my $filename = shift; - - $filename =~ s#.*debian/##; - $filename =~ s#/#_#g; - $filename =~ s#:#\%3a#g; - return $pkg.'_'.$data->version($pkg).'_'.$filename; -} - -sub store_disk_templates { - my $pkg = shift; - my $filename = shift; - - $filename =~ s#/#_#g; - $filename =~ s#:#\%3a#g; - return $pkg.'_'.$data->version($pkg).'_'.$filename; -} - -### -### subs -### -sub parse_tarball { - my $path = shift; - my $pkg = shift; - my $version = shift; - my $patch = ''; - - $data->package($pkg, $pkg); - $data->version($pkg, $version); - $data->upstream($pkg, "debian"); - - # Determine how many characters of each files are read and cached - # when parsing the tar archive - # - # Files cannot be stored on their definitive location, - # since we do not know yet the package section, this - # information is read from debian/control. - # So they are stored in a temporary area, and moved away - # as soon as possible. - # - my $match = sub { - my $file = shift; - return 80 if $file =~ m#(^|/)nls/#; - return -1 if $file eq 'debian/control'; - return ":$PO_ROOT/_tmp/".store_disk_po($pkg, $file) - if $file =~ m#\.po$#; - return ":$MENU_ROOT/_tmp/".store_disk_menu($pkg, $file) - if $file =~ m#(^|/)debian/[^/]*menu[^/]*$#; - return ":$TEMPLATES_ROOT/_tmp/".store_disk_templates($pkg, $file) - if $file =~ m#(^|/)debian/([^/]+\.)?templates(\.|$)#; - return -1 if $file =~ m#(^|/)debian/[^/]*doc-base[^/]*$#; - - return 0; - }; - my $deb = Local::Inside::DebSrc->new($path, - parse_dft => $match, - patch_parse_dft => -1, - maxmem => 300000000, - debug => 0, - patch_debug => 0, - ); - unless ($deb) { - $data->clear_pkg($pkg); - warn "Package $pkg skipped because some file could not be retrieved\n"; - return undef; - } - - $data->upstream($pkg, "other") - if $deb->get_diff_name() ne ''; - $data->upstream($pkg, "dbs") - if $deb->file_matches("^debian/patches/"); - - #####[ search the section and priority]################################# - # - # (a LOT of packages place spaces here, or upper case, or even typos) - # - ##### - my $section = ""; - my $priority = ""; - my $pooldir = "main/"; - my $control = "debian/control"; - - unless ($deb->file_exists($control)) { - # The debian/ directory may be a link, search for - # debian/control elsewhere - my @list = $deb->file_matches('/debian/control$'); - if (@list) { - $control = $list[0]; - } else { - $data->clear_pkg($pkg); - warn("Error: can't find debian/control; skipping package $pkg."); - return undef; - } - } - $_ = $deb->file_content($control); - if (m/^Section: ([^\n]*)/m) { - $section = $1; - $section =~ s/\s//g; - } - if (m/^Priority: ([^\n]*)/m) { - $priority = $1; - $priority =~ s/\s//g; - } - if (defined($synonym{$section})) { - $section = $synonym{$section}; - if ($section =~ m#^(non-US/(contrib|non-free))#) { - $pooldir = $section."/"; - } elsif ($section =~ m#^non-US#) { - $pooldir = "non-US/main/"; - } elsif ($section =~ m#^(contrib|non-free)/#) { - $pooldir = $1."/"; - } - } else { - $data->add_errors($pkg,"'$section' is not a valid section\n"); - if ($section =~ m#^non-US/(contrib|non-free)#i) { - $section = "non-US/$1"; - $pooldir = $section."/"; - } elsif ($section =~ m#^non-US#i) { - $section = "non-US"; - $pooldir = "non-US/main/"; - } elsif ($section =~ m#^(contrib|non-free)/#) { - $section = $1; - $pooldir = $section."/"; - } else { - $section = "unknown"; - } - } - if (defined($synonym{$priority})) { - $priority = $synonym{$priority}; - } else { - $data->add_errors($pkg,"'$priority' is not a valid priority\n"); - $priority = "unknown"; - } - if ($pkg =~ m/^(lib.)/) { - $pooldir .= $1; - } elsif ($pkg =~ m/^(.)/) { - $pooldir .= $1; - } - - # Move files to their definitive location - foreach (($PO_ROOT,$TEMPLATES_ROOT,$MENU_ROOT)) { - File::Path::rmtree($_."/".$pooldir."/".$pkg); - if (-d $_."/_tmp") { - File::Path::mkpath($_."/".$pooldir, 0, 0755); - qx(mv $_/_tmp $_/$pooldir/$pkg); - } - } - - $data->section ($pkg, $section); - $data->priority($pkg, $priority); - $data->pooldir ($pkg, $pooldir."/".$pkg); - - return $deb; -} - -sub check_pkg { - my $pkg = shift; - my $deb = shift; - - #####[ Check the type of organization ]################################# - # - # try to guess the organisation of this stuff. It could be : - # - standard gnu (po dir, Makefile.in.in file and POTFILES.in in it) - # - standard nls (nls dir hopefully, with all catalogs in it) - # - full (dir "en" containing po files or "nls" dir or - # "LC_MESSAGES" dir) - # (and hopefully man pages and info pages) - ##### - my $type_org = ""; - my $addtype = sub { - my $arg = shift; - if ($type_org eq "") { - $type_org = $arg; - } else { - $type_org = "$type_org|$arg"; - } - }; - - &$addtype("nls") if $deb->file_matches("(?:^|/)nls/"); - - &$addtype("gnu") if $deb->file_matches("(?:^|/)po/Makefile.in.in\$") - && $deb->file_matches("(?:^|/)po/POTFILES.in\$"); - - &$addtype("full") if $deb->file_matches("(?:^|/)en/.*\\.po\\b") - && $deb->file_matches("(?:^|/)en/.*/nls/") - && $deb->file_matches("(?:^|/)en/(?:.*/)?LC_MESSAGES/"); - - $type_org="?" if ($type_org eq ""); - $data->type($pkg, $type_org); - - search_nls($pkg); - search_po($pkg); - search_menu($pkg); - search_docbase($pkg); - search_templates($pkg); -} - -#----[ search_nls ]------------------------------------------------------------- -sub search_nls { - my $pkg = shift; - my $line; - - $data->nls($pkg, ()); - foreach ($deb->file_matches("(?:^|/)nls/")) { - $line = $deb->file_content($_, 80); - $data->add_nls($pkg, $_) if $line =~ m/^\$set[\s\d]+#/s; - } - -} - -#----[ search_po ]-------------------------------------------------------------- -sub search_po { - my $pkg = shift; - - my @pofiles = $deb->file_matches("\\.po\$"); - - ## - ## for po files, try to guess the language from the name, - ## and the l10n with msgfmt - ## - my $file; # the po file name in the package - my $filename; #the po file name to be archived - my $lang=""; # the identified code language - my $bad_lang=""; #this could be a language, but this is not a valid language - my $this_stat = ""; #stats for this file - my $err_msg =""; # err msg of the statistic external command (ie, msgfmt or debconf-stats) - my $regexp_for_lang_code = '(([a-zA-Z]{2})([-_][a-zA-Z]{2})?(@[^./]*)?)(\.[^./]+)?'; - - POFILE: foreach $file (@pofiles) { - $filename = store_disk_po($pkg, $file); - - my $PO_DIR = $PO_ROOT."/".$data->pooldir($pkg); - - $this_stat = ""; - $lang = ""; - if ($lang eq "" && $file=~ m,(?:_|\b)$regexp_for_lang_code\.po$,o) { - $bad_lang =$1; - if (is_lang($bad_lang)) { - $lang = $bad_lang; - $bad_lang = ""; - } - } - # The next rule is for kde-i18n and other such packages - if ($lang eq "" && $file =~ m,(?:^|/)$regexp_for_lang_code/(messages|LC_MESSAGES)/,) { - $bad_lang = $1; - if (is_lang($bad_lang)) { - $lang = $bad_lang; - $bad_lang = ""; - } - } - if ($lang ne "") { - # stats the file - ($this_stat, $err_msg) = read_stats("msgfmt --statistics -o /dev/null $PO_DIR/$filename 2>&1 1>/dev/null"); - if ($err_msg ne '') { - $err_msg =~ s,\Q$PO_DIR/$filename\E,$file,g; - $data->add_errors($pkg, "gettext: ".$err_msg); - } - } else { # no valid lang found - next POFILE if $file =~ m,messages.po$,; - if ($bad_lang eq "") { - $data->add_errors($pkg, "gettext: $file: can't guess language"); - } else { - $data->add_errors($pkg, "gettext: $file: $bad_lang not a language code"); - } - } - # Add this file to the data - $data->add_po($pkg, $file, normalize_lang($lang), $this_stat, $filename); - if (system("gzip -9 $PO_DIR/$filename")) { - warn "Can't gzip $PO_DIR/$filename: $!"; - } - } - print STDERR "MEM: ".$deb->get_max_memory()."\n" if $verbose; -} - -#----[ search_menu ]----------------------------------------------------------- -sub search_menu { - my $pkg = shift; - my $filename; - - my @menufiles = $deb->file_matches("(^|/)debian/[^/]*menu[^/]*\$"); - foreach my $file (@menufiles) { - # Add this file to the data - $filename = store_disk_menu($pkg, $file); - $data->add_menu($pkg, $file, $filename.".gz"); - if (system("gzip -9 $MENU_ROOT/".$data->pooldir($pkg)."/$filename")){ - warn "Can't gzip $MENU_ROOT/".$data->pooldir($pkg)."/$filename: $!\n"; - } - } -} - -#----[ search_docbase ]--------------------------------------------------------- -sub search_docbase { - my $pkg = shift; - my ($dirname, $filename); - - my @docbasefiles = $deb->file_matches("(^|/)debian/[^/]*doc-base[^/]*\$"); - - foreach my $file (@docbasefiles) { - $_ = $deb->file_content($file); - next unless m/^Document:\s*(\S*)\s*$/m; - $filename = 'doc-base-' . $1; - $dirname = $file; - $dirname =~ s#/+[^/]*$##; - $filename = $dirname . '/' . $filename; - $filename =~ s,^.*debian/,,; - $filename =~ s/:/\%3a/g; - $filename =~ s,/,_,g; - File::Path::mkpath($MENU_ROOT."/".$data->pooldir($pkg), 0, 0755); - unless (open (DOCBASE, "> $MENU_ROOT/".$data->pooldir($pkg)."/$filename")) { - warn "Unable to write to $MENU_ROOT/".$data->pooldir($pkg)."/$filename\n"; - next; - } - print DOCBASE; - close DOCBASE; - $data->add_menu($pkg, $file, $filename.".gz"); - if (system("gzip -9 $MENU_ROOT/".$data->pooldir($pkg)."/$filename")) { - warn "Can't gzip $MENU_ROOT/".$data->pooldir($pkg)."/$filename: $!\n"; - } - } -} - -#----[ search_templates ]------------------------------------------------------ -sub search_templates { - my $pkg = shift; - my ($filename, $tmpl, %tmpl_stats, $this_stat, @list, @list2); - - my @debconffiles = $deb->file_matches("(^|/)debian/([^/]+\\.)?templates\$"); - $tmpl = Debian::L10n::Debconf->new(); - foreach my $file (@debconffiles) { - # All translations in a single file - next if $deb->file_matches($file."\\."); - - # Add this file to data - $filename = store_disk_templates($pkg, $file); - my $storedfile = $TEMPLATES_ROOT."/".$data->pooldir($pkg)."/$filename"; - - # Trap warnings from Debian::L10n::Debconf and reword them - { - local $SIG{__WARN__} = sub { - my $msg = $_[0]; - $msg =~ s,^\Q$storedfile\E,debconf: $file,; - $data->add_errors($pkg, $msg); - }; - eval { $tmpl->read_compact($storedfile) }; - } - %tmpl_stats = $tmpl->stats(); - # Add information about English template - $data->add_templates($pkg, $file, '_', $tmpl->count().'t0f0u', $filename); - foreach (keys %tmpl_stats) { - $this_stat = $tmpl_stats{$_}->[0].'t'.$tmpl_stats{$_}->[1].'f'.$tmpl_stats{$_}->[2].'u'; - $data->add_templates($pkg, $file, normalize_lang($_), $this_stat, $filename); - } - if (system("gzip -9 $storedfile")){ - warn "Can't gzip $storedfile: $!\n"; - } - } - foreach my $file (@debconffiles) { - # Translations are put in separate files - @list = $deb->file_matches($file."\\."); - next unless @list; - - $filename = store_disk_templates($pkg, $file); - - @list2 = (); - my %storedfile = (); - my %origfile = (); - foreach (@list) { - my $relfile = $TEMPLATES_ROOT."/".$data->pooldir($pkg)."/".store_disk_templates($pkg, $_); - $storedfile{$relfile} = store_disk_templates($pkg, $_); - $origfile{$relfile} = $_; - push (@list2, $relfile); - } - # Trap warnings from Debian::L10n::Debconf and reword them - { - local $SIG{__WARN__} = sub { - my $msg = $_[0]; - my $disk = $TEMPLATES_ROOT."/".$data->pooldir($pkg)."/$filename"; - $msg =~ s,^\Q$disk\E,debconf: $file,; - $data->add_errors($pkg, $msg); - }; - eval { $tmpl->read_dispatched($TEMPLATES_ROOT."/".$data->pooldir($pkg)."/".$filename, @list2) }; - } - %tmpl_stats = $tmpl->stats(); - # Add information about English template - $data->add_templates($pkg, $file, '_', $tmpl->count().'t0f0u', $filename); - foreach (keys %tmpl_stats) { - $this_stat = $tmpl_stats{$_}->[0].'t'.$tmpl_stats{$_}->[1].'f'.$tmpl_stats{$_}->[2].'u'; - $data->add_templates($pkg, $origfile{$tmpl->filename($_)}, normalize_lang($_), $this_stat, $storedfile{$tmpl->filename($_)}, $filename); - if (system("gzip -9 $TEMPLATES_ROOT/".$data->pooldir($pkg)."/".$storedfile{$tmpl->filename($_)})) { - warn "Can't gzip $TEMPLATES_ROOT/".$data->pooldir($pkg)."/".$storedfile{$tmpl->filename($_)}.": $!\n"; - } - } - if (system("gzip -9 $TEMPLATES_ROOT/".$data->pooldir($pkg)."/".$filename)) { - warn "Can't gzip $TEMPLATES_ROOT/".$data->pooldir($pkg)."/".$filename.": $!\n"; - } - } -} - -#----[ normalize_lang ]-------------------------------------------------------- -sub normalize_lang { - my $lang = shift; - if ($lang =~ m,^(..)[-_](..)$,) { - return lc($1).'_'.uc($2); - } elsif ($lang =~ m,^(..)$,) { - return lc($1); - } - return $lang; -} - -#----[ parse_stats ]------------------------------------------------------------ -# transform "5 translated templates, 1 fuzzy translations" -> "5t1f0u" -sub parse_stats { - my $line = shift; - my $returned_stats = ""; - - $returned_stats .= ($line =~ /(\d+) translated/ ? $1 : "0")."t"; - $returned_stats .= ($line =~ /(\d+) fuzzy/ ? $1 : "0")."f"; - $returned_stats .= ($line =~ /(\d+) untranslated/ ? $1 : "0")."u"; - - return $returned_stats; -} - -#----[ read_stats ]------------------------------------------------------------- -# run an external command to get the level of translation of a file -# arg1 = cmd to run -# -# ret1 = stats line -# ret2 = "" or error msg got -sub read_stats { - my $cmd = shift; - - my ($found) = 0; #true if output seems to be correct - my $returned_err = ""; - my $returned_stats = "0t0f0u"; - - # reads the new stats - my @lines = qx,$cmd,; - return ("0t0f0u","Something weird append (no output)\n") - unless $#lines >= 0; - - foreach (@lines) { - if (m/translated|fuzzy/) { - $returned_stats = parse_stats($_); - } else { - $returned_err .= $_; - } - } - return ($returned_stats,$returned_err); -} - -#----[ init_synonym ]----------------------------------------------------------- -# Read the synonym file -sub init_synonym { - my $right; - my $wrong; - - open (DATA,"< $SYN_FILE") - || die ("Can't read $SYN_FILE"); - while (<DATA>) { - next unless /\S/; - next if /^\#/; - chop; - if (m/:/) { - ($wrong, $right) = split(/:/, $_, 2); - } else { - $wrong = $right = $_; - } - $synonym{$wrong} = $right; - } - close (DATA); -} - -# sub is_lang(code) : returns true iff code is a valid code of language -sub is_lang { - my $code = shift; - $code =~ s/\@.*$//; - # Accept these codes - return 1 if $code eq 'du-NL' || $code eq 'no_NY' || $code eq 'cz' || $code eq 'dk' || $code eq 'sp' || $code eq 'wa'; - if ($code =~ /^(..)[-_](..)$/) { - return (defined(code2language($1)) && defined(code2country($2))); - } - return defined code2language($code); -} - -1; - |