[31111] | 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";
|
---|
[33234] | 12 | print "$ARGV[0]\n";
|
---|
[33756] | 13 | if($ARGV[0] && $ARGV[0] =~ /^https?:\/\//)
|
---|
[31111] | 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 | {
|
---|
[33841] | 34 | system "mv \"$name\" \"$name.orig\"";
|
---|
[31111] | 35 | my ($path, $xmlname) = ($1, $2);
|
---|
[33841] | 36 | my $res = `xmllint --format --schema ../core/data/tagging-preset.xsd \"$name.orig\" --encode utf-8 --output \"$name\" 2>&1`;
|
---|
[31111] | 37 | print $res if $res !~ /\.orig validates/;
|
---|
[33841] | 38 | system "perl convpreset.pl \"$name\" >\"${path}trans_$xmlname\"";
|
---|
[31111] | 39 | unlink "$name.orig";
|
---|
| 40 | }
|
---|
| 41 | elsif($name =~ /^(.*?)([^\/]+-style\.xml$)/)
|
---|
| 42 | {
|
---|
[33841] | 43 | system "perl convstyle.pl \"$name\" >${1}trans_$2";
|
---|
[31111] | 44 | }
|
---|
| 45 | elsif($name =~ /^(.*?)([^\/]+\.mapcss)$/)
|
---|
| 46 | {
|
---|
[33841] | 47 | system "perl convcss.pl \"$name\" >${1}trans_$2";
|
---|
[31111] | 48 | }
|
---|
| 49 | else
|
---|
| 50 | {
|
---|
[33841] | 51 | die "Unknown file type \"$name\".";
|
---|
[31111] | 52 | }
|
---|
| 53 | unlink $name;
|
---|
| 54 | }
|
---|