pf-tools/pf-tools: gardons les commentaires lors de la traductions
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Tue Apr 8 13:07:53 UTC 2014
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/f9281e042897
changeset: 1255:f9281e042897
user: shad
date: Tue Apr 08 15:07:49 2014 +0200
description:
gardons les commentaires lors de la traductions
diffstat:
tools/Translate_old_config | 77 +++++++++++++++++++++++++++++++++++++++++----
1 files changed, 69 insertions(+), 8 deletions(-)
diffs (154 lines):
diff -r 502a1da44cf0 -r f9281e042897 tools/Translate_old_config
--- a/tools/Translate_old_config Tue Apr 08 13:15:44 2014 +0200
+++ b/tools/Translate_old_config Tue Apr 08 15:07:49 2014 +0200
@@ -87,19 +87,42 @@
croak qq{File "$options->{'input'}" doesn't exist};
}
+my $comments = {};
+my @tempcomment;
+my $current_section;
my %sectionorder = ( __hostfile => 0 );
my $sectionnumber = 1;
open my $FILE, q{<}, $options->{'input'}
or croak qq{Can't open '$options->{'input'}': $OS_ERROR};
while (<$FILE>) {
chomp;
- if ( $_ =~ m{\A \[ ([^\]]*) \] }msx ) {
- $sectionorder{$1} = $sectionnumber;
+
+ if ( $_ =~ m{\A \s* \# }msx ) {
+ push @tempcomment, $_;
+ }
+ elsif ( $_ =~ m{\A \[ ([^\]]*) \] }msx ) {
+ $current_section = $1;
+ $sectionorder{$current_section} = $sectionnumber;
$sectionnumber++;
+ if (@tempcomment) {
+ @{ $comments->{$current_section}->{'general'} } = @tempcomment;
+ undef @tempcomment;
+ }
}
elsif ( $_ =~ m{\A \@include [ ] (.*) }msx ) {
- $sectionorder{"include-$1"} = $sectionnumber;
+ $current_section = $1;
+ $sectionorder{"include-$current_section"} = $sectionnumber;
$sectionnumber++;
+ if (@tempcomment) {
+ @{ $comments->{$current_section}->{'general'} } = @tempcomment;
+ undef @tempcomment;
+ }
+ }
+ elsif ( $_ =~ m{\A \s* ([^=\#\s]*) \s* = .* }msx ) {
+ if (@tempcomment) {
+ @{ $comments->{$current_section}->{$1} } = @tempcomment;
+ undef @tempcomment;
+ }
}
}
close $FILE
@@ -108,6 +131,7 @@
my $old_parsing
= Parser_pftools( $options->{'input'}, {}, $options->{'include'} );
my $trans = {};
+
#print Dumper($old_parsing);
if ( $options->{'type'} eq 'config' ) {
$trans = Translate_old2new_config($old_parsing);
@@ -141,7 +165,8 @@
$trans->{'__hostfile'}->{$section}
= Translate_old2new_host( $old_parsing->{$section},
$section );
- } else {
+ }
+ else {
$trans->{$section}
= Translate_old2new_vhost( $old_parsing->{$section},
$section );
@@ -194,15 +219,24 @@
return $orderby{$roota} <=> $orderby{$rootb};
}
}
-
if ( $options->{'type'} eq 'config' ) {
foreach my $section (
sort { $sectionorder{$a} <=> $sectionorder{$b} }
keys %{$trans}
)
{
+ if ( $comments->{$section}->{'general'} ) {
+ $output_fh->print(
+ join( qq{\n}, @{ $comments->{$section}->{'general'} } )
+ . qq{\n} );
+ }
$output_fh->print(qq{[$section]\n});
foreach my $key ( sort orderkeys keys %{ $trans->{$section} } ) {
+ if ( $comments->{$section}->{$key} ) {
+ $output_fh->print(
+ join( qq{\n}, @{ $comments->{$section}->{$key} } )
+ . qq{\n} );
+ }
$output_fh->print("\t$key\t= $trans->{$section}->{$key}\n");
}
$output_fh->print("\n");
@@ -232,12 +266,32 @@
foreach my $hostsection (
sort keys %{ $trans->{$section}->{$hostdef} } )
{
+ if ( $comments->{$hostsection}->{'general'} ) {
+ $output_fh->print(
+ join(
+ qq{\n},
+ @{ $comments->{$hostsection}->{'general'}
+ }
+ )
+ . qq{\n}
+ );
+ }
$host_output_fh->print(qq{[$hostsection]\n});
foreach my $hostkey (
sort orderkeys
keys
%{ $trans->{$section}->{$hostdef}->{$hostsection} } )
{
+ if ( $comments->{$hostsection}->{$hostkey} ) {
+ $output_fh->print(
+ join(
+ qq{\n},
+ @{ $comments->{$hostsection}->{$hostkey}
+ }
+ )
+ . qq{\n}
+ );
+ }
if ( $hostkey =~ m{\A @ }mxs ) {
foreach my $subhostkey (
@{ $trans->{$section}->{$hostdef}
@@ -271,17 +325,24 @@
}
}
else {
+ if ( $comments->{$section}->{'general'} ) {
+ $output_fh->print(
+ join( qq{\n}, @{ $comments->{$section}->{'general'} } )
+ . qq{\n} );
+ }
$output_fh->print(qq{[$section]\n});
foreach my $key ( sort orderkeys keys %{ $trans->{$section} } ) {
+ if ( $comments->{$section}->{$key} ) {
+ $output_fh->print(
+ join( qq{\n}, @{ $comments->{$section}->{$key} } )
+ . qq{\n} );
+ }
$output_fh->print("\t$key\t= $trans->{$section}->{$key}\n");
}
$output_fh->print("\n");
}
}
- print
- qq{Need to implement the output for other type: '$options->{'type'}'\n};
-
#print Dumper($trans);
}
More information about the pf-tools-commits
mailing list