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.
29 # To just make backups of the databases into the rsync directory:
30 # ./update-master-info -b -d ~ftp/users/ijackson/yarrg/ -a
31 # ./update-master-info -b -d ~ftp/users/ijackson/yarrg/ -O ...
33 # This is part of the YARRG website. YARRG is a tool and website
34 # for assisting players of Yohoho Puzzle Pirates.
36 # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
38 # This program is free software: you can redistribute it and/or modify
39 # it under the terms of the GNU Affero General Public License as
40 # published by the Free Software Foundation, either version 3 of the
41 # License, or (at your option) any later version.
43 # This program is distributed in the hope that it will be useful,
44 # but WITHOUT ANY WARRANTY; without even the implied warranty of
45 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 # GNU Affero General Public License for more details.
48 # You should have received a copy of the GNU Affero General Public License
49 # along with this program. If not, see <http://www.gnu.org/licenses/>.
51 # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
52 # are used without permission. This program is not endorsed or
53 # sponsored by Three Rings.
55 use strict (qw(vars));
61 $ENV{'LC_CTYPE'}= 'en_GB.UTF-8';
66 print "## updating topology of $ocean\n";
67 system('./yppedia-chart-parser',$ocean); die "$ocean $?" if $?;
73 print STDERR "## updating schema and commodities for $ocean\n";
74 system('./db-idempotent-populate',$ocean); die $? if $?;
79 sub process_some_info ($$$) {
80 my ($v,$df,$sfn) = @_;
81 my $sf= new IO::File $sfn or die "$sfn $!";
86 next if m/^\s*\#/ || !m/\S/;
90 die "$_ ?" unless defined $h;
91 if ($h =~ m/^commods|^\%[a-z]\b/) {
95 next if $h =~ m/^nocommods/;
97 next if $sfn =~ m/source-info/ && $h =~ m/^ocean\b/;
98 next if $h =~ m/^client|^vessels|^shot\b|^commodclasses/;
100 print $df $_, "\n" or die $!;
103 $sf->error and die $!;
106 sub update_master_info () {
107 foreach my $v (1..$masterinfoversion) {
108 my $dfnl= sprintf "master-info%s.txt", ($v>1 ? "-v$v" : '');
109 print STDERR "installing new $dfnl...\n";
111 my $dfn= "$rsyncdir/$dfnl";
112 my $df= new IO::File "$dfn.tmp", 'w' or die "$dfn.tmp $!";
114 process_some_info($v,$df, 'source-info.txt');
115 foreach my $ocean (sort keys %oceans) {
116 process_some_info($v,$df, '_ocean-'.(lc $ocean).'.txt');
120 rename "$dfn.tmp", "$dfn" or die $!;
132 return scalar shift @ARGV;
135 while (@ARGV && $ARGV[0] =~ m/^-/) {
140 die if defined $rsyncdir;
143 push @specoceans, optarg();
157 die if @specoceans && $alloceans;
158 die if $backup && !$alloceans && !@specoceans;
160 parse_info_serverside();
163 my @oceans= $alloceans ? (sort keys %oceans) : @specoceans;
164 foreach my $ocean (@oceans) {
165 print "## database backup for $ocean\n";
169 $dbh->selectall_arrayref("SELECT * FROM commods WHERE commodid=1");
170 my $src= db_filename();
171 my $dst= $src; $dst =~ s,.*/,,; $dst= "$rsyncdir/$dst";
172 copy($src,"$dst.tmp") or die "$src -> $dst.tmp $!";
173 rename("$dst.tmp",$dst) or die "$dst.tmp -> $dst $!";
176 } elsif (@specoceans) {
177 print "### full update of specified oceans ...\n";
178 foreach my $ocean (@specoceans) {
179 die "$ocean ?" unless defined $oceans{$ocean};
182 } elsif ($alloceans) {
183 print "### full (inc.topology) update of all oceans ...\n";
184 foreach my $ocean (sort keys %oceans) {
188 print "### quick (no topology) update only (of all oceans) ...\n";
189 foreach my $ocean (sort keys %oceans) {
194 if (defined $rsyncdir and !$backup) {
195 print "### master-info update ...\n";
196 update_master_info();