Index: trunk/ippToPsps/perl/ippToPsps_run.pl
===================================================================
--- trunk/ippToPsps/perl/ippToPsps_run.pl	(revision 28887)
+++ trunk/ippToPsps/perl/ippToPsps_run.pl	(revision 28888)
@@ -14,4 +14,5 @@
 use ippToPsps::Gpc1Db;
 use ippToPsps::IppToPspsDb;
+use ippToPsps::Datastore;
 
 # globals
@@ -103,8 +104,9 @@
 my $gpc1Db = new ippToPsps::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser", $verbose, $save_temps);
 my $ippToPspsDb = new ippToPsps::IppToPspsDb("ippToPsps", "ippdb01", "ipp", "ipp", $verbose, $save_temps);
+my $datastore = undef;
+if ($datastoreProduct) {$datastore = new ippToPsps::Datastore($datastoreProduct, $verbose, $save_temps);}
 
 # check we can run programs and get camera config
 my $ippToPsps = can_run('ippToPsps') or (warn "Can't find 'ippToPsps' program" and exit($PS_EXIT_CONFIG_ERROR));
-my $dsreg = can_run('dsreg') or (warn "Can't find 'dsreg' program" and exit($PS_EXIT_CONFIG_ERROR));
 my $ipprc = PS::IPP::Config->new($camera) or (warn "Can't get camera configuration" and exit($PS_EXIT_CONFIG_ERROR)); 
 
@@ -179,5 +181,5 @@
         if (!$surveyType) {next;}
 
-        $batchId = $ippToPspsDb->createNewBatch($expId, $distGroup, $pspsBatchType, $dvoDb, (defined $datastoreProduct) ? $datastoreProduct : "NONE");
+        $batchId = $ippToPspsDb->createNewBatch($expId, $distGroup, $pspsBatchType, $dvoDb, (defined $datastore) ? $datastoreProduct : "NONE");
 
         # TODO quit here if no sensible batch ID
@@ -202,5 +204,8 @@
                 if (!$dontTarNZip) {
                     my $tarball = tarAndZipBatch($output, $batch);
-                    if ($tarball && $datastoreProduct && publishToDatastore($batch, $output, $tarball)) {$published = 1;}
+                    if ($tarball && defined $datastore ) {
+                        
+                        $published = $datastore->register($batch, $output, $tarball, "IPP_PSPS", "tgz");
+                    }
                 }
             }
@@ -421,38 +426,4 @@
 
     if (!$foundFits) { print "* Could not find any FITS files for this batch\n"; return 0;}
-    return 1;
-}
-
-#######################################################################################
-#
-# register new job with the datastore
-#
-########################################################################################
-sub publishToDatastore {
-    my ($batch, $path, $tarball) = @_;
-
-    my ($tempFile, $tempName) = tempfile( "/tmp/ippToPsps_dsregList.XXXX", UNLINK => !$save_temps);
-
-    print $tempFile $tarball . '|||tgz' . "\n";
-
-    # build dsreg command command
-    my $command  = "$dsreg";
-    $command .= " --add $batch";
-    $command .= " --copy";
-    $command .= " --datapath $path";
-    $command .= " --type IPP_PSPS";
-    $command .= " --product $datastoreProduct";
-    $command .= " --list $tempName";
-
-    # run command
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbose);
-
-    if (!$success) { print "* Unable to publish $tarball to datastore\n" and return 0 };
-
-    print "* Successfully published $tarball to datastore\n";
-
-    close($tempFile);
-
     return 1;
 }
