source: trunk/npemap.org.uk/scripts/tile-processing/upload.pl @ 712

Last change on this file since 712 was 712, checked in by Nick Burch, 10 years ago

Per-decade support in tile scripts

  • Property svn:executable set to *
File size: 3.4 KB
Line 
1#!/usr/bin/perl
2#
3# Copyright (c) 2006-2007 Nick Burch
4# Permission is hereby granted, free of charge, to any person obtaining a
5# copy of this software and associated documentation files (the "Software"),
6# to deal in the Software without restriction, including without limitation
7# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8# and/or sell copies of the Software, and to permit persons to whom the
9# Software is furnished to do so, subject to the following conditions:
10#
11# The above copyright notice and this permission notice shall be included in
12# all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20# IN THE SOFTWARE.
21#
22use strict;
23
24# Path to the scale directory on each server
25my %servers;
26#$servers{dev} = "/usr/local/OSGB/";
27#$servers{encore} = "/usr/local/maps/OSGB/";
28$servers{urchin} = "/srv/www/tile.npemap.org.uk/html/";
29#$servers{bitclean} = "/home/bitclean/public_html/";
30#$servers{openstreetmap} = "/home/dsheldon/npetiles/";
31
32# Allow restricting to just one server
33if($ARGV[0] && $servers{$ARGV[0]}) {
34        my $srv = shift @ARGV;
35        print "Restricting to just server $srv\n";
36        my %srvs;
37        $srvs{$srv} = $servers{$srv};
38        %servers = %srvs;
39}
40
41# Process the rest of the arguments
42my $scale = shift @ARGV;
43my @args = @ARGV;
44
45unless($scale && $args[0]) {
46        print "Use:\n";
47        print "  upload.pl <scale> [easting] [easting] [easting....]\n";
48        print "\n";
49        print "Will upload the specified easting directories to all 3 servers\n";
50        exit 1;
51}
52unless($scale == 1 || $scale == 3 || $scale == 6 || $scale eq 'm') {
53        die("Scale must be the 1st argument, and one of 1, 3, 6 or m\n");
54}
55
56# Check they're in the right directory
57my $curdir = `pwd`;
58chomp $curdir;
59print "$curdir\n";
60if($scale eq "m") { $curdir =~ s/meta1$/scaledm/; }
61unless($curdir =~ /scaled$scale$/) {
62    die("Can't upload for scale $scale from directory $curdir\n");
63}
64
65# Do they want to upload to osgb, or osie?
66my $remote_append = "";
67if($curdir =~ /\/ni-maps\//) {
68    print "Detected OS Northern Ireland tiles, uploading to osie\n\n";
69    $remote_append = "osie/";
70} else {
71    $remote_append = "osgb/";
72}
73
74# Are they uploading the latest tiles, or ones for just one
75#  decade?
76if($curdir =~ /\/(19[0-6]0s)\//) {
77    my $decade = $1;
78    print "Decade is set to the $decade\n";
79    $remote_append .= $decade."/";
80} else {
81    print "No decade restriction, uploading latest tiles\n";
82    $remote_append .= "latest/";
83}
84
85# Report what we're going to do
86print "\n";
87print "About to upload ".join(" ",@args)." for scale $scale\n\n";
88
89my $dir = "scaled$scale/";
90if($scale eq 'm') {
91        $dir = "meta1/";
92}
93
94# Upload each in turn
95foreach my $server (reverse sort keys %servers) {
96        my $path = $servers{$server} . $remote_append . $dir;
97
98        my $cmd = "rsync -avc --bwlimit=96 ".join(" ",@args)." $server:$path";
99        print $cmd."\n";
100        print `$cmd 1>&2`;
101}
102print "\n\n";
103
104# Fix permissions on urchin
105my $cmd = "ssh urchin 'cd $servers{urchin}$remote_append$dir && chown -R .npemap ".join(" ",@args)."'"; 
106print $cmd."\n";
107`$cmd`;
108
109# Done
110print "\n\n";
Note: See TracBrowser for help on using the repository browser.