chiark / gitweb /
Merge branch 'stable-3.x'
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 9 Sep 2009 20:46:04 +0000 (21:46 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 9 Sep 2009 20:46:04 +0000 (21:46 +0100)
1  2 
yarrg/source-info.txt
yarrg/update-master-info

diff --combined yarrg/source-info.txt
index 35a13aa618443c83bd793749245e152effbe73e5,b7d285b620601fbe29ce39fb5416287a3cb9cc4b..88b93113ff41ee5bc8b4c55c387733be0dd58e9b
@@@ -1,36 -1,4 +1,36 @@@
  
 +vessels
 +#|   Ship Name    |Gun Size|Volume | Mass  |
 + |Sloop           |small   |20,250 |13,500 |
 + |----------------+--------+-------+-------|
 + |Cutter          |small   |60,750 |40,500 |
 + |----------------+--------+-------+-------|
 + |Dhow            |medium  |20,250 |13,500 |
 + |----------------+--------+-------+-------|
 + |Longship        |small   |20,250 |13,500 |
 + |----------------+--------+-------+-------|
 + |Baghlah         |medium  |27,000 |18,000 |
 + |----------------+--------+-------+-------|
 + |Merchant brig   |medium  |135,000|90,000 |
 + |----------------+--------+-------+-------|
 + |War brig        |medium  |81,000 |54,000 |
 + |----------------+--------+-------+-------|
 + |Merchant galleon|large   |405,000|270,000|
 + |----------------+--------+-------+-------|
 + |Xebec           |medium  |182,250|121,500|
 + |----------------+--------+-------+-------|
 + |War frigate     |large   |324,000|216,000|
 + |----------------+--------+-------+-------|
 + |Grand frigate   |large   |810,000|540,000|
 +# From http://yppedia.puzzlepirates.com/Ship; when updating,
 +# delete unused columns and check heading is the same as above.
 +# If fields reordered must change parser in Commods.pm.
 +
 +shot
 + small        2
 + medium       3
 + large        4
 +
  commods
   kraken's blood               1kg
   %c dye                       1kg
@@@ -177,6 -145,7 +177,7 @@@ ocean Ic
  ocean Hunter
   Eagle
    Ix Chel
+   Manu Island
  
  ocean Malachite
   Draco
diff --combined yarrg/update-master-info
index b16e7b4704b4e486b4426ad423a81656bdd4d873,c0bbbffe1a303928159b120e66ebef046b55f8ef..e2b0973db453b093e9b6f261b60c5f2969701e8b
@@@ -26,6 -26,9 +26,9 @@@
  #         ./update-master-info -a
  #    and check that nothing unexpected changes.
  #
+ #    To just make backups of the databases into the rsync directory:
+ #         ./update-master-info -b -d ~ftp/users/ijackson/yarrg/ -a
+ #         ./update-master-info -b -d ~ftp/users/ijackson/yarrg/ -O ...
  
  # This is part of ypp-sc-tools, a set of third-party tools for assisting
  # players of Yohoho Puzzle Pirates.
@@@ -52,6 -55,8 +55,8 @@@
  use strict (qw(vars));
  use DBI;
  use Commods;
+ use CommodsDatabase;
+ use File::Copy;
  
  $ENV{'LC_CTYPE'}= 'en_GB.UTF-8';
  
@@@ -90,7 -95,7 +95,7 @@@ sub process_some_info ($$$) 
            next if $h =~ m/^nocommods/;
        }
        next if $sfn =~ m/source-info/ && $h =~ m/^ocean\b/;
 -      next if $h =~ m/^client\b/;
 +      next if $h =~ m/^client|^vessels|^shot\b/;
  
        print $df $_, "\n" or die $!;
      }
@@@ -119,6 -124,7 +124,7 @@@ sub update_master_info () 
  
  my @specoceans;
  my $alloceans;
+ my $backup;
  
  sub optarg () {
      return $_ if length;
@@@ -135,7 -141,10 +141,10 @@@ while (@ARGV && $ARGV[0] =~ m/^-/) 
            $rsyncdir= optarg();
        } elsif (s/^-O//) {
            push @specoceans, optarg();
-       } elsif (s/^-a//) {
+       } elsif (s/^-b/-/) {
+           die if $backup;
+           $backup=1;
+       } elsif (s/^-a/-/) {
            die if $alloceans;
            $alloceans=1;
        } else {
  die if @ARGV;
  
  die if @specoceans && $alloceans;
+ die if $backup && !$alloceans && !@specoceans;
  
  parse_info_serverside();
  
- if (@specoceans) {
+ if ($backup) {
+     my @oceans= $alloceans ? (sort keys %oceans) : @specoceans;
+     foreach my $ocean (@oceans) {
+       print "## database backup for $ocean\n";
+       db_setocean($ocean);
+       db_writer();
+       db_connect();
+       $dbh->selectall_arrayref("SELECT * FROM commods WHERE commodid=1");
+       my $src= db_filename();
+       my $dst= $src; $dst =~ s,.*/,,; $dst= "$rsyncdir/$dst";
+       copy($src,"$dst.tmp") or die "$src -> $dst.tmp $!";
+       rename("$dst.tmp",$dst) or die "$dst.tmp -> $dst $!";
+       $dbh->rollback();
+     }
+ } elsif (@specoceans) {
      print "### full update of specified oceans ...\n";
      foreach my $ocean (@specoceans) {
        die "$ocean ?" unless defined $oceans{$ocean};
      }
  }
  
- if (defined $rsyncdir) {
+ if (defined $rsyncdir and !$backup) {
      print "### master-info update ...\n";
      update_master_info();
  }