IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 22, 2008, 10:21:52 AM (18 years ago)
Author:
eugene
Message:

using new user/site/system construction for config files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Config.pm

    r16325 r16611  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.75 2008-02-06 02:05:44 price Exp $
     3# $Id: Config.pm,v 1.76 2008-02-22 20:20:37 eugene Exp $
    44
    55package PS::IPP::Config;
     
    6262    my $name;                   # Name of ipprc file
    6363    GetOptions( 'site=s' => \$name );
    64     $name = $ENV{PS_SITE} if not defined $name;
     64    $name = $ENV{IPPRC} if not defined $name;
    6565    if (not defined $name and defined $ENV{HOME}) {
    6666        $name = $ENV{HOME} . '/.ipprc';
     
    9090        filerules => undef,     # File rules from the camera configuration
    9191        rejection => undef,     # Rejection data
    92         _ipprc => $mdc          # The parsed configuration
     92        _userConfig => $mdc,    # The top-level user configuration
     93        _siteConfig => undef,   # The site configuration (from _userConfig)
     94        _systemConfig => undef  # The system configuration (from _userConfig)
    9395        };
    9496    bless $self, $class;
     97
     98    $self->load_site();
     99    $self->load_system();
    95100
    96101    $self->define_camera($camera) if defined $camera;
     
    140145}
    141146
     147# Load the site config file
     148sub load_site
     149{
     150    my $self = shift;           # Configuration object
     151
     152    my $i = 0;
     153
     154    unless (defined $self) {
     155        carp "Programming error";
     156        exit($PS_EXIT_PROG_ERROR);
     157    }
     158
     159    my $filename = metadataLookupStr($self->{_userConfig}, 'SITE'); # Site config file
     160    unless (defined $filename) {
     161        carp "Unable to find site configuration file\n";
     162        exit($PS_EXIT_CONFIG_ERROR);
     163    }
     164
     165    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
     166
     167    # Read the file
     168    my $file;                   # File handle
     169    unless (open $file, $realfile) {
     170        carp "Unable to open site configuration file $realfile: $!";
     171        exit($PS_EXIT_CONFIG_ERROR);
     172    }
     173
     174    my @contents = <$file>;
     175    close $file;
     176    $self->{_siteConfig} = $parser->parse( join '', @contents); # The parsed metadata config
     177
     178    unless (defined $self->{_siteConfig}) {
     179        carp "Failure to parse the site configuration file $realfile";
     180        exit($PS_EXIT_CONFIG_ERROR);
     181    }
     182
     183    return $self;
     184}
     185
     186# Load the system config file
     187sub load_system
     188{
     189    my $self = shift;           # Configuration object
     190
     191    unless (defined $self) {
     192        carp "Programming error";
     193        exit($PS_EXIT_PROG_ERROR);
     194    }
     195
     196    my $filename = metadataLookupStr($self->{_userConfig}, 'SYSTEM'); # System config file
     197    unless (defined $filename) {
     198        carp "Unable to find system configuration file\n";
     199        exit($PS_EXIT_CONFIG_ERROR);
     200    }
     201
     202    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
     203
     204    # Read the file
     205    my $file;                   # File handle
     206    unless (open $file, $realfile) {
     207        carp "Unable to open system configuration file $realfile: $!";
     208        exit($PS_EXIT_CONFIG_ERROR);
     209    }
     210    my @contents = <$file>;
     211    close $file;
     212    $self->{_systemConfig} = $parser->parse( join '', @contents); # The parsed metadata config
     213
     214    unless (defined $self->{_systemConfig}) {
     215        carp "Failure to define system configuration";
     216        exit($PS_EXIT_CONFIG_ERROR);
     217    }
     218
     219    # XXX why isn't just $self being returned here? -JH
     220    return $self;
     221}
     222
    142223# Define a camera to use
    143224sub define_camera
     
    151232    }
    152233
    153     my $camera_list = metadataLookupMD($self->{_ipprc}, 'CAMERAS'); # List of cameras
     234    my $camera_list = metadataLookupMD($self->{_systemConfig}, 'CAMERAS'); # List of cameras
    154235    my $filename = metadataLookupStr($camera_list, $name); # Filename of camera configuration
    155236    unless (defined $filename) {
     
    233314    }
    234315
    235     my $path_list = metadataLookupMD($self->{_ipprc}, 'DATAPATH'); # List of paths
     316    my $path_list = metadataLookupMD($self->{_siteConfig}, 'DATAPATH'); # List of paths
    236317    my $pathname = metadataLookupStr($path_list, $name); # Path of interest
    237318    unless (defined $pathname) {
     
    258339    return 1 if defined $self->{nebulous}; # Already started
    259340
    260     my $server = metadataLookupStr( $self->{_ipprc}, 'NEB_SERVER' ); # Nebulous server
     341    my $server = metadataLookupStr( $self->{_siteConfig}, 'NEB_SERVER' ); # Nebulous server
    261342    unless (defined $server) {
    262343        carp "Unable to find NEB_SERVER in camera configuration file.";
     
    561642    my @dirs = File::Spec->splitdir( $name );
    562643   
    563     my $path_list = metadataLookupMD($self->{_ipprc}, 'DATAPATH'); # List of paths
     644    my $path_list = metadataLookupMD($self->{_siteConfig}, 'DATAPATH'); # List of paths
    564645    my $best_path;
    565646    my $best_name;
     
    790871    my $tess_id = shift;        # Tessellation identifier
    791872
    792     unless (defined $self and defined $self->{_ipprc} and defined $tess_id) {
    793         carp "Programming error";
    794         exit($PS_EXIT_PROG_ERROR);
    795     }
    796 
    797     my $tessellations = metadataLookupMD($self->{_ipprc}, 'TESSELLATIONS'); # Tessellations
     873    unless (defined $self and defined $self->{_siteConfig} and defined $tess_id) {
     874        carp "Programming error";
     875        exit($PS_EXIT_PROG_ERROR);
     876    }
     877
     878    my $tessellations = metadataLookupMD($self->{_siteConfig}, 'TESSELLATIONS'); # Tessellations
    798879    unless (defined $tessellations) {
    799880        carp "Can't find TESSELLATIONS in site configuration.\n";
     
    817898}
    818899
     900
     901# Return catdir for the dvo db, from DVO.CATDIRS within the site configuration
     902sub dvo_catdir
     903{
     904    my $self = shift;   # Configuration object
     905    my $dvodb = shift;  # DVO db identifier
     906
     907    unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) {
     908        carp "Programming error";
     909        exit($PS_EXIT_PROG_ERROR);
     910    }
     911
     912    my $catdirs = metadataLookupMD($self->{_siteConfig}, 'DVO.CATDIRS'); # Tessellations
     913    unless (defined $catdirs) {
     914        carp "Can't find DVO.CATDIRS in site configuration.\n";
     915        exit($PS_EXIT_CONFIG_ERROR);
     916    }
     917
     918    my $catdir = metadataLookupStr($catdirs, $dvodb);
     919    unless (defined $catdir) {
     920        carp "Can't find dvodb identifier $dvodb in DVO.CATDIR in site configuration.\n";
     921        exit($PS_EXIT_CONFIG_ERROR);
     922    }
     923
     924    ### Because DVO doesn't use psModules, it doesn't understand Nebulous --- check
     925    my $scheme = file_scheme($catdir); # The scheme, e.g., file, path, neb
     926    if (defined $scheme and lc($scheme) eq 'neb') {
     927        carp "DVO catdir $dvodb refers to a Nebulous path: $catdir\n";
     928        exit($PS_EXIT_CONFIG_ERROR);
     929    }
     930
     931    return $catdir
     932}
     933
     934# Return catdir for the psastro reference, from PSASTRO.CATDIRS within the site configuration
     935sub psastro_catdir
     936{
     937    my $self = shift;   # Configuration object
     938    my $dvodb = shift;  # DVO db identifier
     939
     940    unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) {
     941        carp "Programming error";
     942        exit($PS_EXIT_PROG_ERROR);
     943    }
     944
     945    my $catdirs = metadataLookupMD($self->{_siteConfig}, 'PSASTRO.CATDIRS'); # Tessellations
     946    unless (defined $catdirs) {
     947        carp "Can't find PSASTRO.CATDIRS in site configuration.\n";
     948        exit($PS_EXIT_CONFIG_ERROR);
     949    }
     950
     951    my $catdir = metadataLookupStr($catdirs, $dvodb);
     952    unless (defined $catdir) {
     953        carp "Can't find dvodb identifier $dvodb in PSASTRO.CATDIR in site configuration.\n";
     954        exit($PS_EXIT_CONFIG_ERROR);
     955    }
     956
     957    ### Because DVO doesn't use psModules, it doesn't understand Nebulous --- check
     958    my $scheme = file_scheme($catdir); # The scheme, e.g., file, path, neb
     959    if (defined $scheme and lc($scheme) eq 'neb') {
     960        carp "PSASTRO catdir $dvodb refers to a Nebulous path: $catdir\n";
     961        exit($PS_EXIT_CONFIG_ERROR);
     962    }
     963
     964    return $catdir
     965}
    819966
    820967# Return the DVO.CAMERADIR in the camera configuration
Note: See TracChangeset for help on using the changeset viewer.