#! /usr/bin/env perl

# $Id: detFetchFromDS 145 2007-03-07 02:02:44Z yamada $

print "*********************************\n";
print "* This is detFindFetchAndInsert *\n";
print "*********************************\n";

#use lib '/home/yamada/prj/panstarrs/mops/src';

use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;

use PS::MOPS::DET::find;

my $help;

my $instance_name = $ENV{'MOPS_DBINSTANCE'};
my $datastore = $ENV{'MOPS_DATASTORE'};
my $mops_home = $ENV{'MOPS_HOME'};
my $var = $ENV{'MOPS_VAR'};

GetOptions(
	'instance=s' => \$instance_name,
	'datastore=s' => \$datastore,
	'mops_home=s' => \$mops_home,
	'var=s' => \$var,
    help => \$help,
) or pod2usage(2);                      # opts parse error
pod2usage(-verbose => 3) if $help;      # user asked for help

pod2usage(2) unless $#ARGV == -1;
die("Must specify instance name or MOPS_DBINSTANCE") unless $instance_name;
die("Must specify data store or MOPS_DATASTORE") unless $datastore;
die("Must specify mops home or MOPS_HOME") unless $mops_home;
$var = $mops_home . "/var/" . $instance_name unless $var;

PS::MOPS::DET::find::find_fetch_and_update($datastore, $instance_name, $var);

__END__

=head1 NAME

detFindFetchAndInstall - Search the data store for new files, insert.

=head1 SYNOPSIS

detFindFetchAndInstall [OPTIONS]

=head1 OPTIONS

=over 4

=item --instance=INSTANCE

Instance name.  Either the --instance option or the MOPS_DBINSTANCE 
environment variable must be used.  If both are used, the command line
option has priority.

=item --datastore=HOSTNAME[:PORT]

Data store server name.  If the server is listening on a non-standard
port, the port may be specified also.  Either the --datastore option
or the MOPS_DATASTORE environment variable must be used.  If both
are used, the command line option has priority.

=item --mops_home=MOPSHOME

Root of the MOPS hierarchy.  Either the --mops_home option or the
MOPS_HOME environment variable must be used.  If both are used, the
command line option has priority.

=item --mops_var=MOPSVAR

Where are temporary files created.  The directory must already
exist.  If this variable is not set, then the MOPS_VAR environment
variable is use.  If neither is set, then MOPSHOME/var/INSTANCE is
used.

=back

=head1 DESCRIPTION

Check the datastore for new files, retrieve any new files, then
insert them into the simulation database.

=head1 ENVIRONMENT VARIABLES

=over 4

=item MOPS_DBINSTANCE

Simulation instance.

=item MOPS_DATASTORE

Hostname or hostname:port used to specify the data store.

=item MOPS_HOME

Root of the MOPS directory hierachy.

=back

=head1 TO DO

=head1 BUGS

=cut
