From 31746b6aeecf4d7cdbe3d4b9cf797d089e48fa25 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 28 Apr 2010 18:34:43 +0000 Subject: A script to automatically update/add priority tag with some value for each node.def according to the inputs. --- scripts/update-priority.pl | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 scripts/update-priority.pl (limited to 'scripts/update-priority.pl') diff --git a/scripts/update-priority.pl b/scripts/update-priority.pl new file mode 100644 index 0000000..e70688a --- /dev/null +++ b/scripts/update-priority.pl @@ -0,0 +1,74 @@ +#!/usr/bin/perl + +# Author: Arthur Xiong +# Date: 04/15/2010 +# Description: Script to automatically update/add priority tag with +# some value for each node.def according to the inputs + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2006-2010 Vyatta, Inc. +# All Rights Reserved. +# +# **** End License **** + +use strict; +use warnings; + +die "Usage: update-priority.pl " + unless $#ARGV == 1; + +my $priority; +my $path; +my $comment; +my $priority_line; +my $node_def; +my $priority_file = $ARGV[0]; +my $prefix = $ARGV[1]; + +open my $pf, '<', $priority_file or die "$priority_file can't be opened"; +while (<$pf>) { + chomp; + next if /^#.*/; + die "Syntax Error \"$_\"" unless /^(\d+)\s+(\S+)\s+(|#.*)$/; + $priority = $1; + $path = $2; + $comment = $3; + + $priority_line = ""; + $priority_line = "priority: " . $priority . "\t" . $comment . "\n"; + print "priority_line: $priority_line"; + + $node_def = ""; + $node_def = $prefix . "/" . $path . "/" . "node.def"; + print "node_def: ", $node_def, "\n"; + + open my $nf, '<', $node_def or die "$node_def can't be opened"; + open my $nfn, '>', "$node_def.new" or die "$node_def.new can't be opened"; + while (<$nf>) { + print $nfn $_ if /^(tag|multi):/; + print $nfn $priority_line; + print $nfn $_ unless /^priority:\s(\d+)/ or /^(tag|multi):/; + last if $. == 1; + } + while (<$nf>) { + print $nfn $_ unless /^priority:\s(\d+)/; + } + close $nfn; + close $nf; + + rename "$node_def.new", "$node_def" + or die "$node_def.new can't be renamed to $node_def"; + + print "Updated $node_def\n\n"; +} +close $pf; -- cgit v1.2.3