From b96a209ff70d2e74ac230f0f0acec22c74d5b9d6 Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel Date: Sun, 6 Apr 2014 21:39:08 -0300 Subject: [PATCH] Bug 12061 - tmpl_process3.pl - Multiple source dir This patch adds the option to use multiple source dirs for tmpl_process3.pl on create/update actions. To test after patch: A) Old 1. install cd misc/translator perl tmpl_process3.pl create -i ../../koha-tmpl/opac-tmpl/bootstrap/en -s bootstrap.po -r 2. update perl tmpl_process3.pl update -i ../../koha-tmpl/opac-tmpl/bootstrap -s bootstrap.po -r 3. install mkdir test perl tmpl_process3.pl install -i ../../koha-tmpl/opac-tmpl/bootstrap -s bootstrap.po -r -o ./test -q - check same number of files ls -lR ../../koha-tmpl/opac-tmpl/bootstrap | wc -l ls -lR ./test | wc -l rm -f bootstrap.po B) New 4. create from multiple sources perl tmpl_process3.pl create -i ../../koha-tmpl/opac-tmpl/prog/en -i ../../koha-tmpl/opac-tmpl/bootstrap/en -i ../../koha-tmpl/opac-tmpl/ccsr/en -s opac.po -r 5. update from multiple source perl tmpl_process3.pl update -i ../../koha-tmpl/opac-tmpl/prog/en -i ../../koha-tmpl/opac-tmpl/bootstrap/en -i ../../koha-tmpl/opac-tmpl/ccsr/en -s opac.po -r 6. install (must give an error) perl tmpl_process3.pl install -i ../../koha-tmpl/opac-tmpl/prog/en -i ../../koha-tmpl/opac-tmpl/bootstrap -s opac.po -r -o ./test 7. updated help perl tmpl_process3.pl --help Any other functionality must not be affected Signed-off-by: Fridolin Somers Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- misc/translator/tmpl_process3.pl | 34 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/misc/translator/tmpl_process3.pl b/misc/translator/tmpl_process3.pl index 1690306274..4c23a8f20a 100755 --- a/misc/translator/tmpl_process3.pl +++ b/misc/translator/tmpl_process3.pl @@ -22,7 +22,7 @@ use VerboseWarnings qw( :warn :die ); ############################################################################### -use vars qw( $in_dir @filenames $str_file $out_dir $quiet ); +use vars qw( @in_dirs @filenames $str_file $out_dir $quiet ); use vars qw( @excludes $exclude_regex ); use vars qw( $recursive_p ); use vars qw( $pedantic_p ); @@ -185,7 +185,9 @@ Usage: $0 create [OPTION] or: $0 --help Create or update PO files from templates, or install translated templates. - -i, --input=SOURCE Get or update strings from SOURCE directory. + -i, --input=SOURCE Get or update strings from SOURCE directory(s). + On create or update can have multiple values. + On install only one value. -o, --outputdir=DIRECTORY Install translation(s) to specified DIRECTORY --pedantic-warnings Issue warnings even for detected problems which are likely to be harmless @@ -199,10 +201,10 @@ Create or update PO files from templates, or install translated templates. -q, --quiet no output to screen (except for errors) The -o option is ignored for the "create" and "update" actions. -Try `perldoc $0 for perhaps more information. +Try `perldoc $0` for perhaps more information. EOF exit($exitcode); -}#` +} ############################################################################### @@ -217,7 +219,7 @@ sub usage_error (;$) { ############################################################################### GetOptions( - 'input|i=s' => \$in_dir, + 'input|i=s' => \@in_dirs, 'filename|f=s' => \@filenames, 'outputdir|o=s' => \$out_dir, 'recursive|r' => \$recursive_p, @@ -239,15 +241,17 @@ $SIG{__WARN__} = sub { my $action = shift or usage_error('You must specify an ACTION.'); usage_error('You must at least specify input and string list filenames.') - if !$in_dir || !defined $str_file; + if !@in_dirs || !defined $str_file; # Type match defaults to *.tt plus *.inc if not specified $type = "tt|inc|xsl|xml|def" if !defined($type); # Check the inputs for being directories -usage_error("$in_dir: Input must be a directory.\n" - . "(Symbolic links are not supported at the moment)") - unless -d $in_dir; +for my $in_dir ( @in_dirs ) { + usage_error("$in_dir: Input must be a directory.\n" + . "(Symbolic links are not supported at the moment)") + unless -d $in_dir; +} # Generates the global exclude regular expression $exclude_regex = '(?:'.join('|', @excludes).')' if @excludes; @@ -255,13 +259,15 @@ $exclude_regex = '(?:'.join('|', @excludes).')' if @excludes; my @in_files; # Generate the list of input files if a directory is specified # input is a directory, generates list of files to process -$in_dir =~ s/\/$//; # strips the trailing / if any for my $fn ( @filenames ) { die "You cannot specify input files and directories at the same time.\n" if -d $fn; } -@in_files = listfiles($in_dir, $type, $action, \@filenames); +for my $in_dir ( @in_dirs ) { + $in_dir =~ s/\/$//; # strips the trailing / if any + @in_files = ( @in_files, listfiles($in_dir, $type, $action, \@filenames) ); +} # restores the string list from file $href = Locale::PO->load_file_ashash($str_file); @@ -394,6 +400,12 @@ if ($action eq 'create') { usage_error("You must specify an output directory when using the install method."); } + if ( scalar @in_dirs > 1 ) { + usage_error("You must specify only one input directory when using the install method."); + } + + my $in_dir = shift @in_dirs; + if ($in_dir eq $out_dir) { warn "You must specify a different input and output directory.\n"; exit -1; -- 2.39.5