-
Notifications
You must be signed in to change notification settings - Fork 1
/
tahconfig.pm
310 lines (257 loc) · 9.76 KB
/
tahconfig.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
use strict;
#--------------------------------------------------------------------------
# Reads a tiles@home config file, returns a hash array
#--------------------------------------------------------------------------
sub ReadConfig {
my %Config;
while ( my $Filename = shift() ) {
open( my $fp, "<$Filename" ) || die("Can't open \"$Filename\" ($!)\n");
while ( my $Line = <$fp> ) {
$Line =~ s/#.*$//; # Comments
$Line =~ s/\s*$//; # Trailing whitespace
if (
$Line =~ m{
^
\s*
([A-Za-z0-9._-]+) # Keyword: just one single word no spaces
\s* # Optional whitespace
= # Equals
\s* # Optional whitespace
(.*) # Value
}x
)
{
# Store config options in a hash array
$Config{$1} = $2;
print "Found $1 ($2)\n" if (0); # debug option
}
}
close $fp;
}
ApplyConfigLogic( \%Config );
return %Config;
}
#--------------------------------------------------------------------------
# Any application-specific knowledge regarding config file options
# e.g. correct common errors in config files, or enforce naming conventions
#--------------------------------------------------------------------------
sub ApplyConfigLogic {
my $Config = shift();
$Config->{OsmUsername} =~ s/@/%40/; # Encode the @-symbol in OSM passwords
if ( !defined( $Config->{"Layers"} ) ) {
$Config->{"Layers"} = "default";
}
# check layer configuration and if not present, use sensible defaults
foreach my $layer ( split( /,/, $Config->{"Layers"} ) ) {
$Config->{"Layer.$layer.MaxZoom"} = 18
unless defined( $Config->{"Layer.$layer.MaxZoom"} );
$Config->{"Layer.$layer.MinZoom"} = 12
unless defined( $Config->{"Layer.$layer.MinZoom"} );
for (
my $zoom = $Config->{"Layer.$layer.MinZoom"} ;
$zoom <= $Config->{"Layer.$layer.MaxZoom"} ;
$zoom++
)
{
if ( !defined( $Config->{"Layer.$layer.Rules.$zoom"} ) ) {
if ( $layer eq "default" ) {
$Config->{"Layer.$layer.Rules.$zoom"} =
"osm-map-features-z$zoom.xml";
}
}
}
if ( !defined( $Config->{"Layer.$layer.Prefix"} ) ) {
if ( $layer eq "default" ) {
$Config->{"Layer.$layer.Prefix"} = "tile";
}
}
if ( !defined( $Config->{"Layer.$layer.Overlay"} ) ) {
$Config->{"Layer.$layer.Overlay"} = 0;
}
if ( !defined( $Config->{"Layer.$layer.RenderFullTileset"} ) ) {
$Config->{"Layer.$layer.RenderFullTileset"} = 0;
}
}
## check for Pngcrush config option and set to default if not found
$Config->{"Pngcrush"} = "pngcrush" unless defined( $Config->{"Pngcrush"} );
## check for Mogrify config option and set to default if not found
$Config->{"Mogrify"} = "mogrify" unless defined( $Config->{"Mogrify"} );
## check for Mogrify config option and set to default if not found
$Config->{"MogrifyOptions"} = " -filter Sinc -resize x256 -virtual-pixel mirror "
unless defined( $Config->{"MogrifyOptions"} );
## check for AAL config option and set to default if not found
$Config->{"AAL"} = 2 unless defined( $Config->{"AAL"} );
## check for DiSKPerformance config option and set to default if not found
$Config->{"DiSKPerformance"} = "2000" unless defined( $Config->{"DiSKPerformance"} );
}
#--------------------------------------------------------------------------
# Checks a tiles@home configuration
#--------------------------------------------------------------------------
sub CheckConfig {
my %Config = @_;
my %EnvironmentInfo;
printf "- Using working directory %s\n", $Config{"WorkingDirectory"};
# Inkscape version
my $InkscapeV = `$Config{Inkscape} --version`;
$EnvironmentInfo{Inkscape} = $InkscapeV;
if ( $InkscapeV !~ /Inkscape (\d+)\.(\d+\.?\d*)/ ) {
die("Can't find inkscape (using \"$Config{Inkscape}\")\n");
}
if ( ($1 == 0) ) {
if ($2 < 45.0) {
die("not supported version of Inkscape\@home\n");
}
else {
$EnvironmentInfo{Inkscape1} = 0;
}
}
else {
$EnvironmentInfo{Inkscape1} = 1;
}
print "- Inkscape version $1.$2\n";
# XmlStarlet version
my $XmlV = `$Config{XmlStarlet} --version`;
$EnvironmentInfo{Xml} = $XmlV;
if ( $XmlV !~ /(\d+\.\d+\.\d+)/ ) {
die("Can't find xmlstarlet (using \"$Config{XmlStarlet}\")\n");
}
print "- xmlstarlet version $1\n";
# Zip version
$Config{Zip} = "zip" unless defined( $Config{Zip} );
my $ZipV = `$Config{Zip} -h`;
$EnvironmentInfo{Zip} = $ZipV;
if ( $ZipV eq "" ) {
die("Can't find zip (using \"$Config{Zip}\")\n");
}
print "- zip is present\n";
# PNGCrush version
# CentOS 6.3, pngcrush (1.7.53 from rpmforge repo) prints version information to STDERR
my $PngcrushV = `$Config{Pngcrush} -version 2>&1`;
$EnvironmentInfo{Pngcrush} = $PngcrushV;
if ( $PngcrushV !~ /[Pp]ngcrush\s+(\d+\.\d+\.?\d*)/ ) {
# die here if pngcrush shall be mandatory
die("Can't find pngcrush (using \"$Config{Pngcrush}\")\n");
}
print "- pngcrush version $1\n";
# Mogrify version
my $MogrifyV = `$Config{Mogrify} -version`;
$EnvironmentInfo{Mogrify} = $MogrifyV;
if ( $MogrifyV !~ /[Vv]ersion:\s+[Ii]mage[Mm]agick\s+(\d+\.\d+\.?\d*)/ ) {
# die here if mogrify shall be mandatory
die("Can't find mogrify (using \"$Config{Mogrify}\")\n");
}
print "- mogrify version $1\n";
if ( $Config{"LocalSlippymap"} ) {
print "- Writing LOCAL slippy map directory hierarchy, no uploading\n";
}
else {
# Upload URL, username
printf "- Uploading with username \"$Config{UploadUsername}\"\n",;
if ( $Config{"UploadPassword"} =~ /\W/ ) {
die("Check your upload password\n");
}
if ( $Config{"UploadURL"} ne $Config{"UploadURL2"} ) {
printf "! Please set UploadURL to %s, this will become the default "
. "UploadURL soon\n", $Config{"UploadURL2"};
}
if ( $Config{"UploadChunkSize"} > 2 ) {
print "! Upload chunks may be too large for server\n";
}
if ( $Config{"UploadChunkSize"} < 0.1 ) {
$Config{"UploadChunkSize"} = 1;
print "! Using default upload chunk size of 1.0 MB\n";
}
# $Config{"UploadURL2"};
if ( $Config{"DeleteZipFilesAfterUpload"} ) {
print "- Deleting ZIP files after upload\n";
}
}
if ( $Config{"RequestUrl"} ) {
print "- Using $Config{RequestUrl} for Requests\n";
}
# OSM username
if ( $Config{DiSKUsername} !~ /%40/ ) {
die(
"DiSKUsername should be an email address, with the \@ replaced by %40\n"
);
}
print "- Using DiSK username \"$Config{DiSKUsername}\"\n";
# $Config{"OsmPassword"};
# Misc stuff
foreach (qw(N S E W)) {
if ( $Config{"Border$_"} > 0.5 ) {
printf "Border$_ looks abnormally large\n";
}
}
# layers
foreach my $layer ( split( /,/, $Config{"Layers"} ) ) {
print "- Configured Layer: $layer\n";
if ( $Config{"Layers.LowZoom"} )
{
if ( $Config{"Layer.$layer.MinZoom"} < 5
|| $Config{"Layer.$layer.MinZoom"} > 11 )
{
print "Check Layer.$layer.MinZoom\n";
}
if ( $Config{"Layer.$layer.MaxZoom"} < 5
|| $Config{"Layer.$layer.MaxZoom"} > 11 )
{
print "Check Layer.$layer.MaxZoom\n";
}
}
else
{
if ( $Config{"Layer.$layer.MinZoom"} < 12
|| $Config{"Layer.$layer.MinZoom"} > 20 )
{
print "Check Layer.$layer.MinZoom\n";
}
if ( $Config{"Layer.$layer.MaxZoom"} < 12
|| $Config{"Layer.$layer.MaxZoom"} > 20 )
{
print "Check Layer.$layer.MaxZoom\n";
}
}
if (
$Config{"Layer.$layer.MaxZoom"} < $Config{"Layer.$layer.MinZoom"} )
{
print "Check Layer.$layer.MaxZoom vs. Layer.$layer.MinZoom\n";
}
for (
my $zoom = $Config{"Layer.$layer.MinZoom"} ;
$zoom <= $Config{"Layer.$layer.MaxZoom"} ;
$zoom++
)
{
if ( !defined( $Config{"Layer.$layer.Rules.$zoom"} ) ) {
die "config option Layer.$layer.Rules.$zoom is not set";
}
if ( !-f $Config{"Layer.$layer.Rules.$zoom"} ) {
die "rules file "
. $Config{"Layer.$layer.Rules.$zoom"}
. " referenced by config option Layer.$layer.Rules.$zoom "
. "is not present";
}
}
if ( !defined( $Config{"Layer.$layer.Prefix"} ) ) {
die "config option Layer.$layer.Prefix is not set";
}
# any combination of comma-separated preprocessor names is allowed
die "config option Layer.$layer.Preprocessor has invalid value"
if (
grep {
$_ !~
/maplint|close-areas|simplify|mercator|reduce|simplifyNames|relation/
} split( /,/, $Config{"Layer.$layer.Preprocessor"} )
);
foreach
my $reqfile ( split( /,/, $Config{"Layer.$layer.RequiredFiles"} ) )
{
die "file $reqfile required for layer $layer as per config option "
. "Layer.$layer.RequiredFiles not found"
unless ( -f $reqfile );
}
}
return %EnvironmentInfo;
}
1;