diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-01-19 14:15:17 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-01-19 14:15:17 -0800 |
commit | 0f6e2fa51871b05b91dfc286a582ae025cc8c51f (patch) | |
tree | f0d72f98f98218f139aa0fcc9a028fd71c5901df | |
parent | b2fb16ddc08cc65384d6b93cb65097a4b917f02a (diff) | |
download | vyatta-cfg-0f6e2fa51871b05b91dfc286a582ae025cc8c51f.tar.gz vyatta-cfg-0f6e2fa51871b05b91dfc286a582ae025cc8c51f.zip |
Restore priority comments
Also sort the names when multiple values have same priority.
-rw-r--r-- | scripts/priority.pl | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/scripts/priority.pl b/scripts/priority.pl index 3f5804f..4124987 100644 --- a/scripts/priority.pl +++ b/scripts/priority.pl @@ -8,43 +8,60 @@ use strict; use warnings; use File::Find; -my %pri; +my %priorities; +# Open node file and extract priority and comment if any sub get_priority { open( my $f, '<', $_ ) or return; my $priority; + my $comment; while (<$f>) { chomp; next unless m/^priority:\s(\d+)/; $priority = $1; + + $comment = $1 if (/#(.*)$/); + last; } close $f; - return $priority; + return ( $priority, $comment ); } +# Called by find and returns true iff +# file is named node.def +# file contains priority tag +# Side effect: tores resulting line in $priorities hash for display sub wanted { return unless ( $_ eq 'node.def' ); - my $p = get_priority($File::Find::name); - return unless $p; + my ( $priority, $comment ) = get_priority($File::Find::name); + return unless $priority; my $dir = $File::Find::dir; $dir =~ s/^.*\/templates\///; - push @{ $pri{$p} }, $dir; + $dir .= " #" . $comment + if $comment; + + # append line to list of entries with same priority + push @{ $priorities{$priority} }, $dir; return 1; } +# main program my $cfgdir = '/opt/vyatta/share/vyatta-cfg/templates'; die "$cfgdir does not exist!" unless -d $cfgdir; + +# walk config file tree find( \&wanted, $cfgdir ); -foreach my $key ( sort { $a <=> $b } keys %pri ) { - my @a = @{ $pri{$key} }; - foreach my $val (@a) { +# display resulting priorities +foreach my $key ( sort { $a <=> $b } keys %priorities ) { + my @a = @{ $priorities{$key} }; + foreach my $val ( sort @a ) { print $key, " ", $val, "\n"; } } |