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 BEGIN { unshift @INC, qw(.) }
57 use strict (qw(vars));
63 $ENV{'LC_CTYPE'}= 'en_GB.UTF-8';
68 print "## updating topology of $ocean\n";
69 system('./yppedia-chart-parser',$ocean); die "$ocean $?" if $?;
75 print STDERR "## updating schema and commodities for $ocean\n";
76 system('./db-idempotent-populate',$ocean); die $? if $?;
81 sub process_some_info ($$$) {
82 my ($v,$df,$sfn) = @_;
83 my $sf= new IO::File $sfn or die "$sfn $!";
88 next if m/^\s*\#/ || !m/\S/;
92 die "$_ ?" unless defined $h;
93 if ($h =~ m/^commods|^\%[a-z]\b/) {
97 next if $h =~ m/^nocommods/;
99 next if $sfn =~ m/source-info/ && $h =~ m/^ocean\b/;
100 next if $h =~ m/^client|^vessels|^shot\b|^commodclasses/;
102 print $df $_, "\n" or die $!;
105 $sf->error and die $!;
108 sub update_master_info () {
109 foreach my $v (1..$masterinfoversion) {
110 my $dfnl= sprintf "master-info%s.txt", ($v>1 ? "-v$v" : '');
111 print STDERR "installing new $dfnl...\n";
113 my $dfn= "$rsyncdir/$dfnl";
114 my $df= new IO::File "$dfn.tmp", 'w' or die "$dfn.tmp $!";
116 process_some_info($v,$df, 'source-info.txt');
117 foreach my $ocean (sort keys %oceans) {
118 process_some_info($v,$df, '_ocean-'.(lc $ocean).'.txt');
122 rename "$dfn.tmp", "$dfn" or die $!;
134 return scalar shift @ARGV;
137 while (@ARGV && $ARGV[0] =~ m/^-/) {
142 die if defined $rsyncdir;
145 push @specoceans, optarg();
159 die if @specoceans && $alloceans;
160 die if $backup && !$alloceans && !@specoceans;
162 parse_info_serverside();
165 my @oceans= $alloceans ? (sort keys %oceans) : @specoceans;
166 foreach my $ocean (@oceans) {
167 print "## database backup for $ocean\n";
171 $dbh->selectall_arrayref("SELECT * FROM commods WHERE commodid=1");
172 my $src= db_filename();
173 my $dst= $src; $dst =~ s,.*/,,; $dst= "$rsyncdir/$dst";
174 copy($src,"$dst.tmp") or die "$src -> $dst.tmp $!";
175 rename("$dst.tmp",$dst) or die "$dst.tmp -> $dst $!";
178 } elsif (@specoceans) {
179 print "### full update of specified oceans ...\n";
180 foreach my $ocean (@specoceans) {
181 die "$ocean ?" unless defined $oceans{$ocean};
184 } elsif ($alloceans) {
185 print "### full (inc.topology) update of all oceans ...\n";
186 foreach my $ocean (sort keys %oceans) {
190 print "### quick (no topology) update only (of all oceans) ...\n";
191 foreach my $ocean (sort keys %oceans) {
196 if (defined $rsyncdir and !$backup) {
197 print "### master-info update ...\n";
198 update_master_info();