X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2Fupdate-master-info;h=00aee34b890767cf308ec43c226128caefce701b;hb=6a03862e8e23287617045432cc14fb15305c2261;hp=a52b212366ab635becd16399a26baf5ae3cde1b7;hpb=877b0ba6b2d72d7957e2a8015520b87371cba6c9;p=ypp-sc-tools.db-test.git diff --git a/yarrg/update-master-info b/yarrg/update-master-info index a52b212..00aee34 100755 --- a/yarrg/update-master-info +++ b/yarrg/update-master-info @@ -1,22 +1,105 @@ #!/usr/bin/perl -w use strict (qw(vars)); - use DBI; - use Commods; -@ARGV==1 or die; -my ($rsyncdir) = @ARGV; + +sub full ($) { + my ($ocean) = @_; + quick($ocean); + print "## updating topology of $ocean\n"; + system('./yppedia-chart-parser',$ocean); die $? if $?; +} + +sub quick ($) { + my ($ocean) = @_; + print STDERR "## updating schema and commodities for $ocean\n"; + system('./db-idempotent-populate',$ocean); die $? if $?; +} + +my $rsyncdir; + +sub update_master_info () { + my $sfn= 'source-info.txt'; + + foreach my $v (1..$masterinfoversion) { + my $dfnl= sprintf "master-info%s.txt", ($v>1 ? "-v$v" : ''); + print STDERR "installing new $dfnl...\n"; + + my $dfn= "$rsyncdir/$dfnl"; + my $sf= new IO::File $sfn or die "$sfn $!"; + my $df= new IO::File "$dfn.tmp", 'w' or die "$dfn.tmp $!"; + + my $h; + while (<$sf>) { + chomp; s/\s+$//; + next if m/^\s*\#/ || !m/\S/; + if (m/^\S.*/) { + $h= $&; + } + die "$_ ?" unless defined $h; + if ($h =~ m/^commods|^\%[a-z]\b/) { + s/\t.*//; + } + if ($v<2) { + next if $h =~ m/^nocommods/; + } + print $df $_, "\n" or die $!; + } + + $sf->error and die $!; + close $df or die $!; + rename "$dfn.tmp", "$dfn" or die $!; + } + +} + + +my @specoceans; +my $alloceans; + +sub optarg () { + return $_ if length; + die unless @ARGV; + return scalar shift @ARGV; +} + +while (@ARGV && $ARGV[0] =~ m/^-/) { + $_= shift @ARGV; + last if m/^--?$/; + while (m/^-./) { + if (s/^-d//) { $rsyncdir= optarg(); } + elsif (s/^-O//) { push @specoceans, optarg(); } + elsif (s/^-a//) { $alloceans=1; } + else { die "$_ ?"; } + } +} +die if @ARGV; + +die if @specoceans && $alloceans; parse_info_serverside(); -foreach my $oceanname (sort keys %oceans) { - print STDERR "updating ocean $oceanname...\n"; - system('./db-idempotent-populate',$oceanname); die $? if $?; +if (@specoceans) { + print "### full update of specified oceans ...\n"; + foreach my $ocean (@specoceans) { + die "$ocean ?" unless defined $oceans{$ocean}; + full($ocean); + } +} elsif ($alloceans) { + print "### full (inc.topology) update of all oceans ...\n"; + foreach my $ocean (sort keys %oceans) { + full($ocean); + } +} else { + print "### quick (no topology) update only (of all oceans) ...\n"; + foreach my $ocean (sort keys %oceans) { + quick($ocean); + } } -print STDERR "installing new master-info...\n"; -my $df= "$rsyncdir/master-info.txt"; -system('cp','--','master-info.txt',"$df.tmp"); die $? if $?; -system('mv','--',"$df.tmp",$df); die $? if $? +if (defined $rsyncdir) { + print "### master-info update ...\n"; + update_master_info(); +}