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

Revision 11607, 3.4 KB checked in by joerg, 5 years ago (diff)

map-icons/tools: move all scripts into there own tools directory

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