[Koha-cvs] CVS: koha/misc/translator tmpl_process3.pl,1.20,1.21

Ambrose C. LI acli at users.sourceforge.net
Fri Feb 4 04:49:36 CET 2005


Update of /cvsroot/koha/koha/misc/translator
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16299

Modified Files:
	tmpl_process3.pl 
Log Message:
Some changes from rel_2_2:

Make the generated pot file (i.e., result of "create") look more "real",
but using msgmerge to reformat the output

Script failed to create intermediate directories if the directory of the
target does not exist and the parent of that directory does not exist
either. This should fix that.


Index: tmpl_process3.pl
===================================================================
RCS file: /cvsroot/koha/koha/misc/translator/tmpl_process3.pl,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -r1.20 -r1.21
*** tmpl_process3.pl	10 Mar 2004 07:00:28 -0000	1.20
--- tmpl_process3.pl	4 Feb 2005 03:49:33 -0000	1.21
***************
*** 139,142 ****
--- 139,157 ----
  ###############################################################################
  
+ sub mkdir_recursive ($) {
+     my($dir) = @_;
+     local($`, $&, $', $1);
+     $dir = $` if $dir ne /^\/+$/ && $dir =~ /\/+$/;
+     my ($prefix, $basename) = ($dir =~ /\/([^\/]+)$/s)? ($`, $1): ('.', $dir);
+     mkdir_recursive($prefix) if $prefix ne '.' && !-d $prefix;
+     if (!-d $dir) {
+ 	print STDERR "Making directory $dir...";
+ 	# creates with rwxrwxr-x permissions
+ 	mkdir($dir, 0775) || warn_normal "$dir: $!", undef;
+     }
+ }
+ 
+ ###############################################################################
+ 
  sub usage ($) {
      my($exitcode) = @_;
***************
*** 263,276 ****
      }
      die "$str_file: Output file already exists\n" if -f $str_file;
!     my($tmph, $tmpfile) = tmpnam();
      # Generate the temporary file that acts as <MODULE>/POTFILES.in
      for my $input (@in_files) {
! 	print $tmph "$input\n";
      }
!     close $tmph;
      # Generate the specified po file ($str_file)
!     $st = system ($xgettext, '-s', '-f', $tmpfile, '-o', $str_file);
!     warn_normal "Text extraction failed: $xgettext: $!\n", undef if $st != 0;
! #   unlink $tmpfile || warn_normal "$tmpfile: unlink failed: $!\n", undef;
  
  } elsif ($action eq 'update') {
--- 278,316 ----
      }
      die "$str_file: Output file already exists\n" if -f $str_file;
!     my($tmph1, $tmpfile1) = tmpnam();
!     my($tmph2, $tmpfile2) = tmpnam();
!     close $tmph2; # We just want a name
      # Generate the temporary file that acts as <MODULE>/POTFILES.in
      for my $input (@in_files) {
! 	print $tmph1 "$input\n";
      }
!     close $tmph1;
      # Generate the specified po file ($str_file)
!     $st = system ($xgettext, '-s', '-f', $tmpfile1, '-o', $tmpfile2);
!     # Run msgmerge so that the pot file looks like a real pot file
!     # We need to help msgmerge a bit by pre-creating a dummy po file that has
!     # the headers and the "" msgid & msgstr. It will fill in the rest.
!     if ($st == 0) {
! 	# Merge the temporary "pot file" with the specified po file ($str_file)
! 	# FIXME: msgmerge(1) is a Unix dependency
! 	# FIXME: need to check the return value
! 	unless (-f $str_file) {
! 	    local(*INPUT, *OUTPUT);
! 	    open(INPUT, "<$tmpfile2");
! 	    open(OUTPUT, ">$str_file");
! 	    while (<INPUT>) {
! 		print OUTPUT;
! 	    last if /^\n/s;
! 	    }
! 	    close INPUT;
! 	    close OUTPUT;
! 	}
! 	$st = system('msgmerge', '-U', '-s', $str_file, $tmpfile2);
!     } else {
! 	error_normal "Text extraction failed: $xgettext: $!\n", undef;
! 	error_additional "Will not run msgmerge\n", undef;
!     }
! #   unlink $tmpfile1 || warn_normal "$tmpfile1: unlink failed: $!\n", undef;
! #   unlink $tmpfile2 || warn_normal "$tmpfile2: unlink failed: $!\n", undef;
  
  } elsif ($action eq 'update') {
***************
*** 329,337 ****
  	my $target = $out_dir . substr($input, length($in_dir));
  	my $targetdir = $` if $target =~ /[^\/]+$/s;
! 	if (!-d $targetdir) {
! 	    print STDERR "Making directory $targetdir...";
! 	    # creates with rwxrwxr-x permissions
! 	    mkdir($targetdir, 0775) || warn_normal "$targetdir: $!", undef;
! 	}
  	print STDERR "Creating $target...\n";
  	open( OUTPUT, ">$target" ) || die "$target: $!\n";
--- 369,373 ----
  	my $target = $out_dir . substr($input, length($in_dir));
  	my $targetdir = $` if $target =~ /[^\/]+$/s;
! 	mkdir_recursive($targetdir) unless -d $targetdir;
  	print STDERR "Creating $target...\n";
  	open( OUTPUT, ">$target" ) || die "$target: $!\n";





More information about the Koha-cvs mailing list