Index: trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
===================================================================
--- trunk/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 16325)
+++ trunk/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 16611)
@@ -1,5 +1,5 @@
 # Copyright (c) 2006  Paul Price, Joshua Hoblitt
 #
-# $Id: Config.pm,v 1.75 2008-02-06 02:05:44 price Exp $
+# $Id: Config.pm,v 1.76 2008-02-22 20:20:37 eugene Exp $
 
 package PS::IPP::Config;
@@ -62,5 +62,5 @@
     my $name;			# Name of ipprc file
     GetOptions( 'site=s' => \$name );
-    $name = $ENV{PS_SITE} if not defined $name;
+    $name = $ENV{IPPRC} if not defined $name;
     if (not defined $name and defined $ENV{HOME}) {
 	$name = $ENV{HOME} . '/.ipprc';
@@ -90,7 +90,12 @@
 	filerules => undef,	# File rules from the camera configuration
 	rejection => undef,	# Rejection data
-	_ipprc => $mdc		# The parsed configuration
+	_userConfig => $mdc,	# The top-level user configuration
+	_siteConfig => undef,	# The site configuration (from _userConfig)
+	_systemConfig => undef	# The system configuration (from _userConfig)
 	};
     bless $self, $class;
+
+    $self->load_site();
+    $self->load_system();
 
     $self->define_camera($camera) if defined $camera;
@@ -140,4 +145,80 @@
 }
 
+# Load the site config file
+sub load_site
+{
+    my $self = shift;		# Configuration object
+
+    my $i = 0;
+
+    unless (defined $self) {
+	carp "Programming error";
+	exit($PS_EXIT_PROG_ERROR);
+    }
+
+    my $filename = metadataLookupStr($self->{_userConfig}, 'SITE'); # Site config file
+    unless (defined $filename) {
+	carp "Unable to find site configuration file\n";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
+
+    # Read the file
+    my $file;			# File handle
+    unless (open $file, $realfile) {
+	carp "Unable to open site configuration file $realfile: $!";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    my @contents = <$file>;
+    close $file;
+    $self->{_siteConfig} = $parser->parse( join '', @contents); # The parsed metadata config
+
+    unless (defined $self->{_siteConfig}) {
+	carp "Failure to parse the site configuration file $realfile";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    return $self;
+}
+
+# Load the system config file
+sub load_system
+{
+    my $self = shift;		# Configuration object
+
+    unless (defined $self) {
+	carp "Programming error";
+	exit($PS_EXIT_PROG_ERROR);
+    }
+
+    my $filename = metadataLookupStr($self->{_userConfig}, 'SYSTEM'); # System config file
+    unless (defined $filename) {
+	carp "Unable to find system configuration file\n";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
+
+    # Read the file
+    my $file;			# File handle
+    unless (open $file, $realfile) {
+	carp "Unable to open system configuration file $realfile: $!";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+    my @contents = <$file>;
+    close $file;
+    $self->{_systemConfig} = $parser->parse( join '', @contents); # The parsed metadata config
+
+    unless (defined $self->{_systemConfig}) {
+	carp "Failure to define system configuration";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    # XXX why isn't just $self being returned here? -JH
+    return $self;
+}
+
 # Define a camera to use
 sub define_camera
@@ -151,5 +232,5 @@
     }
 
-    my $camera_list = metadataLookupMD($self->{_ipprc}, 'CAMERAS'); # List of cameras
+    my $camera_list = metadataLookupMD($self->{_systemConfig}, 'CAMERAS'); # List of cameras
     my $filename = metadataLookupStr($camera_list, $name); # Filename of camera configuration
     unless (defined $filename) {
@@ -233,5 +314,5 @@
     }
 
-    my $path_list = metadataLookupMD($self->{_ipprc}, 'DATAPATH'); # List of paths
+    my $path_list = metadataLookupMD($self->{_siteConfig}, 'DATAPATH'); # List of paths
     my $pathname = metadataLookupStr($path_list, $name); # Path of interest
     unless (defined $pathname) {
@@ -258,5 +339,5 @@
     return 1 if defined $self->{nebulous}; # Already started
 
-    my $server = metadataLookupStr( $self->{_ipprc}, 'NEB_SERVER' ); # Nebulous server
+    my $server = metadataLookupStr( $self->{_siteConfig}, 'NEB_SERVER' ); # Nebulous server
     unless (defined $server) {
 	carp "Unable to find NEB_SERVER in camera configuration file.";
@@ -561,5 +642,5 @@
     my @dirs = File::Spec->splitdir( $name );
     
-    my $path_list = metadataLookupMD($self->{_ipprc}, 'DATAPATH'); # List of paths
+    my $path_list = metadataLookupMD($self->{_siteConfig}, 'DATAPATH'); # List of paths
     my $best_path;
     my $best_name;
@@ -790,10 +871,10 @@
     my $tess_id = shift;	# Tessellation identifier
 
-    unless (defined $self and defined $self->{_ipprc} and defined $tess_id) {
-	carp "Programming error";
-	exit($PS_EXIT_PROG_ERROR);
-    }
-
-    my $tessellations = metadataLookupMD($self->{_ipprc}, 'TESSELLATIONS'); # Tessellations
+    unless (defined $self and defined $self->{_siteConfig} and defined $tess_id) {
+	carp "Programming error";
+	exit($PS_EXIT_PROG_ERROR);
+    }
+
+    my $tessellations = metadataLookupMD($self->{_siteConfig}, 'TESSELLATIONS'); # Tessellations
     unless (defined $tessellations) {
 	carp "Can't find TESSELLATIONS in site configuration.\n";
@@ -817,4 +898,70 @@
 }
 
+
+# Return catdir for the dvo db, from DVO.CATDIRS within the site configuration
+sub dvo_catdir
+{
+    my $self = shift;	# Configuration object
+    my $dvodb = shift;	# DVO db identifier
+
+    unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) {
+	carp "Programming error";
+	exit($PS_EXIT_PROG_ERROR);
+    }
+
+    my $catdirs = metadataLookupMD($self->{_siteConfig}, 'DVO.CATDIRS'); # Tessellations
+    unless (defined $catdirs) {
+	carp "Can't find DVO.CATDIRS in site configuration.\n";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    my $catdir = metadataLookupStr($catdirs, $dvodb);
+    unless (defined $catdir) {
+	carp "Can't find dvodb identifier $dvodb in DVO.CATDIR in site configuration.\n";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    ### Because DVO doesn't use psModules, it doesn't understand Nebulous --- check
+    my $scheme = file_scheme($catdir); # The scheme, e.g., file, path, neb
+    if (defined $scheme and lc($scheme) eq 'neb') {
+	carp "DVO catdir $dvodb refers to a Nebulous path: $catdir\n";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    return $catdir
+}
+
+# Return catdir for the psastro reference, from PSASTRO.CATDIRS within the site configuration
+sub psastro_catdir
+{
+    my $self = shift;	# Configuration object
+    my $dvodb = shift;	# DVO db identifier
+
+    unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) {
+	carp "Programming error";
+	exit($PS_EXIT_PROG_ERROR);
+    }
+
+    my $catdirs = metadataLookupMD($self->{_siteConfig}, 'PSASTRO.CATDIRS'); # Tessellations
+    unless (defined $catdirs) {
+	carp "Can't find PSASTRO.CATDIRS in site configuration.\n";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    my $catdir = metadataLookupStr($catdirs, $dvodb);
+    unless (defined $catdir) {
+	carp "Can't find dvodb identifier $dvodb in PSASTRO.CATDIR in site configuration.\n";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    ### Because DVO doesn't use psModules, it doesn't understand Nebulous --- check
+    my $scheme = file_scheme($catdir); # The scheme, e.g., file, path, neb
+    if (defined $scheme and lc($scheme) eq 'neb') {
+	carp "PSASTRO catdir $dvodb refers to a Nebulous path: $catdir\n";
+	exit($PS_EXIT_CONFIG_ERROR);
+    }
+
+    return $catdir
+}
 
 # Return the DVO.CAMERADIR in the camera configuration
