#! /usr/bin/env perl

# $Id: submit.pl 109 2007-03-05 20:59:54Z yamada $

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

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

use PS::MOPS::DET::Constants;
use PS::MOPS::DET::htclient;

my $help;
my $datastore = $ENV{'MOPS_DATASTORE'};
my $instance_name = $ENV{'MOPS_DBINSTANCE'};
my $status = $MOPS_DET_STATUS_PENDING;

GetOptions(
	'datastore=s' => \$datastore,
	'instance=s' => \$instance_name,
	'status=s' => \$status,
    help => \$help,
) or pod2usage(2);                      # opts parse error
pod2usage(-verbose => 3) if $help;      # user asked for help
die("Must specify instance name or MOPS_DBINSTANCE") unless $instance_name;
die("Must specify data store or MOPS_DATASTORE") unless $datastore;

if ( $#ARGV < 0 ) {
	pod2usage(2);
	exit(1);
}

my $server_url = "http://$datastore/";

for my $filename (@ARGV) {
	PS::MOPS::DET::htclient::status_set($server_url, $instance_name, $filename,
		$status);
}

__END__

=head1 NAME

detDSStatusSet - Update the status field on the data store

=head1 SYNOPSIS

detDSStatusSet [OPTIONS] DBFILE [DBFILE [...]]

=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 --status=STATUS

New data store status (any single upper-case character, normally N
[new] or P [processing]).  If this option is not specified explicitly, the
status will be set to 'P'.

=back

=head1 ARGUMENTS

=over 4

=item DBFILE

Data store file name.

=back

=head1 DESCRIPTION

Submits a request to the data store to change the status field of the index
entry for a detections file.

Status field:
	N - New - Just submitted
	P - Processing - Retrieved and entered into database

=head1 ENVIRONMENT VARIABLES

=over 4

=item MOPS_DBINSTANCE

Simulation instance.

=item MOPS_DATASTORE

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

=back

=head1 TO DO

=head1 BUGS

=over 4

=item *

If a non-existent file is specified, no error will be reported.

=back

=cut
