1 | #! /usr/bin/perl -w
|
---|
2 |
|
---|
3 | # Written by Dirk Stöcker <openstreetmap@dstoecker.de>
|
---|
4 | # Public domain, no rights reserved.
|
---|
5 |
|
---|
6 | use strict;
|
---|
7 | use LWP::Simple;
|
---|
8 | use open qw/:std :encoding(utf8)/;
|
---|
9 |
|
---|
10 | my $filename;
|
---|
11 | my $dir = $ARGV[1] || "build/josmfiles";
|
---|
12 | if($ARGV[0] && $ARGV[0] =~ /^http:\/\//)
|
---|
13 | {
|
---|
14 | $filename = $ARGV[2] || "build/josmfiles.zip";
|
---|
15 | my $content = get($ARGV[0]);
|
---|
16 | die "Couldn't get $ARGV[0]" unless defined $content;
|
---|
17 | open FILE,">:raw",$filename or die "Could not open $filename";
|
---|
18 | print FILE $content;
|
---|
19 | close FILE
|
---|
20 | }
|
---|
21 | else
|
---|
22 | {
|
---|
23 | $filename = $ARGV[0];
|
---|
24 | }
|
---|
25 | system "rm -rf $dir/";
|
---|
26 | print "Extracting to $dir\n";
|
---|
27 | mkdir $dir;
|
---|
28 | system "unzip -q -d $dir $filename";
|
---|
29 | foreach my $name (glob "$dir/*")
|
---|
30 | {
|
---|
31 | if($name =~ /^(.*?)([^\/]+-preset\.xml)$/)
|
---|
32 | {
|
---|
33 | system "mv $name $name.orig";
|
---|
34 | my ($path, $xmlname) = ($1, $2);
|
---|
35 | my $res = `xmllint --format --schema ../core/data/tagging-preset.xsd $name.orig --encode utf-8 --output $name 2>&1`;
|
---|
36 | print $res if $res !~ /\.orig validates/;
|
---|
37 | system "perl convpreset.pl $name >${path}trans_$xmlname";
|
---|
38 | unlink "$name.orig";
|
---|
39 | }
|
---|
40 | elsif($name =~ /^(.*?)([^\/]+-style\.xml$)/)
|
---|
41 | {
|
---|
42 | system "perl convstyle.pl $name >${1}trans_$2";
|
---|
43 | }
|
---|
44 | elsif($name =~ /^(.*?)([^\/]+\.mapcss)$/)
|
---|
45 | {
|
---|
46 | system "perl convcss.pl $name >${1}trans_$2";
|
---|
47 | }
|
---|
48 | else
|
---|
49 | {
|
---|
50 | die "Unknown file type $name.";
|
---|
51 | }
|
---|
52 | unlink $name;
|
---|
53 | }
|
---|