3 # MAIN ADMINISTRATIVE DATABASE UPDATE TOOL
6 # ./update-master-info [-d RSYNCDESTDIR] [-O OCEAN ... | -a]
10 # After editing source-info.txt to add commodities, or
11 # changing db-idempotent-update (eg to change the schema):
12 # ./update-master-info -d ~ftp/users/ijackson/yarrg/
13 # This will update everything except the ocean topologies.
15 # To take account of new islands, or to fix a mistake in
16 # assigning island(s) to archipelago(es), or to add support
18 # ./update-master-info -d ~ftp/users/ijackson/yarrg/ -O Midnight
20 # After a fix to a mistake on a YPPedia chart page, correcting
21 # only inter-island-distances:
22 # ./update-master-info -O Midnight
24 # After changing the algorithms for topology determination
25 # or YPPedia scraping:
26 # ./update-master-info -a
27 # and check that nothing unexpected changes.
30 # This is part of ypp-sc-tools, a set of third-party tools for assisting
31 # players of Yohoho Puzzle Pirates.
33 # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
35 # This program is free software: you can redistribute it and/or modify
36 # it under the terms of the GNU General Public License as published by
37 # the Free Software Foundation, either version 3 of the License, or
38 # (at your option) any later version.
40 # This program is distributed in the hope that it will be useful,
41 # but WITHOUT ANY WARRANTY; without even the implied warranty of
42 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 # GNU General Public License for more details.
45 # You should have received a copy of the GNU General Public License
46 # along with this program. If not, see <http://www.gnu.org/licenses/>.
48 # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
49 # are used without permission. This program is not endorsed or
50 # sponsored by Three Rings.
52 use strict (qw(vars));
56 $ENV{'LC_CTYPE'}= 'en_GB.UTF-8';
61 print "## updating topology of $ocean\n";
62 system('./yppedia-chart-parser',$ocean); die "$ocean $?" if $?;
68 print STDERR "## updating schema and commodities for $ocean\n";
69 system('./db-idempotent-populate',$ocean); die $? if $?;
74 sub process_some_info ($$$) {
75 my ($v,$df,$sfn) = @_;
76 my $sf= new IO::File $sfn or die "$sfn $!";
81 next if m/^\s*\#/ || !m/\S/;
85 die "$_ ?" unless defined $h;
86 if ($h =~ m/^commods|^\%[a-z]\b/) {
90 next if $h =~ m/^nocommods/;
92 next if $sfn =~ m/source-info/ && $h =~ m/^ocean\b/;
93 next if $h =~ m/^client\b/;
95 print $df $_, "\n" or die $!;
98 $sf->error and die $!;
101 sub update_master_info () {
102 foreach my $v (1..$masterinfoversion) {
103 my $dfnl= sprintf "master-info%s.txt", ($v>1 ? "-v$v" : '');
104 print STDERR "installing new $dfnl...\n";
106 my $dfn= "$rsyncdir/$dfnl";
107 my $df= new IO::File "$dfn.tmp", 'w' or die "$dfn.tmp $!";
109 process_some_info($v,$df, 'source-info.txt');
110 foreach my $ocean (sort keys %oceans) {
111 process_some_info($v,$df, '_ocean-'.(lc $ocean).'.txt');
115 rename "$dfn.tmp", "$dfn" or die $!;
126 return scalar shift @ARGV;
129 while (@ARGV && $ARGV[0] =~ m/^-/) {
134 die if defined $rsyncdir;
137 push @specoceans, optarg();
148 die if @specoceans && $alloceans;
150 parse_info_serverside();
153 print "### full update of specified oceans ...\n";
154 foreach my $ocean (@specoceans) {
155 die "$ocean ?" unless defined $oceans{$ocean};
158 } elsif ($alloceans) {
159 print "### full (inc.topology) update of all oceans ...\n";
160 foreach my $ocean (sort keys %oceans) {
164 print "### quick (no topology) update only (of all oceans) ...\n";
165 foreach my $ocean (sort keys %oceans) {
170 if (defined $rsyncdir) {
171 print "### master-info update ...\n";
172 update_master_info();