1*cdf0e10cSrcweir: 2*cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}' 3*cdf0e10cSrcweir if 0; 4*cdf0e10cSrcweir#************************************************************************* 5*cdf0e10cSrcweir# 6*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7*cdf0e10cSrcweir# 8*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 9*cdf0e10cSrcweir# 10*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 11*cdf0e10cSrcweir# 12*cdf0e10cSrcweir# This file is part of OpenOffice.org. 13*cdf0e10cSrcweir# 14*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 15*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 16*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 17*cdf0e10cSrcweir# 18*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 19*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 20*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 22*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 23*cdf0e10cSrcweir# 24*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 25*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 26*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 27*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 28*cdf0e10cSrcweir# 29*cdf0e10cSrcweir#************************************************************************* 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir# 32*cdf0e10cSrcweir# packimages.pl - pack images into archives 33*cdf0e10cSrcweir# 34*cdf0e10cSrcweir 35*cdf0e10cSrcweiruse strict; 36*cdf0e10cSrcweiruse Getopt::Long; 37*cdf0e10cSrcweiruse File::Find; 38*cdf0e10cSrcweiruse File::Basename; 39*cdf0e10cSrcweiruse Archive::Zip qw(:ERROR_CODES :CONSTANTS); 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir#### globals #### 42*cdf0e10cSrcweir 43*cdf0e10cSrcweirmy $img_global = '%GLOBALRES%'; # 'global' image prefix 44*cdf0e10cSrcweirmy $img_module = '%MODULE%'; # 'module' image prefix 45*cdf0e10cSrcweir 46*cdf0e10cSrcweirmy $out_file; # path to output archive 47*cdf0e10cSrcweirmy $tmp_out_file; # path to temporary output file 48*cdf0e10cSrcweirmy $global_path; # path to global images directory 49*cdf0e10cSrcweirmy $module_path; # path to module images directory 50*cdf0e10cSrcweirmy $sort_file; # path to file containing sorting data 51*cdf0e10cSrcweirmy @custom_path; # path to custom images directory 52*cdf0e10cSrcweirmy @imagelist_path; # pathes to directories containing the image lists 53*cdf0e10cSrcweirmy $verbose; # be verbose 54*cdf0e10cSrcweirmy $extra_verbose; # be extra verbose 55*cdf0e10cSrcweirmy $do_rebuild = 0; # is rebuilding zipfile required? 56*cdf0e10cSrcweir 57*cdf0e10cSrcweirmy @custom_list; 58*cdf0e10cSrcweir#### script id ##### 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir( my $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweirmy $script_rev; 63*cdf0e10cSrcweirmy $id_str = ' $Revision: 1.17 $ '; 64*cdf0e10cSrcweir$id_str =~ /Revision:\s+(\S+)\s+\$/ 65*cdf0e10cSrcweir ? ($script_rev = $1) : ($script_rev = "-"); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweirprint "$script_name -- version: $script_rev\n"; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir#### main ##### 70*cdf0e10cSrcweir 71*cdf0e10cSrcweirparse_options(); 72*cdf0e10cSrcweirmy $image_lists_ref = get_image_lists(); 73*cdf0e10cSrcweirmy %image_lists_hash; 74*cdf0e10cSrcweirforeach ( @{$image_lists_ref} ) { 75*cdf0e10cSrcweir $image_lists_hash{$_}=""; 76*cdf0e10cSrcweir} 77*cdf0e10cSrcweir$do_rebuild = is_file_newer(\%image_lists_hash) if $do_rebuild == 0; 78*cdf0e10cSrcweirmy ($global_hash_ref, $module_hash_ref, $custom_hash_ref) = iterate_image_lists($image_lists_ref); 79*cdf0e10cSrcweir# custom_hash filled from filesystem lookup 80*cdf0e10cSrcweirfind_custom($custom_hash_ref); 81*cdf0e10cSrcweirmy $zip_hash_ref = create_zip_list($global_hash_ref, $module_hash_ref, $custom_hash_ref); 82*cdf0e10cSrcweir$do_rebuild = is_file_newer($zip_hash_ref) if $do_rebuild == 0; 83*cdf0e10cSrcweirif ( $do_rebuild == 1 ) { 84*cdf0e10cSrcweir create_zip_archive($zip_hash_ref); 85*cdf0e10cSrcweir replace_file($tmp_out_file, $out_file); 86*cdf0e10cSrcweir print_message("packing $out_file finished."); 87*cdf0e10cSrcweir} else { 88*cdf0e10cSrcweir print_message("$out_file up to date. nothing to do."); 89*cdf0e10cSrcweir} 90*cdf0e10cSrcweir 91*cdf0e10cSrcweirexit(0); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir#### subroutines #### 94*cdf0e10cSrcweir 95*cdf0e10cSrcweirsub parse_options 96*cdf0e10cSrcweir{ 97*cdf0e10cSrcweir my $opt_help; 98*cdf0e10cSrcweir my $p = Getopt::Long::Parser->new(); 99*cdf0e10cSrcweir my @custom_path_list; 100*cdf0e10cSrcweir my $custom_path_extended; 101*cdf0e10cSrcweir my $success =$p->getoptions( 102*cdf0e10cSrcweir '-h' => \$opt_help, 103*cdf0e10cSrcweir '-o=s' => \$out_file, 104*cdf0e10cSrcweir '-g=s' => \$global_path, 105*cdf0e10cSrcweir '-s=s' => \$sort_file, 106*cdf0e10cSrcweir '-m=s' => \$module_path, 107*cdf0e10cSrcweir '-c=s' => \@custom_path_list, 108*cdf0e10cSrcweir '-e=s' => \$custom_path_extended, 109*cdf0e10cSrcweir '-l=s' => \@imagelist_path, 110*cdf0e10cSrcweir '-v' => \$verbose, 111*cdf0e10cSrcweir '-vv' => \$extra_verbose 112*cdf0e10cSrcweir ); 113*cdf0e10cSrcweir push @custom_path_list, $custom_path_extended if ($custom_path_extended); 114*cdf0e10cSrcweir if ( $opt_help || !$success || !$out_file || !$global_path 115*cdf0e10cSrcweir || !$module_path || !@custom_path_list || !@imagelist_path ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir usage(); 118*cdf0e10cSrcweir exit(1); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir #define intermediate output file 121*cdf0e10cSrcweir $tmp_out_file="$out_file"."$$".$ENV{INPATH}; 122*cdf0e10cSrcweir # Sanity checks. 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir # Check if out_file can be written. 125*cdf0e10cSrcweir my $out_dir = dirname($out_file); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir # Check paths. 128*cdf0e10cSrcweir foreach ($out_dir, $global_path, $module_path, @imagelist_path) { 129*cdf0e10cSrcweir print_error("no such directory: '$_'", 2) if ! -d $_; 130*cdf0e10cSrcweir print_error("can't search directory: '$_'", 2) if ! -x $_; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir print_error("directory is not writable: '$out_dir'", 2) if ! -w $out_dir; 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir # Use just the working paths 135*cdf0e10cSrcweir @custom_path = (); 136*cdf0e10cSrcweir foreach (@custom_path_list) { 137*cdf0e10cSrcweir if ( ! -d $_ ) { 138*cdf0e10cSrcweir print_warning("skipping non-existing directory: '$_'", 2); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir elsif ( ! -x $_ ) { 141*cdf0e10cSrcweir print_error("can't search directory: '$_'", 2); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir else { 144*cdf0e10cSrcweir push @custom_path, $_; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir} 148*cdf0e10cSrcweir 149*cdf0e10cSrcweirsub get_image_lists 150*cdf0e10cSrcweir{ 151*cdf0e10cSrcweir my @image_lists; 152*cdf0e10cSrcweir my $glob_imagelist_path; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir foreach ( @imagelist_path ) { 155*cdf0e10cSrcweir $glob_imagelist_path = $_; 156*cdf0e10cSrcweir # cygwin perl 157*cdf0e10cSrcweir chomp( $glob_imagelist_path = qx{cygpath -u "$glob_imagelist_path"} ) if "$^O" eq "cygwin"; 158*cdf0e10cSrcweir push @image_lists, glob("$glob_imagelist_path/*.ilst"); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir if ( !@image_lists ) { 161*cdf0e10cSrcweir print_error("can't find any image lists in '@imagelist_path'", 3); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir return wantarray ? @image_lists : \@image_lists; 165*cdf0e10cSrcweir} 166*cdf0e10cSrcweir 167*cdf0e10cSrcweirsub iterate_image_lists 168*cdf0e10cSrcweir{ 169*cdf0e10cSrcweir my $image_lists_ref = shift; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir my %global_hash; 172*cdf0e10cSrcweir my %module_hash; 173*cdf0e10cSrcweir my %custom_hash; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir foreach my $i ( @{$image_lists_ref} ) { 176*cdf0e10cSrcweir parse_image_list($i, \%global_hash, \%module_hash, \%custom_hash); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir return (\%global_hash, \%module_hash, \%custom_hash); 180*cdf0e10cSrcweir} 181*cdf0e10cSrcweir 182*cdf0e10cSrcweirsub parse_image_list 183*cdf0e10cSrcweir{ 184*cdf0e10cSrcweir my $image_list = shift; 185*cdf0e10cSrcweir my $global_hash_ref = shift; 186*cdf0e10cSrcweir my $module_hash_ref = shift; 187*cdf0e10cSrcweir my $custom_hash_ref = shift; 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir print_message("parsing '$image_list' ...") if $verbose; 190*cdf0e10cSrcweir my $linecount = 0; 191*cdf0e10cSrcweir open(IMAGE_LIST, "< $image_list") or die "ERROR: can't open $image_list: $!"; 192*cdf0e10cSrcweir while ( <IMAGE_LIST> ) { 193*cdf0e10cSrcweir $linecount++; 194*cdf0e10cSrcweir next if /^\s*#/; 195*cdf0e10cSrcweir next if /^\s*$/; 196*cdf0e10cSrcweir # clean up trailing whitespace 197*cdf0e10cSrcweir tr/\r\n//d; 198*cdf0e10cSrcweir s/\s+$//; 199*cdf0e10cSrcweir # clean up backslashes and double slashes 200*cdf0e10cSrcweir tr{\\}{/}s; 201*cdf0e10cSrcweir tr{/}{}s; 202*cdf0e10cSrcweir # hack "res" back into globals 203*cdf0e10cSrcweir if ( /^\Q$img_global\E\/(.*)$/o ) { 204*cdf0e10cSrcweir $global_hash_ref->{"res/".$1}++; 205*cdf0e10cSrcweir next; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir if ( /^\Q$img_module\E\/(.*)$/o ) { 208*cdf0e10cSrcweir $module_hash_ref->{$1}++; 209*cdf0e10cSrcweir next; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir # parse failed if we reach this point, bail out 212*cdf0e10cSrcweir close(IMAGE_LIST); 213*cdf0e10cSrcweir print_error("can't parse line $linecount from file '$image_list'", 4); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir close(IMAGE_LIST); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir return ($global_hash_ref, $module_hash_ref, $custom_hash_ref); 218*cdf0e10cSrcweir} 219*cdf0e10cSrcweir 220*cdf0e10cSrcweirsub find_custom 221*cdf0e10cSrcweir{ 222*cdf0e10cSrcweir my $custom_hash_ref = shift; 223*cdf0e10cSrcweir my $keep_back; 224*cdf0e10cSrcweir for my $path (@custom_path) { 225*cdf0e10cSrcweir find({ wanted => \&wanted, no_chdir => 0 }, $path); 226*cdf0e10cSrcweir foreach ( @custom_list ) { 227*cdf0e10cSrcweir if ( /^\Q$path\E\/(.*)$/ ) { 228*cdf0e10cSrcweir $keep_back=$1; 229*cdf0e10cSrcweir if (!defined $custom_hash_ref->{$keep_back}) { 230*cdf0e10cSrcweir $custom_hash_ref->{$keep_back} = $path; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir} 236*cdf0e10cSrcweir 237*cdf0e10cSrcweirsub wanted 238*cdf0e10cSrcweir{ 239*cdf0e10cSrcweir my $file = $_; 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir if ( $file =~ /.*\.png$/ && -f $file ) { 242*cdf0e10cSrcweir push @custom_list, $File::Find::name; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir} 245*cdf0e10cSrcweir 246*cdf0e10cSrcweirsub create_zip_list 247*cdf0e10cSrcweir{ 248*cdf0e10cSrcweir my $global_hash_ref = shift; 249*cdf0e10cSrcweir my $module_hash_ref = shift; 250*cdf0e10cSrcweir my $custom_hash_ref = shift; 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir my %zip_hash; 253*cdf0e10cSrcweir my @warn_list; 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir print_message("assemble image list ...") if $verbose; 256*cdf0e10cSrcweir foreach ( keys %{$global_hash_ref} ) { 257*cdf0e10cSrcweir # check if in 'global' and in 'module' list and add to warn list 258*cdf0e10cSrcweir if ( exists $module_hash_ref->{$_} ) { 259*cdf0e10cSrcweir push(@warn_list, $_); 260*cdf0e10cSrcweir next; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir if ( exists $custom_hash_ref->{$_} ) { 263*cdf0e10cSrcweir $zip_hash{$_} = $custom_hash_ref->{$_}; 264*cdf0e10cSrcweir next; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir # it's neither in 'module' nor 'custom', record it in zip hash 267*cdf0e10cSrcweir $zip_hash{$_} = $global_path; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir foreach ( keys %{$module_hash_ref} ) { 270*cdf0e10cSrcweir if ( exists $custom_hash_ref->{$_} ) { 271*cdf0e10cSrcweir $zip_hash{$_} = $custom_hash_ref->{$_}; 272*cdf0e10cSrcweir next; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir # it's not in 'custom', record it in zip hash 275*cdf0e10cSrcweir $zip_hash{$_} = $module_path; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir if ( @warn_list ) { 279*cdf0e10cSrcweir foreach ( @warn_list ) { 280*cdf0e10cSrcweir print_warning("$_ is duplicated in 'global' and 'module' list"); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir return \%zip_hash 285*cdf0e10cSrcweir} 286*cdf0e10cSrcweir 287*cdf0e10cSrcweirsub is_file_newer 288*cdf0e10cSrcweir{ 289*cdf0e10cSrcweir my $test_hash_ref = shift; 290*cdf0e10cSrcweir my $reference_stamp = 0; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir print_message("checking timestamps ...") if $verbose; 293*cdf0e10cSrcweir if ( -e $out_file ) { 294*cdf0e10cSrcweir $reference_stamp = (stat($out_file))[9]; 295*cdf0e10cSrcweir print_message("found $out_file with $reference_stamp ...") if $verbose; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir return 1 if $reference_stamp == 0; 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir foreach ( sort keys %{$test_hash_ref} ) { 300*cdf0e10cSrcweir my $path = $test_hash_ref->{$_}; 301*cdf0e10cSrcweir $path .= "/" if "$path" ne ""; 302*cdf0e10cSrcweir $path .= "$_"; 303*cdf0e10cSrcweir print_message("checking '$path' ...") if $extra_verbose; 304*cdf0e10cSrcweir my $mtime = (stat($path))[9]; 305*cdf0e10cSrcweir return 1 if $reference_stamp < $mtime; 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir return 0; 308*cdf0e10cSrcweir} 309*cdf0e10cSrcweir 310*cdf0e10cSrcweirsub optimize_zip_layout($) 311*cdf0e10cSrcweir{ 312*cdf0e10cSrcweir my $zip_hash_ref = shift; 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir if (!defined $sort_file) { 315*cdf0e10cSrcweir print_message("no sort file - sorting alphabetically ...") if $verbose; 316*cdf0e10cSrcweir return sort keys %{$zip_hash_ref}; 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir print_message("sorting from $sort_file ...") if $verbose; 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir my $orderh; 321*cdf0e10cSrcweir my %included; 322*cdf0e10cSrcweir my @sorted; 323*cdf0e10cSrcweir open ($orderh, $sort_file) || die "Can't open $sort_file: $!"; 324*cdf0e10cSrcweir while (<$orderh>) { 325*cdf0e10cSrcweir /^\#.*/ && next; # comments 326*cdf0e10cSrcweir s/[\r\n]*$//; 327*cdf0e10cSrcweir /^\s*$/ && next; 328*cdf0e10cSrcweir my $file = $_; 329*cdf0e10cSrcweir if (!defined $zip_hash_ref->{$file}) { 330*cdf0e10cSrcweir print "unknown file '$file'\n" if ($extra_verbose); 331*cdf0e10cSrcweir } else { 332*cdf0e10cSrcweir push @sorted, $file; 333*cdf0e10cSrcweir $included{$file} = 1; 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir close ($orderh); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir for my $img (sort keys %{$zip_hash_ref}) { 339*cdf0e10cSrcweir push @sorted, $img if (!$included{$img}); 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir print_message("done sort ...") if $verbose; 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir return @sorted; 345*cdf0e10cSrcweir} 346*cdf0e10cSrcweir 347*cdf0e10cSrcweirsub create_zip_archive 348*cdf0e10cSrcweir{ 349*cdf0e10cSrcweir my $zip_hash_ref = shift; 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir print_message("creating image archive ...") if $verbose; 352*cdf0e10cSrcweir my $zip = Archive::Zip->new(); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir# FIXME: test - $member = addfile ... $member->desiredCompressionMethod( COMPRESSION_STORED ); 355*cdf0e10cSrcweir# any measurable performance win/loss ? 356*cdf0e10cSrcweir foreach ( optimize_zip_layout($zip_hash_ref) ) { 357*cdf0e10cSrcweir my $path = $zip_hash_ref->{$_} . "/$_"; 358*cdf0e10cSrcweir print_message("zipping '$path' ...") if $extra_verbose; 359*cdf0e10cSrcweir my $member = $zip->addFile($path, $_); 360*cdf0e10cSrcweir if ( !$member ) { 361*cdf0e10cSrcweir print_error("can't add file '$path' to image zip archive: $!", 5); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir my $status = $zip->writeToFileNamed($tmp_out_file); 365*cdf0e10cSrcweir if ( $status != AZ_OK ) { 366*cdf0e10cSrcweir print_error("write image zip archive '$tmp_out_file' failed. Reason: $status", 6); 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir return; 369*cdf0e10cSrcweir} 370*cdf0e10cSrcweir 371*cdf0e10cSrcweirsub replace_file 372*cdf0e10cSrcweir{ 373*cdf0e10cSrcweir my $source_file = shift; 374*cdf0e10cSrcweir my $dest_file = shift; 375*cdf0e10cSrcweir my $result = 0; 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir $result = unlink($dest_file) if -f $dest_file; 378*cdf0e10cSrcweir if ( $result != 1 && -f $dest_file ) { 379*cdf0e10cSrcweir unlink $source_file; 380*cdf0e10cSrcweir print_error("couldn't remove '$dest_file'",1); 381*cdf0e10cSrcweir } else { 382*cdf0e10cSrcweir if ( !rename($source_file, $dest_file)) { 383*cdf0e10cSrcweir unlink $source_file; 384*cdf0e10cSrcweir print_error("couldn't rename '$source_file'",1); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir return; 388*cdf0e10cSrcweir} 389*cdf0e10cSrcweir 390*cdf0e10cSrcweirsub usage 391*cdf0e10cSrcweir{ 392*cdf0e10cSrcweir print STDERR "Usage: packimages.pl [-h] -o out_file -g g_path -m m_path -c c_path -l imagelist_path\n"; 393*cdf0e10cSrcweir print STDERR "Creates archive of images\n"; 394*cdf0e10cSrcweir print STDERR "Options:\n"; 395*cdf0e10cSrcweir print STDERR " -h print this help\n"; 396*cdf0e10cSrcweir print STDERR " -o out_file path to output archive\n"; 397*cdf0e10cSrcweir print STDERR " -g g_path path to global images directory\n"; 398*cdf0e10cSrcweir print STDERR " -m m_path path to module images directory\n"; 399*cdf0e10cSrcweir print STDERR " -c c_path path to custom images directory\n"; 400*cdf0e10cSrcweir print STDERR " -s sort_file path to image sort order file\n"; 401*cdf0e10cSrcweir print STDERR " -l imagelist_path path to directory containing image lists (may appear mutiple times)\n"; 402*cdf0e10cSrcweir print STDERR " -v verbose\n"; 403*cdf0e10cSrcweir print STDERR " -vv very verbose\n"; 404*cdf0e10cSrcweir} 405*cdf0e10cSrcweir 406*cdf0e10cSrcweirsub print_message 407*cdf0e10cSrcweir{ 408*cdf0e10cSrcweir my $message = shift; 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir print "$script_name: "; 411*cdf0e10cSrcweir print "$message\n"; 412*cdf0e10cSrcweir return; 413*cdf0e10cSrcweir} 414*cdf0e10cSrcweir 415*cdf0e10cSrcweirsub print_warning 416*cdf0e10cSrcweir{ 417*cdf0e10cSrcweir my $message = shift; 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir print STDERR "$script_name: "; 420*cdf0e10cSrcweir print STDERR "WARNING $message\n"; 421*cdf0e10cSrcweir return; 422*cdf0e10cSrcweir} 423*cdf0e10cSrcweir 424*cdf0e10cSrcweirsub print_error 425*cdf0e10cSrcweir{ 426*cdf0e10cSrcweir my $message = shift; 427*cdf0e10cSrcweir my $error_code = shift; 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir print STDERR "$script_name: "; 430*cdf0e10cSrcweir print STDERR "ERROR: $message\n"; 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir if ( $error_code ) { 433*cdf0e10cSrcweir print STDERR "\nFAILURE: $script_name aborted.\n"; 434*cdf0e10cSrcweir exit($error_code); 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir return; 437*cdf0e10cSrcweir} 438