IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 19, 2008, 10:09:10 AM (18 years ago)
Author:
eugene
Message:

re-vamping config to define user/site/system

File:
1 edited

Legend:

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

    r16325 r16542  
    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.75.2.1 2008-02-19 20:09:09 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    print "load site\n";
     99    $self->load_site();
     100
     101    print "load system\n";
     102    $self->load_system();
    95103
    96104    $self->define_camera($camera) if defined $camera;
     
    140148}
    141149
     150# Load the site config file
     151sub load_site
     152{
     153    my $self = shift;           # Configuration object
     154
     155    my $i = 0;
     156    print "$i"; $i ++;
     157
     158    unless (defined $self) {
     159        carp "Programming error";
     160        exit($PS_EXIT_PROG_ERROR);
     161    }
     162    print "$i"; $i ++;
     163
     164    my $filename = metadataLookupStr($self->{_userConfig}, 'SITE'); # Site config file
     165    unless (defined $filename) {
     166        carp "Unable to find site configuration file\n";
     167        exit($PS_EXIT_CONFIG_ERROR);
     168    }
     169    print "$i"; $i ++;
     170
     171    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
     172    print "$i"; $i ++;
     173
     174    # Read the file
     175    my $file;                   # File handle
     176    unless (open $file, $realfile) {
     177        carp "Unable to open site configuration file $realfile: $!";
     178        exit($PS_EXIT_CONFIG_ERROR);
     179    }
     180    print "$i"; $i ++;
     181
     182    my @contents = <$file>;
     183    close $file;
     184    $self->{_siteConfig} = $parser->parse( join '', @contents); # The parsed metadata config
     185    print "$i"; $i ++;
     186
     187    ## XXXX : the error is here
     188    unless (defined $self->{_siteConfig}) {
     189        carp "Failure to define site configuration";
     190        exit($PS_EXIT_CONFIG_ERROR);
     191    }
     192    print "$i"; $i ++;
     193
     194    # XXX why isn't just $self being returned here? -JH
     195    return $self;
     196}
     197
     198# Load the system config file
     199sub load_system
     200{
     201    my $self = shift;           # Configuration object
     202
     203    unless (defined $self) {
     204        carp "Programming error";
     205        exit($PS_EXIT_PROG_ERROR);
     206    }
     207
     208    my $filename = metadataLookupStr($self->{_userConfig}, 'SYSTEM'); # System config file
     209    unless (defined $filename) {
     210        carp "Unable to find system configuration file\n";
     211        exit($PS_EXIT_CONFIG_ERROR);
     212    }
     213
     214    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
     215
     216    # Read the file
     217    my $file;                   # File handle
     218    unless (open $file, $realfile) {
     219        carp "Unable to open system configuration file $realfile: $!";
     220        exit($PS_EXIT_CONFIG_ERROR);
     221    }
     222    my @contents = <$file>;
     223    close $file;
     224    $self->{_systemConfig} = $parser->parse( join '', @contents); # The parsed metadata config
     225
     226    unless (defined $self->{_systemConfig}) {
     227        carp "Failure to define system configuration";
     228        exit($PS_EXIT_CONFIG_ERROR);
     229    }
     230
     231    # XXX why isn't just $self being returned here? -JH
     232    return $self;
     233}
     234
    142235# Define a camera to use
    143236sub define_camera
     
    151244    }
    152245
    153     my $camera_list = metadataLookupMD($self->{_ipprc}, 'CAMERAS'); # List of cameras
     246    my $camera_list = metadataLookupMD($self->{_systemConfig}, 'CAMERAS'); # List of cameras
    154247    my $filename = metadataLookupStr($camera_list, $name); # Filename of camera configuration
    155248    unless (defined $filename) {
     
    233326    }
    234327
    235     my $path_list = metadataLookupMD($self->{_ipprc}, 'DATAPATH'); # List of paths
     328    my $path_list = metadataLookupMD($self->{_siteConfig}, 'DATAPATH'); # List of paths
    236329    my $pathname = metadataLookupStr($path_list, $name); # Path of interest
    237330    unless (defined $pathname) {
     
    258351    return 1 if defined $self->{nebulous}; # Already started
    259352
    260     my $server = metadataLookupStr( $self->{_ipprc}, 'NEB_SERVER' ); # Nebulous server
     353    my $server = metadataLookupStr( $self->{_siteConfig}, 'NEB_SERVER' ); # Nebulous server
    261354    unless (defined $server) {
    262355        carp "Unable to find NEB_SERVER in camera configuration file.";
     
    561654    my @dirs = File::Spec->splitdir( $name );
    562655   
    563     my $path_list = metadataLookupMD($self->{_ipprc}, 'DATAPATH'); # List of paths
     656    my $path_list = metadataLookupMD($self->{_siteConfig}, 'DATAPATH'); # List of paths
    564657    my $best_path;
    565658    my $best_name;
     
    790883    my $tess_id = shift;        # Tessellation identifier
    791884
    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
     885    unless (defined $self and defined $self->{_siteConfig} and defined $tess_id) {
     886        carp "Programming error";
     887        exit($PS_EXIT_PROG_ERROR);
     888    }
     889
     890    my $tessellations = metadataLookupMD($self->{_siteConfig}, 'TESSELLATIONS'); # Tessellations
    798891    unless (defined $tessellations) {
    799892        carp "Can't find TESSELLATIONS in site configuration.\n";
     
    817910}
    818911
     912
     913# Return catdir for the dvo db, from DVO.CATDIRS within the site configuration
     914sub dvo_catdir
     915{
     916    my $self = shift;   # Configuration object
     917    my $dvodb = shift;  # DVO db identifier
     918
     919    unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) {
     920        carp "Programming error";
     921        exit($PS_EXIT_PROG_ERROR);
     922    }
     923
     924    my $catdirs = metadataLookupMD($self->{_siteConfig}, 'DVO.CATDIRS'); # Tessellations
     925    unless (defined $catdirs) {
     926        carp "Can't find DVO.CATDIRS in site configuration.\n";
     927        exit($PS_EXIT_CONFIG_ERROR);
     928    }
     929
     930    my $catdir = metadataLookupStr($catdirs, $dvodb);
     931    unless (defined $catdir) {
     932        carp "Can't find dvodb identifier $dvodb in DVO.CATDIR in site configuration.\n";
     933        exit($PS_EXIT_CONFIG_ERROR);
     934    }
     935
     936    ### Because DVO doesn't use psModules, it doesn't understand Nebulous --- check
     937    my $scheme = file_scheme($catdir); # The scheme, e.g., file, path, neb
     938    if (defined $scheme and lc($scheme) eq 'neb') {
     939        carp "DVO catdir $dvodb refers to a Nebulous path: $catdir\n";
     940        exit($PS_EXIT_CONFIG_ERROR);
     941    }
     942
     943    return $catdir
     944}
     945
     946# Return catdir for the psastro reference, from PSASTRO.CATDIRS within the site configuration
     947sub psastro_catdir
     948{
     949    my $self = shift;   # Configuration object
     950    my $dvodb = shift;  # DVO db identifier
     951
     952    unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) {
     953        carp "Programming error";
     954        exit($PS_EXIT_PROG_ERROR);
     955    }
     956
     957    my $catdirs = metadataLookupMD($self->{_siteConfig}, 'PSASTRO.CATDIRS'); # Tessellations
     958    unless (defined $catdirs) {
     959        carp "Can't find PSASTRO.CATDIRS in site configuration.\n";
     960        exit($PS_EXIT_CONFIG_ERROR);
     961    }
     962
     963    my $catdir = metadataLookupStr($catdirs, $dvodb);
     964    unless (defined $catdir) {
     965        carp "Can't find dvodb identifier $dvodb in PSASTRO.CATDIR in site configuration.\n";
     966        exit($PS_EXIT_CONFIG_ERROR);
     967    }
     968
     969    ### Because DVO doesn't use psModules, it doesn't understand Nebulous --- check
     970    my $scheme = file_scheme($catdir); # The scheme, e.g., file, path, neb
     971    if (defined $scheme and lc($scheme) eq 'neb') {
     972        carp "PSASTRO catdir $dvodb refers to a Nebulous path: $catdir\n";
     973        exit($PS_EXIT_CONFIG_ERROR);
     974    }
     975
     976    return $catdir
     977}
    819978
    820979# Return the DVO.CAMERADIR in the camera configuration
Note: See TracChangeset for help on using the changeset viewer.