From: Ian Jackson Date: Thu, 27 Aug 2009 14:20:25 +0000 (+0100) Subject: master-info sanitiser. master-info is now renamed source-info X-Git-Tag: 3.4~82 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=commitdiff_plain;h=bd155443745759a5a9c95cd1cbce5a8f73894737 master-info sanitiser. master-info is now renamed source-info --- diff --git a/yarrg/Commods.pm b/yarrg/Commods.pm index dff539d..fa8e7bf 100644 --- a/yarrg/Commods.pm +++ b/yarrg/Commods.pm @@ -65,6 +65,10 @@ our (%pctb_commodmap,@pctb_commodmap); my %colours; # eg $colours{'c'}{'black'}= $sources my @rawcm; # eg $rawcm[0]='fine rum'; $rawcm[1]='fine %c cloth' +# IMPORTANT +# when extending the format of source-info in a non-backward +# compatible way, be sure to update update-master-info too. + sub parse_info1 ($$) { my ($mmfn,$src)= @_; my $mm= new IO::File $mmfn, 'r' or die "$mmfn $!"; @@ -209,7 +213,7 @@ sub parse_info_maproutes ($$$) { } sub parse_info_serverside () { - parse_info1('master-info.txt','s'); + parse_info1('source-info.txt','s'); } sub parse_info_serverside_ocean ($) { my ($oceanname) = @_; diff --git a/yarrg/CommodsWeb.pm b/yarrg/CommodsWeb.pm index 3ad8590..198185d 100644 --- a/yarrg/CommodsWeb.pm +++ b/yarrg/CommodsWeb.pm @@ -91,7 +91,7 @@ my @ocean_list; sub ocean_list () { my $datadir= datadir(); if (!@ocean_list) { - my $fn= "$datadir/master-info.txt"; + my $fn= "$datadir/source-info.txt"; my $f= new IO::File $fn or die "$fn $!"; my @r; while (<$f>) { diff --git a/yarrg/TODO b/yarrg/TODO index 938ae3d..1c158a0 100644 --- a/yarrg/TODO +++ b/yarrg/TODO @@ -15,9 +15,6 @@ P C pager scrollbar distance moved check DATABASE/DICTIONARY MANAGER --------------------------- -P N master-info sanitiser (new master-info with distances hints etc. is - no good for old clients and clients don't need all that stuff anyway) - commodity mass/volume in live database O N yppedia distance scraper finish @@ -29,6 +26,8 @@ O N yppedia also cross-check arch/island pages when update rejected print better error message including broken commodity name + notice commodities deleted from source-info and warn about them + WEBSITE ------- diff --git a/yarrg/db-idempotent-populate b/yarrg/db-idempotent-populate index 9d7bab0..b44d45d 100755 --- a/yarrg/db-idempotent-populate +++ b/yarrg/db-idempotent-populate @@ -1,5 +1,8 @@ #!/usr/bin/perl -w # +# Normally run from +# update-master-info +# # usage: ./db-idempotent-populate # creates or updates OCEAN-Oceanname.db # from master-master.txt diff --git a/yarrg/master-info.txt b/yarrg/source-info.txt similarity index 100% rename from yarrg/master-info.txt rename to yarrg/source-info.txt diff --git a/yarrg/update-master-info b/yarrg/update-master-info index a52b212..3aa9ac2 100755 --- a/yarrg/update-master-info +++ b/yarrg/update-master-info @@ -17,6 +17,27 @@ foreach my $oceanname (sort keys %oceans) { } 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 $? + +my $sfn= 'source-info.txt'; +my $dfn= "$rsyncdir/master-info.txt"; + +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.*//; + } + print $df $_, "\n" or die $!; +} + +$sf->error and die $!; +close $df or die $!; +rename "$dfn.tmp", "$dfn" or die $!;