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 | print "$ARGV[0]\n";
|
---|
13 | if($ARGV[0] && $ARGV[0] =~ /^http:\/\//)
|
---|
14 | {
|
---|
15 | $filename = $ARGV[2] || "build/josmfiles.zip";
|
---|
16 | my $content = get($ARGV[0]);
|
---|
17 | die "Couldn't get $ARGV[0]" unless defined $content;
|
---|
18 | open FILE,">:raw",$filename or die "Could not open $filename";
|
---|
19 | print FILE $content;
|
---|
20 | close FILE
|
---|
21 | }
|
---|
22 | else
|
---|
23 | {
|
---|
24 | $filename = $ARGV[0];
|
---|
25 | }
|
---|
26 | system "rm -rf $dir/";
|
---|
27 | print "Extracting to $dir\n";
|
---|
28 | mkdir $dir;
|
---|
29 | system "unzip -q -d $dir $filename";
|
---|
30 | foreach my $name (glob "$dir/*")
|
---|
31 | {
|
---|
32 | if($name =~ /^(.*?)([^\/]+-preset\.xml)$/)
|
---|
33 | {
|
---|
34 | system "mv $name $name.orig";
|
---|
35 | my ($path, $xmlname) = ($1, $2);
|
---|
36 | my $res = `xmllint --format --schema ../core/data/tagging-preset.xsd $name.orig --encode utf-8 --output $name 2>&1`;
|
---|
37 | print $res if $res !~ /\.orig validates/;
|
---|
38 | system "perl convpreset.pl $name >${path}trans_$xmlname";
|
---|
39 | unlink "$name.orig";
|
---|
40 | }
|
---|
41 | elsif($name =~ /^(.*?)([^\/]+-style\.xml$)/)
|
---|
42 | {
|
---|
43 | system "perl convstyle.pl $name >${1}trans_$2";
|
---|
44 | }
|
---|
45 | elsif($name =~ /^(.*?)([^\/]+\.mapcss)$/)
|
---|
46 | {
|
---|
47 | system "perl convcss.pl $name >${1}trans_$2";
|
---|
48 | }
|
---|
49 | else
|
---|
50 | {
|
---|
51 | die "Unknown file type $name.";
|
---|
52 | }
|
---|
53 | unlink $name;
|
---|
54 | }
|
---|