#!/usr/bin/perl

use strict;
use SimpleResource;
use Eidetic::Database;
use Eidetic::Racks;
use Getopt::Long qw(:config no_ignore_case bundling);
use Pod::Usage;


#------------------------------------------------------------------------
# Global variables
#------------------------------------------------------------------------

use vars qw($VERSION $NAME);
$VERSION="0.01";
$NAME   ="rackview";

our $LICENSE="
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
";

my %CONFIG = ();
my $CONFDIR="/etc/eidetic";

#------------------------------------------------------------------------
# Config file loading
#------------------------------------------------------------------------
SimpleResource::load_resource(\%CONFIG, $CONFDIR,   "conf");
die "No config file $NAME.conf found\n" unless (exists $CONFIG{$NAME});
my $appconf = $CONFIG{$NAME};


#------------------------------------------------------------------------
# User config area
#------------------------------------------------------------------------

our $opt_version     = 0; # Prints the version and exits
our $opt_help        = 0; # Prints a brief help message
our $opt_man         = 0; # Prints a manual page (detailed help).
our $opt_debug       = 0; # Prints debug messages



#------------------------------------------------------------------------
# Commandline option processing
#------------------------------------------------------------------------

my $long_help = <<HELP;
    Erackview generates a view of a set of cabinets and the machines
    in them, pulling the data in from an Eidetic-managed database.
HELP

    my $usage_string = <<USAGE;
 usage: $NAME [options]
           $NAME [options] [files | directories]
           $NAME -help to view list of options
USAGE

Getopt::Long::Configure ("bundling" );
GetOptions(
           "version|V",     # Prints the version and exits
           "help|h",        # Prints a brief help message
           "man|m",         # Prints a manual page (detailed help)
           "debug|D=i",     # Prints debug messages
           );

if ($opt_version) {
    print "$VERSION\n";
    exit 0;
}


pod2usage(-verbose => 2, -exitstatus => 0) if ($opt_man || $opt_help);

#========================================================================
# Subroutines
#------------------------------------------------------------------------


#========================================================================
# Main program
#------------------------------------------------------------------------

warn "=== Starting main program ===\n" if $opt_debug>1;

my @racks = @ARGV;
die "Usage:  $0 [rack id's]\n" unless scalar(@racks)>0;

my $db = Eidetic::Database->new(
				brand => $appconf->{db_brand},
				name   => $appconf->{db_name},
				host   => $appconf->{db_host},
				user   => $appconf->{db_user},
				pass   => $appconf->{db_pass}
				);

my $racks = new Eidetic::Racks(database => $db, rack_ids => \@racks);

print $racks->toHtml();

warn "=== Ending main program ===\n\n" if ($opt_debug>1);

#========================================================================
__END__

=head1 NAME

rackview - Create an HTML view of a set of racks

=head1 SYNOPSIS

rackview [RACK IDs]

=head1 OPTIONS

None

=head1 DESCRIPTION

B<rackview> is a commandline wrapper to the Eidetic::Racks perl module
that enables generation of HTML and images for viewing a set of computer
racks.  It's intended to be used with the Eidetic Lab Hardware
Management System for showing the layout of a computer lab.

=head1 PREREQUISITES

This script requires the C<GD> module.  It requires Eidetic::DBObject.
It also requires File::Spec, which typically come with the perl
distribution.

=head1 COREQUISITES

None

=head1 SCRIPT CATEGORIES

CPAN/Administrative

=head1 BUGS

None known.

=head1 SEE ALSO

L<Eidetic::Racks(3)>

=head1 AUTHOR

Bryce Harrington E<lt>brycehar@bryceharrington.comE<gt>.

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2003 by Bryce Harrington

This program is free software; you may redistribute it and/or modify
it under the same terms ans Perl itself.

=head1 REVISION

Revision: $Revision: 1.2 $

=cut

