source: trunk/soft/ObsData/ObsData.pm @ 23

Last change on this file since 23 was 23, checked in by thauvin, 19 years ago
  • check obs really exists when getting value
  • Property cvs2svn:cvs-rev set to 1.4
  • Property svn:keywords set to Author Date Id Revision
File size: 1.5 KB
Line 
1# $Id$
2
3package ObsData;
4
5use strict;
6use warnings;
7use Config::IniFiles;
8
9our $VERSION = 0.01;
10
11sub new {
12    my ($class, $configfile) = @_;
13    my $obsdata = {
14        config => new Config::IniFiles(
15            -file => $configfile,
16            -default => 'global',
17            -allowcontinue => 1
18        ),
19    };
20   
21    (-f $configfile && -r _) && $obsdata->{config} or return undef;
22    bless($obsdata, $class);
23}
24
25sub checkconfig {
26    my ($self) = @_;
27    foreach my $g ($self->{config}->GroupMembers('Obs')) {
28        my ($obs) = $g =~ /\S+\s+(.*)/;
29        if (!$self->{config}->SectionExists($obs)) {
30            print "E: '$obs' is listed as Obs but it does not exists\n";
31            next;
32        }
33        foreach my $param ($self->{config}->Parameters($obs)) {
34        }
35    }
36}
37
38sub getvalue {
39    my ($self, $section, $var, $default) = @_;
40    $self->{config}->val($section, $var, $default);
41}
42
43sub list_obs {
44    my ($self) = @_;
45    grep { $self->{config}->SectionExists($_) }
46        map { s/^\S+\s+//; $_ }
47        $self->{config}->GroupMembers('Obs');
48}
49
50sub is_obs {
51    my ($self, $obs) = @_;
52    grep { $_ eq "Obs $obs" } $self->{config}->GroupMembers('Obs');
53}
54
55sub list_datadir {
56    my ($self, $obs) = @_;
57    $self->is_obs($obs) or return undef;
58    map { m,^datadir/(.*),; ( $1 => $self->{config}->val($obs, $_) ) }
59        grep { m,^datadir/, } 
60        $self->{config}->Parameters($obs)
61}
62
63sub get_datadir {
64    my ($self, $obs, $type) = @_;
65    $self->is_obs($obs) or return undef;
66    $self->getvalue($obs, "datadir/$type");
67}
68
691;
Note: See TracBrowser for help on using the repository browser.