#!/usr/bin/perl -w use strict; use Getopt::Std; getopts('ahvd:o:'); our($opt_a, $opt_d, $opt_o, $opt_v, $opt_h); my $config_file = "config/xhconf.xml"; &usage if ($opt_h); my $verbose = $opt_v; my $add_to_conf = $opt_a; my $input_dir = $opt_d || shift; &usage unless ($input_dir); $input_dir =~ s/\/$//; my $output_file = $opt_o; unless ($output_file) { (my $tmp = $input_dir) =~ s/^.*\/([^\/]+)$/$1/; $output_file = "config/$tmp.xml"; } die("Directory $input_dir doesn't exist!") unless (-d $input_dir); # Create XML document header verb("Starting document..."); my $date = localtime(); my $content = < $input_dir $date HEAD # Walk through directory and grab images my $do_teaser = 1; verb("Reading directory $input_dir"); opendir(DIR, $input_dir) || die "can't open $input_dir: $!"; for my $file (sort readdir DIR) { if ($file =~ /\.(gif|jpg|jpeg)$/i) { verb(" processing $file"); if ($do_teaser) { $content .= "$input_dir/$file\n"; $do_teaser = 0; } my $date = localtime((stat("$input_dir/$file"))[9]); my $imgXML = qq( \n); $imgXML .= qq( $date\n); $imgXML .= qq( $file\n); $imgXML .= qq( \n); $imgXML .= qq( \n); $content .= $imgXML; } else { verb(" ...skipping $file"); } } closedir(DIR); # Add footer and print verb("Writing file..."); $content .= "\n"; if ($output_file) { open(OUT,">$output_file") || die "can't open $output_file for writing: $!"; print OUT $content; close(OUT); } else { print $content; } # Update config file verb("Adding $output_file to config file..."); if ($add_to_conf) { my $conf_content; open(CONF,$config_file) || die "can't open $config_file: $!"; { local $/ = undef; $conf_content = ; } close(CONF); (my $filename = $output_file) =~ s/^.*\/([^\/]+)$/$1/; $conf_content =~ s||\n\t$filename\n|s; if ($conf_content) { open(CONF,">$config_file") || die "can't open $config_file: $!"; print CONF $conf_content; close(CONF); } else { warn "something terribly wrong happened. no conf_content!"; } } verb("done."); ##### sub verb { return unless $verbose; my $string = shift; warn "$string\n"; } sub usage { print <