Index: trunk/ippScripts/scripts/sc_remote_poll.pl
===================================================================
--- trunk/ippScripts/scripts/sc_remote_poll.pl	(revision 38145)
+++ trunk/ippScripts/scripts/sc_remote_poll.pl	(revision 38168)
@@ -26,13 +26,4 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
-
-# Hard coded values
-my $DMZ_HOST = 'wtrw';
-my @SEC_HOSTS= ('mu-fe1','mu-fe2','mu-fe3'
-		# ,'mu-fe4'
-    );
-my $SEC_HOST = $SEC_HOSTS[int(rand(@SEC_HOSTS))]; # 'mu-fe';
-my $IPP_PATH = '/turquoise/usr/projects/cosmo/mswarren/ipp/';
-my $remote_root  = '/scratch3/watersc1/';
 
 # tools
@@ -44,4 +35,5 @@
 my $camtool    = can_run('camtool')    or (warn "Can't find camtool"    and $missing_tools = 1);
 my $warptool   = can_run('warptool')   or (warn "Can't find warptool"   and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
 
 if ($missing_tools) {
@@ -51,5 +43,5 @@
 
 # Options
-my ($remote_id,$path_base,$skip_poll,$skip_transfer,$job_id,$dbname,$retry,$verbose,$no_update,$camera);
+my ($remote_id,$path_base,$skip_poll,$skip_transfer,$job_id,$dbname,$retry,$verbose,$no_update,$camera,$cmd_recipe);
 $verbose = 0;
 GetOptions(
@@ -61,4 +53,5 @@
     'camera=s'      => \$camera,
     'dbname=s'      => \$dbname,
+    'recipe=s'       => \$cmd_recipe,
     'retry'         => \$retry,
     'verbose'       => \$verbose,
@@ -67,8 +60,71 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --remote_id --job_id --path_base", -exitval => 3) unless
+pod2usage( -msg => "Required options: --remote_id --job_id --path_base --recipe", -exitval => 3) unless
     defined($path_base) and
     defined($remote_id) and
+    defined($cmd_recipe) and
     defined($job_id);
+
+
+
+# Now accessible from a recipe
+my %remote_recipe = ();
+{
+    my $verbose = 0;
+    my $conf_cmd = "$ppConfigDump -dump-recipe REMOTE -";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $conf_cmd, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppConfigDump: $error_code", -1, $PS_EXIT_SYS_ERROR);
+    }
+    my $mdcParser = PS::IPP::Metadata::Config->new;
+    my $metadata = $mdcParser->parse(join "", @$stdout_buf);
+
+    my $active_recipe = '';
+    my %recipes = ();
+    
+#    print Dumper($metadata);
+    foreach my $entry (@{ $metadata }) {
+        if (${ $entry }{name} eq 'ACTIVE') {
+	$active_recipe = ${ $entry }{value}; # Not actually used
+	}
+	else {
+	    if (${ $entry }{class} eq 'metadata') { # A real recipe
+		my $name = ${ $entry }{name};
+		foreach my $tentry (@{ ${ $entry }{value} }) {
+		    if (${ $tentry }{class} eq 'scalar') { # A recipe value
+			$recipes{$name}{${ $tentry }{name}} = ${ $tentry }{value};
+                    }
+		    elsif (${ $tentry }{class} eq 'metadata') { # A recipe array 
+                        foreach my $arr_entry (@{ ${ $tentry }{value} }) {
+                            push @{ $recipes{$name}{${ $tentry }{name}} }, ${ $arr_entry }{value};
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
+    unless (exists($recipes{$cmd_recipe})) { &my_die("Cannot find recipe $cmd_recipe", -1, $PS_EXIT_CONFIG_ERROR) };
+#    print Dumper(%recipes);
+    %remote_recipe = %{ $recipes{$cmd_recipe} }; # Select the appropriate recipe.
+#    print Dumper(\%remote_recipe);
+}
+
+
+# Hard coded values
+my $DMZ_HOST = $remote_recipe{DMZ_HOST};
+my @SEC_HOSTS= @{ $remote_recipe{SEC_HOST} };
+my $SEC_HOST;
+if ($#SEC_HOSTS != -1) {
+    $SEC_HOST = $SEC_HOSTS[int(rand(@SEC_HOSTS))]; 
+}
+else {
+    $SEC_HOST = '';
+}
+my $IPP_PATH = $remote_recipe{IPP_PATH};
+my $remote_root  = $remote_recipe{REMOTE_ROOT};
+
 
 my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id);
@@ -351,5 +407,11 @@
     my $file = shift;
     my $destination = shift;
-    my $cmd = "$scp $file ${DMZ_HOST}:${SEC_HOST}:${destination}";
+    my $cmd;
+    if ($SEC_HOST ne '') {
+	$cmd = "$scp $file ${DMZ_HOST}:${SEC_HOST}:${destination}";
+    }
+    else {
+        $cmd = "$scp $file ${DMZ_HOST}:${destination}";
+    }
 
     my $directory = dirname($destination);
@@ -367,6 +429,11 @@
     my $destination = shift;
     my $file = shift;
-
-    my $cmd = "$scp ${DMZ_HOST}:${SEC_HOST}:${destination} $file ";
+    my $cmd;
+    if ($SEC_HOST ne '') {
+	$cmd = "$scp ${DMZ_HOST}:${SEC_HOST}:${destination} $file ";
+    }
+    else {
+        $cmd = "$scp $file ${DMZ_HOST}:${destination}";
+    }
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -380,5 +447,12 @@
 sub ssh_exec_command {
     my $cmd = shift;
-    $cmd = "$ssh -n $DMZ_HOST ssh  ${SEC_HOST} $cmd";
+
+    if ($SEC_HOST ne '') {
+        $cmd = "$ssh -n $DMZ_HOST ssh  ${SEC_HOST} $cmd";
+    }
+    else {
+        $cmd = "$ssh -n $DMZ_HOST $cmd";
+    }
+
     print "EXEC: $cmd\n";
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -511,11 +585,11 @@
     }
     elsif ($stage eq 'staticsky') {
-#	($class_id, $stage_id) = $file =~ /(/;
+	($class_id, $stage_id) = $file =~ /(skycell.\d\d\d\d.\d\d\d).sky.(\d*).dbinfo/;
     }
     elsif ($stage eq 'diff') {
-#	($class_id,$stage_id) = $file =~ /(/;
+	($class_id,$stage_id) = $file =~ /(skycell.\d\d\d\d.\d\d\d).WS.dif.(\d*).dbinfo/;
     }
     elsif ($stage eq 'ff') {
-#	($class_id,$stage_id) = $file =~ /(/;
+	($class_id,$stage_id) = $file =~ /wrp\.(\d*).ff.(\d*).dbinfo/;
     }
     return ($stage_id, $class_id);
@@ -548,4 +622,14 @@
         $class_id = 0;
     }
+    elsif ($stage eq 'staticsky') {
+	($class_id, $stage_id, $component) = $file =~ /(skycell.\d\d\d\d.\d\d\d).sky.(\d*).([\w\.]+)$/;
+    }
+    elsif ($stage eq 'diff') {
+	($class_id,$stage_id, $component) = $file =~ /(skycell.\d\d\d\d.\d\d\d).WS.dif.(\d*).([\w\.]+)$/;
+    }
+    elsif ($stage eq 'ff') {
+	($class_id,$stage_id, $component) = $file =~ /wrp\.(\d*).ff.(\d*).([\w\.]+)$/;
+    }
+
     return($stage_id,$class_id,$component);
 }
