xref: /trunk/main/solenv/bin/packimages.pl (revision 81afc36f)
1cdf0e10cSrcweir:
2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}'
3cdf0e10cSrcweir    if 0;
47e90fac2SAndrew Rist#**************************************************************
57e90fac2SAndrew Rist#
67e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
77e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
87e90fac2SAndrew Rist#  distributed with this work for additional information
97e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
107e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
117e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
127e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
137e90fac2SAndrew Rist#
147e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
157e90fac2SAndrew Rist#
167e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
177e90fac2SAndrew Rist#  software distributed under the License is distributed on an
187e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
197e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
207e90fac2SAndrew Rist#  specific language governing permissions and limitations
217e90fac2SAndrew Rist#  under the License.
227e90fac2SAndrew Rist#
237e90fac2SAndrew Rist#**************************************************************
247e90fac2SAndrew Rist
257e90fac2SAndrew Rist
26cdf0e10cSrcweir
27cdf0e10cSrcweir#
28cdf0e10cSrcweir# packimages.pl - pack images into archives
29cdf0e10cSrcweir#
30cdf0e10cSrcweir
31cdf0e10cSrcweiruse strict;
32cdf0e10cSrcweiruse Getopt::Long;
33cdf0e10cSrcweiruse File::Find;
34cdf0e10cSrcweiruse File::Basename;
35cdf0e10cSrcweiruse Archive::Zip qw(:ERROR_CODES :CONSTANTS);
36cdf0e10cSrcweir
37cdf0e10cSrcweir#### globals ####
38cdf0e10cSrcweir
39cdf0e10cSrcweirmy $img_global = '%GLOBALRES%';  # 'global' image prefix
40cdf0e10cSrcweirmy $img_module = '%MODULE%';  # 'module' image prefix
41cdf0e10cSrcweir
42cdf0e10cSrcweirmy $out_file;                # path to output archive
43cdf0e10cSrcweirmy $tmp_out_file;            # path to temporary output file
44cdf0e10cSrcweirmy $global_path;             # path to global images directory
45cdf0e10cSrcweirmy $module_path;             # path to module images directory
46cdf0e10cSrcweirmy $sort_file;               # path to file containing sorting data
47cdf0e10cSrcweirmy @custom_path;             # path to custom images directory
4886e1cf34SPedro Giffunimy @imagelist_path;          # paths to directories containing the image lists
49cdf0e10cSrcweirmy $verbose;                 # be verbose
50cdf0e10cSrcweirmy $extra_verbose;           # be extra verbose
51cdf0e10cSrcweirmy $do_rebuild = 0;          # is rebuilding zipfile required?
52cdf0e10cSrcweir
53cdf0e10cSrcweirmy @custom_list;
54cdf0e10cSrcweir#### script id #####
55cdf0e10cSrcweir
56cdf0e10cSrcweir( my $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
57cdf0e10cSrcweir
58cdf0e10cSrcweirmy $script_rev;
59b9fd132dSpfgmy $id_str = ' $Revision$ ';
60cdf0e10cSrcweir$id_str =~ /Revision:\s+(\S+)\s+\$/
61cdf0e10cSrcweir  ? ($script_rev = $1) : ($script_rev = "-");
62cdf0e10cSrcweir
63cdf0e10cSrcweirprint "$script_name -- version: $script_rev\n";
64cdf0e10cSrcweir
65cdf0e10cSrcweir#### main #####
66cdf0e10cSrcweir
67cdf0e10cSrcweirparse_options();
68cdf0e10cSrcweirmy $image_lists_ref = get_image_lists();
69cdf0e10cSrcweirmy %image_lists_hash;
70cdf0e10cSrcweirforeach ( @{$image_lists_ref} ) {
71cdf0e10cSrcweir    $image_lists_hash{$_}="";
72cdf0e10cSrcweir}
73cdf0e10cSrcweir$do_rebuild = is_file_newer(\%image_lists_hash) if $do_rebuild == 0;
74cdf0e10cSrcweirmy ($global_hash_ref, $module_hash_ref, $custom_hash_ref) = iterate_image_lists($image_lists_ref);
75cdf0e10cSrcweir# custom_hash filled from filesystem lookup
76cdf0e10cSrcweirfind_custom($custom_hash_ref);
77cdf0e10cSrcweirmy $zip_hash_ref = create_zip_list($global_hash_ref, $module_hash_ref, $custom_hash_ref);
78cdf0e10cSrcweir$do_rebuild = is_file_newer($zip_hash_ref) if $do_rebuild == 0;
79cdf0e10cSrcweirif ( $do_rebuild == 1 ) {
80cdf0e10cSrcweir    create_zip_archive($zip_hash_ref);
81cdf0e10cSrcweir    replace_file($tmp_out_file, $out_file);
82cdf0e10cSrcweir    print_message("packing  $out_file finished.");
83cdf0e10cSrcweir} else {
84cdf0e10cSrcweir    print_message("$out_file up to date. nothing to do.");
85cdf0e10cSrcweir}
86cdf0e10cSrcweir
87cdf0e10cSrcweirexit(0);
88cdf0e10cSrcweir
89cdf0e10cSrcweir#### subroutines ####
90cdf0e10cSrcweir
91cdf0e10cSrcweirsub parse_options
92cdf0e10cSrcweir{
93cdf0e10cSrcweir    my $opt_help;
94cdf0e10cSrcweir    my $p = Getopt::Long::Parser->new();
95cdf0e10cSrcweir    my @custom_path_list;
96cdf0e10cSrcweir    my $custom_path_extended;
97cdf0e10cSrcweir    my $success =$p->getoptions(
98cdf0e10cSrcweir                             '-h' => \$opt_help,
99cdf0e10cSrcweir                             '-o=s' => \$out_file,
100cdf0e10cSrcweir                             '-g=s' => \$global_path,
1017d4f049eSAriel Constenla-Haile                             '-s=s' => \$sort_file,
102cdf0e10cSrcweir                             '-m=s' => \$module_path,
103cdf0e10cSrcweir                             '-c=s' => \@custom_path_list,
104cdf0e10cSrcweir                             '-e=s' => \$custom_path_extended,
105cdf0e10cSrcweir                             '-l=s' => \@imagelist_path,
106cdf0e10cSrcweir                             '-v'   => \$verbose,
107cdf0e10cSrcweir                             '-vv'  => \$extra_verbose
108cdf0e10cSrcweir                            );
109cdf0e10cSrcweir    push @custom_path_list, $custom_path_extended if ($custom_path_extended);
110cdf0e10cSrcweir    if ( $opt_help || !$success || !$out_file || !$global_path
111cdf0e10cSrcweir        || !$module_path || !@custom_path_list || !@imagelist_path )
112cdf0e10cSrcweir    {
113cdf0e10cSrcweir        usage();
114cdf0e10cSrcweir        exit(1);
115cdf0e10cSrcweir    }
1167d4f049eSAriel Constenla-Haile
1177d4f049eSAriel Constenla-Haile    # if extra-verbose, set also verbose
1187d4f049eSAriel Constenla-Haile    if ($extra_verbose) { $verbose = 1; }
1197d4f049eSAriel Constenla-Haile
120cdf0e10cSrcweir    #define intermediate output file
121cdf0e10cSrcweir    $tmp_out_file="$out_file"."$$".$ENV{INPATH};
122cdf0e10cSrcweir    # Sanity checks.
123cdf0e10cSrcweir
124cdf0e10cSrcweir    # Check if out_file can be written.
125cdf0e10cSrcweir    my $out_dir = dirname($out_file);
126cdf0e10cSrcweir
127cdf0e10cSrcweir    # Check paths.
128cdf0e10cSrcweir    foreach ($out_dir, $global_path, $module_path, @imagelist_path) {
129cdf0e10cSrcweir        print_error("no such directory: '$_'", 2) if ! -d $_;
130cdf0e10cSrcweir        print_error("can't search directory: '$_'", 2) if ! -x $_;
131cdf0e10cSrcweir    }
132cdf0e10cSrcweir    print_error("directory is not writable: '$out_dir'", 2) if ! -w $out_dir;
133cdf0e10cSrcweir
134cdf0e10cSrcweir    # Use just the working paths
135cdf0e10cSrcweir    @custom_path = ();
136cdf0e10cSrcweir    foreach (@custom_path_list) {
137cdf0e10cSrcweir        if ( ! -d $_ ) {
138cdf0e10cSrcweir            print_warning("skipping non-existing directory: '$_'", 2);
139cdf0e10cSrcweir        }
140cdf0e10cSrcweir        elsif ( ! -x $_ ) {
141cdf0e10cSrcweir            print_error("can't search directory: '$_'", 2);
142cdf0e10cSrcweir        }
143cdf0e10cSrcweir        else {
144cdf0e10cSrcweir            push @custom_path, $_;
145cdf0e10cSrcweir        }
146cdf0e10cSrcweir    }
147cdf0e10cSrcweir}
148cdf0e10cSrcweir
149cdf0e10cSrcweirsub get_image_lists
150cdf0e10cSrcweir{
151cdf0e10cSrcweir    my @image_lists;
152cdf0e10cSrcweir    my $glob_imagelist_path;
153cdf0e10cSrcweir
154cdf0e10cSrcweir    foreach ( @imagelist_path ) {
155cdf0e10cSrcweir        $glob_imagelist_path = $_;
156cdf0e10cSrcweir        # cygwin perl
157cdf0e10cSrcweir        chomp( $glob_imagelist_path = qx{cygpath -u "$glob_imagelist_path"} ) if "$^O" eq "cygwin";
158cdf0e10cSrcweir        push @image_lists, glob("$glob_imagelist_path/*.ilst");
159cdf0e10cSrcweir    }
160cdf0e10cSrcweir    if ( !@image_lists ) {
161cdf0e10cSrcweir        print_error("can't find any image lists in '@imagelist_path'", 3);
162cdf0e10cSrcweir    }
163cdf0e10cSrcweir
164cdf0e10cSrcweir    return wantarray ? @image_lists : \@image_lists;
165cdf0e10cSrcweir}
166cdf0e10cSrcweir
167cdf0e10cSrcweirsub iterate_image_lists
168cdf0e10cSrcweir{
169cdf0e10cSrcweir    my $image_lists_ref = shift;
170cdf0e10cSrcweir
171cdf0e10cSrcweir    my %global_hash;
172cdf0e10cSrcweir    my %module_hash;
173cdf0e10cSrcweir    my %custom_hash;
174cdf0e10cSrcweir
175cdf0e10cSrcweir    foreach my $i ( @{$image_lists_ref} ) {
176cdf0e10cSrcweir        parse_image_list($i, \%global_hash, \%module_hash, \%custom_hash);
177cdf0e10cSrcweir    }
178cdf0e10cSrcweir
179cdf0e10cSrcweir    return (\%global_hash, \%module_hash, \%custom_hash);
180cdf0e10cSrcweir}
181cdf0e10cSrcweir
182cdf0e10cSrcweirsub parse_image_list
183cdf0e10cSrcweir{
184cdf0e10cSrcweir    my $image_list      = shift;
185cdf0e10cSrcweir    my $global_hash_ref = shift;
186cdf0e10cSrcweir    my $module_hash_ref = shift;
187cdf0e10cSrcweir    my $custom_hash_ref = shift;
188cdf0e10cSrcweir
189cdf0e10cSrcweir    print_message("parsing '$image_list' ...") if $verbose;
190cdf0e10cSrcweir    my $linecount = 0;
191cdf0e10cSrcweir    open(IMAGE_LIST, "< $image_list") or die "ERROR: can't open $image_list: $!";
192cdf0e10cSrcweir    while ( <IMAGE_LIST> ) {
193cdf0e10cSrcweir        $linecount++;
194cdf0e10cSrcweir        next if /^\s*#/;
195cdf0e10cSrcweir        next if /^\s*$/;
196cdf0e10cSrcweir        # clean up trailing whitespace
197cdf0e10cSrcweir        tr/\r\n//d;
198cdf0e10cSrcweir        s/\s+$//;
199cdf0e10cSrcweir        # clean up backslashes and double slashes
200cdf0e10cSrcweir        tr{\\}{/}s;
201cdf0e10cSrcweir        tr{/}{}s;
202cdf0e10cSrcweir        # hack "res" back into globals
203cdf0e10cSrcweir        if ( /^\Q$img_global\E\/(.*)$/o ) {
204cdf0e10cSrcweir            $global_hash_ref->{"res/".$1}++;
205cdf0e10cSrcweir            next;
206cdf0e10cSrcweir        }
207cdf0e10cSrcweir        if ( /^\Q$img_module\E\/(.*)$/o ) {
208cdf0e10cSrcweir            $module_hash_ref->{$1}++;
209cdf0e10cSrcweir            next;
210cdf0e10cSrcweir        }
211cdf0e10cSrcweir        # parse failed if we reach this point, bail out
212cdf0e10cSrcweir        close(IMAGE_LIST);
213cdf0e10cSrcweir        print_error("can't parse line $linecount from file '$image_list'", 4);
214cdf0e10cSrcweir    }
215cdf0e10cSrcweir    close(IMAGE_LIST);
216cdf0e10cSrcweir
217cdf0e10cSrcweir    return ($global_hash_ref, $module_hash_ref, $custom_hash_ref);
218cdf0e10cSrcweir}
219cdf0e10cSrcweir
220cdf0e10cSrcweirsub find_custom
221cdf0e10cSrcweir{
222cdf0e10cSrcweir    my $custom_hash_ref = shift;
223cdf0e10cSrcweir    my $keep_back;
224cdf0e10cSrcweir    for my $path (@custom_path) {
2257d4f049eSAriel Constenla-Haile        find({ wanted => \&wanted, no_chdir => 0 }, $path);
2267d4f049eSAriel Constenla-Haile        foreach ( @custom_list ) {
2277d4f049eSAriel Constenla-Haile            if ( /^\Q$path\E\/(.*)$/ ) {
2287d4f049eSAriel Constenla-Haile                $keep_back=$1;
2297d4f049eSAriel Constenla-Haile                if (!defined $custom_hash_ref->{$keep_back}) {
2307d4f049eSAriel Constenla-Haile                    $custom_hash_ref->{$keep_back} = $path;
2317d4f049eSAriel Constenla-Haile                }
2327d4f049eSAriel Constenla-Haile            }
2337d4f049eSAriel Constenla-Haile        }
234cdf0e10cSrcweir    }
235cdf0e10cSrcweir}
236cdf0e10cSrcweir
237cdf0e10cSrcweirsub wanted
238cdf0e10cSrcweir{
239cdf0e10cSrcweir    my $file = $_;
2407d4f049eSAriel Constenla-Haile
241cdf0e10cSrcweir    if ( $file =~ /.*\.png$/ && -f $file ) {
242cdf0e10cSrcweir        push @custom_list, $File::Find::name;
243cdf0e10cSrcweir    }
244cdf0e10cSrcweir}
245cdf0e10cSrcweir
246cdf0e10cSrcweirsub create_zip_list
247cdf0e10cSrcweir{
248cdf0e10cSrcweir    my $global_hash_ref = shift;
249cdf0e10cSrcweir    my $module_hash_ref = shift;
250cdf0e10cSrcweir    my $custom_hash_ref = shift;
251cdf0e10cSrcweir
252cdf0e10cSrcweir    my %zip_hash;
253cdf0e10cSrcweir    my @warn_list;
254cdf0e10cSrcweir
255cdf0e10cSrcweir    print_message("assemble image list ...") if $verbose;
256cdf0e10cSrcweir    foreach ( keys %{$global_hash_ref} ) {
257cdf0e10cSrcweir        # check if in 'global' and in 'module' list and add to warn list
258cdf0e10cSrcweir        if ( exists $module_hash_ref->{$_} ) {
259cdf0e10cSrcweir            push(@warn_list, $_);
260cdf0e10cSrcweir            next;
261cdf0e10cSrcweir        }
262cdf0e10cSrcweir        if ( exists $custom_hash_ref->{$_} ) {
263cdf0e10cSrcweir            $zip_hash{$_} = $custom_hash_ref->{$_};
264cdf0e10cSrcweir            next;
265cdf0e10cSrcweir        }
266cdf0e10cSrcweir        # it's neither in 'module' nor 'custom', record it in zip hash
267cdf0e10cSrcweir        $zip_hash{$_} = $global_path;
268cdf0e10cSrcweir    }
269cdf0e10cSrcweir    foreach ( keys %{$module_hash_ref} ) {
270cdf0e10cSrcweir        if ( exists $custom_hash_ref->{$_} ) {
271cdf0e10cSrcweir            $zip_hash{$_} = $custom_hash_ref->{$_};
272cdf0e10cSrcweir            next;
273cdf0e10cSrcweir        }
274cdf0e10cSrcweir        # it's not in 'custom', record it in zip hash
275cdf0e10cSrcweir        $zip_hash{$_} = $module_path;
276cdf0e10cSrcweir    }
277cdf0e10cSrcweir
278cdf0e10cSrcweir    if ( @warn_list ) {
279cdf0e10cSrcweir        foreach ( @warn_list ) {
280cdf0e10cSrcweir            print_warning("$_ is duplicated in 'global' and 'module' list");
281cdf0e10cSrcweir        }
282cdf0e10cSrcweir    }
283cdf0e10cSrcweir
284cdf0e10cSrcweir    return \%zip_hash
285cdf0e10cSrcweir}
286cdf0e10cSrcweir
287cdf0e10cSrcweirsub is_file_newer
288cdf0e10cSrcweir{
289cdf0e10cSrcweir    my $test_hash_ref = shift;
290cdf0e10cSrcweir    my $reference_stamp = 0;
2917d4f049eSAriel Constenla-Haile
292cdf0e10cSrcweir    print_message("checking timestamps ...") if $verbose;
293cdf0e10cSrcweir    if ( -e $out_file ) {
294cdf0e10cSrcweir        $reference_stamp = (stat($out_file))[9];
295cdf0e10cSrcweir        print_message("found $out_file with $reference_stamp ...") if $verbose;
296cdf0e10cSrcweir    }
297cdf0e10cSrcweir    return 1 if $reference_stamp == 0;
2987d4f049eSAriel Constenla-Haile
299cdf0e10cSrcweir    foreach ( sort keys %{$test_hash_ref} ) {
300cdf0e10cSrcweir        my $path = $test_hash_ref->{$_};
301cdf0e10cSrcweir        $path .= "/" if "$path" ne "";
302cdf0e10cSrcweir        $path .= "$_";
303cdf0e10cSrcweir        print_message("checking '$path' ...") if $extra_verbose;
304cdf0e10cSrcweir        my $mtime = (stat($path))[9];
305cdf0e10cSrcweir        return 1 if $reference_stamp < $mtime;
306cdf0e10cSrcweir    }
307cdf0e10cSrcweir    return 0;
308cdf0e10cSrcweir}
309cdf0e10cSrcweir
310cdf0e10cSrcweirsub optimize_zip_layout($)
311cdf0e10cSrcweir{
312cdf0e10cSrcweir    my $zip_hash_ref = shift;
313cdf0e10cSrcweir
314cdf0e10cSrcweir    if (!defined $sort_file) {
3157d4f049eSAriel Constenla-Haile    print_message("no sort file - sorting alphabetically ...") if $verbose;
3167d4f049eSAriel Constenla-Haile    return sort keys %{$zip_hash_ref};
317cdf0e10cSrcweir    }
318cdf0e10cSrcweir    print_message("sorting from $sort_file ...") if $verbose;
319cdf0e10cSrcweir
320cdf0e10cSrcweir    my $orderh;
321cdf0e10cSrcweir    my %included;
322cdf0e10cSrcweir    my @sorted;
323cdf0e10cSrcweir    open ($orderh, $sort_file) || die "Can't open $sort_file: $!";
324cdf0e10cSrcweir    while (<$orderh>) {
3257d4f049eSAriel Constenla-Haile        /^\#.*/ && next; # comments
3267d4f049eSAriel Constenla-Haile        s/[\r\n]*$//;
3277d4f049eSAriel Constenla-Haile        /^\s*$/ && next;
3287d4f049eSAriel Constenla-Haile        my $file = $_;
3297d4f049eSAriel Constenla-Haile        if (!defined $zip_hash_ref->{$file}) {
3307d4f049eSAriel Constenla-Haile            print "unknown file '$file'\n" if ($extra_verbose);
3317d4f049eSAriel Constenla-Haile        } else {
3327d4f049eSAriel Constenla-Haile            push @sorted, $file;
3337d4f049eSAriel Constenla-Haile            $included{$file} = 1;
3347d4f049eSAriel Constenla-Haile        }
335cdf0e10cSrcweir    }
336cdf0e10cSrcweir    close ($orderh);
337cdf0e10cSrcweir
338cdf0e10cSrcweir    for my $img (sort keys %{$zip_hash_ref}) {
3397d4f049eSAriel Constenla-Haile        push @sorted, $img if (!$included{$img});
340cdf0e10cSrcweir    }
341cdf0e10cSrcweir
342cdf0e10cSrcweir    print_message("done sort ...") if $verbose;
343cdf0e10cSrcweir
344cdf0e10cSrcweir    return @sorted;
345cdf0e10cSrcweir}
346cdf0e10cSrcweir
347cdf0e10cSrcweirsub create_zip_archive
348cdf0e10cSrcweir{
349cdf0e10cSrcweir    my $zip_hash_ref = shift;
350cdf0e10cSrcweir
351cdf0e10cSrcweir    print_message("creating image archive ...") if $verbose;
352cdf0e10cSrcweir    my $zip = Archive::Zip->new();
353cdf0e10cSrcweir
354cdf0e10cSrcweir# FIXME: test - $member = addfile ... $member->desiredCompressionMethod( COMPRESSION_STORED );
355cdf0e10cSrcweir# any measurable performance win/loss ?
356cdf0e10cSrcweir    foreach ( optimize_zip_layout($zip_hash_ref) ) {
357cdf0e10cSrcweir        my $path = $zip_hash_ref->{$_} . "/$_";
358cdf0e10cSrcweir        print_message("zipping '$path' ...") if $extra_verbose;
359cdf0e10cSrcweir        my $member = $zip->addFile($path, $_);
360cdf0e10cSrcweir        if ( !$member ) {
361cdf0e10cSrcweir            print_error("can't add file '$path' to image zip archive: $!", 5);
362cdf0e10cSrcweir        }
363cdf0e10cSrcweir    }
364cdf0e10cSrcweir    my $status = $zip->writeToFileNamed($tmp_out_file);
365cdf0e10cSrcweir    if ( $status != AZ_OK ) {
366cdf0e10cSrcweir        print_error("write image zip archive '$tmp_out_file' failed. Reason: $status", 6);
367cdf0e10cSrcweir    }
368cdf0e10cSrcweir    return;
369cdf0e10cSrcweir}
370cdf0e10cSrcweir
371cdf0e10cSrcweirsub replace_file
372cdf0e10cSrcweir{
373cdf0e10cSrcweir    my $source_file = shift;
374cdf0e10cSrcweir    my $dest_file = shift;
375cdf0e10cSrcweir    my $result = 0;
376cdf0e10cSrcweir
377cdf0e10cSrcweir    $result = unlink($dest_file) if -f $dest_file;
378cdf0e10cSrcweir    if ( $result != 1 && -f $dest_file ) {
379cdf0e10cSrcweir        unlink $source_file;
380cdf0e10cSrcweir        print_error("couldn't remove '$dest_file'",1);
381cdf0e10cSrcweir    }  else {
382cdf0e10cSrcweir        if ( !rename($source_file, $dest_file)) {
383cdf0e10cSrcweir            unlink $source_file;
384cdf0e10cSrcweir            print_error("couldn't rename '$source_file'",1);
385cdf0e10cSrcweir        }
386cdf0e10cSrcweir    }
387cdf0e10cSrcweir    return;
388cdf0e10cSrcweir}
389cdf0e10cSrcweir
390cdf0e10cSrcweirsub usage
391cdf0e10cSrcweir{
392cdf0e10cSrcweir    print STDERR "Usage: packimages.pl [-h] -o out_file -g g_path -m m_path -c c_path -l imagelist_path\n";
393cdf0e10cSrcweir    print STDERR "Creates archive of images\n";
394cdf0e10cSrcweir    print STDERR "Options:\n";
395cdf0e10cSrcweir    print STDERR "    -h                 print this help\n";
396cdf0e10cSrcweir    print STDERR "    -o out_file        path to output archive\n";
397cdf0e10cSrcweir    print STDERR "    -g g_path          path to global images directory\n";
398cdf0e10cSrcweir    print STDERR "    -m m_path          path to module images directory\n";
399cdf0e10cSrcweir    print STDERR "    -c c_path          path to custom images directory\n";
400cdf0e10cSrcweir    print STDERR "    -s sort_file       path to image sort order file\n";
401*81afc36fSJohn Bampton    print STDERR "    -l imagelist_path  path to directory containing image lists (may appear multiple times)\n";
402cdf0e10cSrcweir    print STDERR "    -v                 verbose\n";
403cdf0e10cSrcweir    print STDERR "    -vv                very verbose\n";
404cdf0e10cSrcweir}
405cdf0e10cSrcweir
406cdf0e10cSrcweirsub print_message
407cdf0e10cSrcweir{
408cdf0e10cSrcweir    my $message     = shift;
409cdf0e10cSrcweir
410cdf0e10cSrcweir    print "$script_name: ";
411cdf0e10cSrcweir    print "$message\n";
412cdf0e10cSrcweir    return;
413cdf0e10cSrcweir}
414cdf0e10cSrcweir
415cdf0e10cSrcweirsub print_warning
416cdf0e10cSrcweir{
417cdf0e10cSrcweir    my $message     = shift;
418cdf0e10cSrcweir
419cdf0e10cSrcweir    print STDERR "$script_name: ";
420cdf0e10cSrcweir    print STDERR "WARNING $message\n";
421cdf0e10cSrcweir    return;
422cdf0e10cSrcweir}
423cdf0e10cSrcweir
424cdf0e10cSrcweirsub print_error
425cdf0e10cSrcweir{
426cdf0e10cSrcweir    my $message     = shift;
427cdf0e10cSrcweir    my $error_code  = shift;
428cdf0e10cSrcweir
429cdf0e10cSrcweir    print STDERR "$script_name: ";
430cdf0e10cSrcweir    print STDERR "ERROR: $message\n";
431cdf0e10cSrcweir
432cdf0e10cSrcweir    if ( $error_code ) {
433cdf0e10cSrcweir        print STDERR "\nFAILURE: $script_name aborted.\n";
434cdf0e10cSrcweir        exit($error_code);
435cdf0e10cSrcweir    }
436cdf0e10cSrcweir    return;
437cdf0e10cSrcweir}
438