source: subversion/applications/share/map-icons/copy_icons_to_debian_package_dirs.pl @ 7091

Last change on this file since 7091 was 7091, checked in by joerg, 12 years ago

copy_icons_to_debian_package_dirs.pl: add usage, change getting filename from geoinfo->name to condition->[k=poi]=xx

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#!/usr/bin/perl -w
2# This little helper copies according to the icons.xml File
3# and the geoinfo->restrictions tag
4# all icons will be placed into there package directory
5# For more Inco see --man option
6
7use strict;
8use warnings;
9use Data::Dumper;
10use XML::Simple;
11use File::Basename;
12use File::Path;
13use File::Copy;
14use Getopt::Long;
15use Pod::Usage;
16
17my $file = 'icons';
18
19die "Can't find file \"$file.xml\""
20    unless -f "$file.xml";
21
22my $dst_path="/usr/share/icons/map-icons";
23my $src_dir="build/";
24my $package_path = {
25    ''      => 'debian/openstreetmap-map-icons',
26    'brand' => 'debian/openstreetmap-map-icons-restricted',
27};
28
29
30my @theme_dirs=qw(classic.big classic.small
31                  japan japan_tn
32                  nickw
33                  square.big square.small
34                  svg svg_tn
35                  );
36
37my ($man,$help,$DEBUG,$VERBOSE)=(0,0,0,0);
38# Set defaults and get options from command line
39Getopt::Long::Configure('no_ignore_case');
40GetOptions ( 
41             'd+'                  => \$DEBUG,
42             'debug+'              => \$DEBUG,     
43             'verbose'             => \$VERBOSE,
44             'v+'                  => \$VERBOSE,
45             'h|help|x'            => \$help, 
46             )
47    or pod2usage(1);
48
49pod2usage(1) if $help;
50pod2usage(-verbose=>2) if $man;
51
52
53#-----------------------------------------------------------------------------
54my $rules = XMLin("$file.xml",
55                  ForceArray => [ 'condition' ],
56    );
57my @rules=@{$rules->{rule}};
58for my $rule (@rules) {
59    print Dumper(\$rule) if $DEBUG >10;
60    my $restricted = $rule->{'geoinfo'}->{'restricted'}||'';
61    my $names = $rule->{'condition'};
62    my ($name) = grep { $_->{k} =~ /^poi|rendering$/ } @{$names};
63    $name = $name->{v};
64    print "name: '$name'\n" if $VERBOSE;
65    if ( ! $name ) {
66        warn "Undefined Name\n";
67        warn Dumper(\$rule);
68        next;
69    }
70    $name =~ s,\.,/,g;
71
72    if ( ! defined($package_path->{$restricted})) {
73        die "Wrong or unknown restriction '$restricted'\n";
74    }
75   
76    for my $theme ( @theme_dirs) {
77        #print STDERR "Copy  $theme/$name for Theme\n";
78        my $found=0;
79        for my $fn_icon ( "$theme/$name.png","$theme/$name.svg"){
80            my $src_fn="$src_dir/$fn_icon";
81            my $dst_fn=$package_path->{$restricted}."$dst_path/".$fn_icon;
82            if ( -s $src_fn) {
83                print STDERR "$fn_icon  ---> $dst_fn\n" if $VERBOSE>2 || $DEBUG;
84                my $dir = dirname($dst_fn);
85                mkpath $dir  || warn "Cannot create $dir:$!\n";
86                copy($src_fn,$dst_fn)  || warn "Cannot copy $src_fn,$dst_fn:$!\n";;
87                $found++;
88            }   
89        }
90        # print STDERR "No File for $theme/$name found\n" unless $found;
91    };
92};
93 
94my $write_output=0;
95if ( $write_output) {
96    my $xml = XMLout($rules);
97    my $fo = IO::File->new(">$file-out.xml");
98    print  $fo $xml;
99    $fo->close();
100}
101
102
103__END__
104
105=head1 NAME
106
107B<copy_icons_to_debian_package_dirs.pl> Version 0.1
108
109=head1 DESCRIPTION
110
111B<copy_icons_to_debian_package_dirs.pl> is a program to copy
112This little helper copies according to the icons.xml File
113and the geoinfo->restrictions tag
114all icons will be placed into there package directory
115the default src_dir if build/*
116
117
118=head1 SYNOPSIS
119
120B<Common usages:>
121
122geoinfo.pl [-d] [--man]
123
124=item B<--man>
125
126Print this small usage
127
128=item B<-d>
129
130Add some more Debug Output
131
132=back
Note: See TracBrowser for help on using the repository browser.