source: subversion/applications/rendering/tilesAtHome/tilesGen.pl @ 30554

Last change on this file since 30554 was 21947, checked in by deelkar, 9 years ago

radical code cleanup

  • Property svn:executable set to *
  • Property svn:keywords set to Revision
File size: 5.1 KB
Line 
1#!/usr/bin/perl
2#-------------------------------------------------------------
3# OpenStreetMap tiles@home
4#
5# Contact Deelkar or OJW on the Openstreetmap wiki for help using this program
6#-----------------------------------------------------------------------------
7# Copyright 2006, Oliver White, Etienne Cherdlu, Dirk-Lueder Kreie,
8# Sebastian Spaeth and others
9#
10# This program is free software; you can redistribute it and/or
11# modify it under the terms of the GNU General Public License
12# as published by the Free Software Foundation; either version 2
13# of the License, or (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23#-----------------------------------------------------------------------------
24
25use warnings;
26use strict;
27use lib './lib';
28use File::Copy;
29use File::Path;
30use File::Temp qw(tempfile);
31use File::Spec;
32use Scalar::Util qw(blessed);
33use IO::Socket;
34use Error qw(:try);
35use tahlib;
36use TahConf;
37use Tileset;
38use Server;
39use Request;
40use Upload;
41use SVG::Rasterize;
42use SVG::Rasterize::CoordinateBox;
43use English '-no_match_vars';
44use POSIX;
45
46#---------------------------------
47
48# Read the config file
49my $Config = TahConf->getConfig();
50
51# Handle the command-line
52our $Mode = shift() || '';
53my $LoopMode = (($Mode eq "loop") or ($Mode eq "upload_loop")) ? 1 : 0;
54my $RenderMode = (($Mode eq "") or ($Mode eq "xy") or ($Mode eq "loop")) ? 1 : 0;
55my $UploadMode = (($Mode eq "upload") or ($Mode eq "upload_loop")) ? 1 : 0;
56my %EnvironmentInfo;
57
58# Override *nix locales
59delete $ENV{LC_ALL};
60delete $ENV{LC_NUMERIC};
61delete $ENV{LANG};
62$ENV{LANG} = 'C';
63
64if ($RenderMode)
65{   # need to check that we can render and stuff
66    %EnvironmentInfo = $Config->CheckConfig();
67}
68else
69{   # for uploading we need only basic settings
70    %EnvironmentInfo = $Config->CheckBasicConfig();
71}
72
73# set the progress indicator variables
74our $currentSubTask;
75my $progress = 0;
76our $progressJobs = 1;
77our $progressPercent = 0;
78
79my $LastTimeVersionChecked = 0;   # version is only checked when last time was more than 10 min ago
80
81UpdateClient();
82reExec(-1);
83
84#-----------------------------------------------------------------------------
85# Gets latest copy of client from svn repository
86# returns 1 on perceived success.
87#-----------------------------------------------------------------------------
88sub UpdateClient
89{
90    my $Config = TahConf->getConfig();
91    my $Cmd = sprintf("\"%s\" %s",
92        $Config->get("Subversion"),
93        $Config->get("SubversionUpdateCmd"));
94
95    if (ClientModified())
96    {
97        return cleanUpAndDie("Auto-update failed","EXIT",1);
98    }
99   
100    statusMessage("Updating the Client",1,0);
101    if (runCommand($Cmd,$PID)) # FIXME: evaluate output and handle locally changed files that need updating!
102    {
103        my $versionfile = "version.txt";
104        DownloadFile($Config->get("VersionCheckURL"), $versionfile ,0);
105       
106        return 1;
107    }
108    else  # runCommand failed somehow
109    {
110        statusMessage("Update Failed for some reason. Check \"subversion\" is installed.",1,0);
111        statusMessage("Command run was: \n".$Cmd,1,0);
112    }
113}
114
115#-----------------------------------------------------------------------------
116# Checks svn status for local code modifications
117# returns 1 if such modifications exist
118#-----------------------------------------------------------------------------
119sub ClientModified
120{
121    my $Cmd = sprintf("\"%s\" %s",
122        $Config->get("Subversion"),
123        "status -q --ignore-externals");
124
125    my $svn_status = `$Cmd`;
126
127    chomp $svn_status;
128
129    if ($svn_status ne '')
130    {
131        statusMessage("svn status did not come back clean, check your installation",1,0);
132        print STDERR $svn_status;
133    }
134    return ($svn_status ne '');
135}
136
137sub NewClientVersion 
138{
139    return 1; # this client is outdated, using tags of tilesAtHome-dev now.
140}
141
142
143#-----------------------------------------------------------------------------
144# A function to re-execute the program. 
145#
146# This function restarts the program unconditionally.
147#-----------------------------------------------------------------------------
148sub reExec
149{
150    my $child_pid = shift();## FIXME: make more general
151    my $Config = TahConf->getConfig();
152    # until proven to work with other systems, only attempt a re-exec
153    # on linux.
154    return unless ($^O eq "linux" || $^O eq "cygwin" ||  $^O eq "darwin");
155
156    statusMessage("tilesGen.pl has changed, re-start new version",1,0);
157    if ($Config->get("ForkForUpload") && $child_pid != -1)  ## FIXME: make more general
158    {
159        statusMessage("Waiting for child process (this can take a while)",1,0);
160        waitpid($child_pid, 0);
161    }
162    exec "perl", $0, $Mode, "reexec", 
163        "progressJobs=" . $progressJobs, 
164        "idleSeconds=" . getIdle(1), 
165        "idleFor=" . getIdle(0) or die("could not reExec");
166}
167
Note: See TracBrowser for help on using the repository browser.