diff options
author | 2020-11-19 12:45:32 +0900 | |
---|---|---|
committer | 2020-11-19 12:45:32 +0900 | |
commit | 8e0e00d21146a84c18f9cf9409e187b4fb0248aa (patch) | |
tree | ef791689dad216ac61091a1d1bd3b928d563aba6 /systemservice/config/library/system_manager_config/order/launch_order_xml2cfg.pl | |
parent | 18df6e21c6743a137e2760c52ca89d0789e90417 (diff) |
Init basesystem source codes.
Signed-off-by: Riku Nomoto <riku_nomoto@mail.toyota.co.jp>
Change-Id: I55aa2f1406ce7f751ae14140b613b53b68995528
Diffstat (limited to 'systemservice/config/library/system_manager_config/order/launch_order_xml2cfg.pl')
-rwxr-xr-x | systemservice/config/library/system_manager_config/order/launch_order_xml2cfg.pl | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/systemservice/config/library/system_manager_config/order/launch_order_xml2cfg.pl b/systemservice/config/library/system_manager_config/order/launch_order_xml2cfg.pl new file mode 100755 index 0000000..1060107 --- /dev/null +++ b/systemservice/config/library/system_manager_config/order/launch_order_xml2cfg.pl @@ -0,0 +1,171 @@ +#!/usr/bin/perl -w +use strict; + +use XML::XPath; +use File::Copy; + +my $main_file="launch_order_main.xml"; +my $body_file="launch_order_body.xml"; + + +sub usage(){ + print STDERR "USAGE:$0 *.order *.cfg\n" +} + + + + +#=== MAIN === +my $ret=system("which xmllint > /dev/null"); +if($ret != 0){ + print STDERR "It need xmllint. Please install it.\n"; + exit 1; +} + +if(2 != @ARGV){ + usage(); + exit 1; +} + +my $infile=$ARGV[0]; +my $launchfile=$ARGV[1]; + + +#ARG CHECK +if($infile !~ /.+\.order$/){ + print STDERR "$infile is not *.order\n"; + exit 1; +}elsif(! -e $infile){ + print "$infile not found\n"; + usage(); + exit 1; +} + +if($launchfile !~ /.+\.cfg$/){ + print STDERR "$launchfile is not *.cfg\n"; + exit 1; +}elsif(! -e $launchfile){ + print "$launchfile not found\n"; + usage(); + exit 1; +} + + +system("cp -f $infile $body_file"); + +#check xml vaild +$ret=system("xmllint --noout --valid $main_file"); +if($ret != 0){ + print STDERR "XML is Invalid. \n"; + exit 1; +} + +my $date=`LANG=en date`; +print "# This file is created from $infile and $launchfile\n"; +print "# created date : $date\n"; + +my %gnamemap; +my %gidmap; + +open(FIN,"<$launchfile") or die("error :$!"); +while (my $line = <FIN>){ + if($line =~ /^Launch/){ + $line =~ s/^[^|]+=//g; + my @args = split(/\|/,$line); + $gnamemap{$args[0]}=$args[1]; + $gidmap{$args[1]}=$args[0]; + } +} +close(FIN); + +foreach my $key (sort{$a <=> $b} keys(%gidmap)){ + print "#$key:$gidmap{$key}\n"; +} + + +my $xml = XML::XPath->new(filename=>$main_file); + +my $orders = $xml->find('/launch_order/order'); +foreach my $order ($orders->get_nodelist) { + my $groups = $order->find('./group'); + + my $oname=$order->findvalue('@oname'); + my $fixed_group=$order->findvalue('@fixed_group'); + + print "[$oname]\n"; + print "order="; + + my %l_gidmap = %gidmap; + my $sep=""; + #fix groups + if($fixed_group ne "NULL"){ + if(! exists $gnamemap{$fixed_group}){ + die("$fixed_group not found"); + } + foreach my $gid (sort{$a <=> $b} keys(%l_gidmap)){ + print "$sep$gid"; + $sep="|"; + my $str=$l_gidmap{$gid}; + delete $l_gidmap{$gid}; + if($str eq $fixed_group){ + last; + } + } + } + + # re-order group via *.order + my %waitow; + foreach my $group ($groups->get_nodelist) { + my $gname=$group->findvalue('@gname'); + my $waittime=XML::XPath::Number::value($group->findvalue('@waittime')); + + my $gid=$gnamemap{$gname}; + + if(! exists $gnamemap{$gname}){ + die("$oname:$gname is not defined"); + } + + if(! exists $l_gidmap{$gid}){ + die("$oname:$gname is multiple defined"); + } + + print "$sep$gid"; + $sep="|"; + delete $l_gidmap{$gid}; + + if($waittime > 0){ + $waitow{$gname} = $waittime; + } + } + +# Output waittime configuration + + #out rest groups + foreach my $gid (sort{$a <=> $b} keys(%l_gidmap)){ + print "$sep$gid"; + $sep="|"; + } + + print "\n"; + if(keys(%waitow) > 0 ){ + print "owlist="; + $sep=""; + foreach my $owgroup ( keys(%waitow)) { + print "${sep}oww_${owgroup}"; + $sep="|"; + } + print "\n"; + + foreach my $owgroup ( keys(%waitow)) { + print "oww_${owgroup}=$waitow{$owgroup}\n"; + } + + + } + print "\n"; +} + + + + + |