Changeset 25 for trunk


Ignore:
Timestamp:
11/02/05 19:52:18 (19 years ago)
Author:
thauvin
Message:
  • document way of life (Michele Thetis)
  • doc about ObsData? module
  • functions to dir by type of data
Location:
trunk/soft
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/soft/ObsData/ObsData.pm

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r23 r25  
    88 
    99our $VERSION = 0.01; 
     10 
     11=head1 NAME 
     12 
     13ObsData - Main object to manage data files 
     14 
     15=head1 SYNOPSIS 
     16 
     17    use ObsData; 
     18    my $conf = "configfile"; 
     19    my $obsdata = ObsData->new($conf); 
     20 
     21=head1 METHODS 
     22 
     23=head2 new($configfile) 
     24 
     25Create a new Obsdata object from $configfile 
     26 
     27=cut 
    1028 
    1129sub new { 
     
    2341} 
    2442 
     43=head2 checkconfig() 
     44 
     45Check the validity of information contains in configfile. 
     46 
     47Notice: This test does not include the syntaxe validity 
     48 
     49=cut 
     50 
    2551sub checkconfig { 
    2652    my ($self) = @_; 
     
    2854        my ($obs) = $g =~ /\S+\s+(.*)/; 
    2955        if (!$self->{config}->SectionExists($obs)) { 
    30             print "E: '$obs' is listed as Obs but it does not exists\n"; 
     56            print STDERR "E: '$obs' is listed as Obs but it does not exists\n"; 
    3157            next; 
    3258        } 
     
    3662} 
    3763 
     64=head2 getvalue($section, $var, $default) 
     65 
     66Return a value from the configuration, $default is assumed if the value is not set 
     67 
     68=cut 
     69 
    3870sub getvalue { 
    3971    my ($self, $section, $var, $default) = @_; 
    4072    $self->{config}->val($section, $var, $default); 
    4173} 
     74 
     75=head2 list_obs 
     76 
     77Return the list of observatories defined in configuration 
     78 
     79=cut 
    4280 
    4381sub list_obs { 
     
    4886} 
    4987 
     88=head2 is_obs($obsname) 
     89 
     90Return True if $obsname is an observatory 
     91 
     92=cut 
     93 
    5094sub is_obs { 
    5195    my ($self, $obs) = @_; 
     
    5397} 
    5498 
    55 sub list_datadir { 
     99=head2 list_obsdatadir($obsname) 
     100 
     101Return a hash of data directories per data type for $obsname observatories 
     102 
     103=cut 
     104 
     105sub list_obsdatadir { 
    56106    my ($self, $obs) = @_; 
    57107    $self->is_obs($obs) or return undef; 
    58     map { m,^datadir/(.*),; ( $1 => $self->{config}->val($obs, $_) ) } 
    59         grep { m,^datadir/, }  
     108    map { m,^datadir/(.*),; ( ($1 || "") => $self->{config}->val($obs, $_) ) } 
     109        grep { m,^datadir/, || $_ eq 'datadir' } 
    60110        $self->{config}->Parameters($obs) 
    61111} 
     112 
     113=head2 list_typedatadir($type) 
     114 
     115List all directories for $type data 
     116 
     117=cut 
     118 
     119sub list_typedatadir { 
     120    my ($self, $type) = @_; 
     121    my %dirs; 
     122    foreach my $obs ($self->list_obs) { 
     123        $dirs{$_} = 1 foreach(grep { $_ } $self->get_datadir($obs, $type)); 
     124    } 
     125    keys %dirs;  
     126         
     127} 
     128 
     129=head2 get_datadir($obs, $type) 
     130 
     131Return a list of directories for $type data on $obs observatory 
     132 
     133=cut 
    62134 
    63135sub get_datadir { 
    64136    my ($self, $obs, $type) = @_; 
    65137    $self->is_obs($obs) or return undef; 
    66     $self->getvalue($obs, "datadir/$type"); 
     138    grep { defined($_) } ($self->getvalue($obs, "datadir/$type"), $self->getvalue($obs, "datadir")); 
    67139} 
    68140 
  • trunk/soft/ObsData/ObsData/Data.pm

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r24 r25  
    1111        obsdata => $obsdata, 
    1212        datafile => $file, 
     13        datatype => undef, 
    1314    }; 
    1415 
     
    2324    my ($self) = @_; 
    2425    # check if the config has all info need for proccessing 
     26    if(!$self->{datatype}) { 
     27        return 0; 
     28    } 
     29    # if ($self->{obsdata}->getvalue($self->{datatype}, ' 
    2530} 
     31 
     32 
    2633 
    27341; 
  • trunk/soft/ObsData/t/O-01.t

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r23 r25  
    55use_ok('ObsData'); 
    66 
    7 can_ok('ObsData', qw(list_obs list_datadir get_datadir getvalue is_obs)); 
     7can_ok('ObsData', qw(list_obs list_obsdatadir list_typedatadir get_datadir getvalue is_obs)); 
    88 
    99ok(ObsData->new('testdata/obsdata-conftest'), "Can create object"); 
  • trunk/soft/ObsData/t/O-02.t

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r23 r25  
    11# $Id$ 
    22 
    3 use Test::More tests => 8; 
     3use Test::More tests => 9; 
    44 
    55use_ok('ObsData'); 
     
    88ok($o->getvalue('ohp', 'description'), "can get value"); 
    99 
    10 ok(grep { 'ohp' } $o->list_obs, "Can list observatories"); 
     10ok(eq_set([ $o->list_obs ], [ 'ohp' ]), "Can list observatories"); 
    1111 
    1212ok($o->is_obs('ohp'), "check is an obs is defined"); 
    1313ok(!$o->is_obs('NOohp'), "check is an obs is not defined"); 
    1414 
    15 my %datadir =  $o->list_datadir('ohp'); 
     15{ 
     16my %datadir =  $o->list_obsdatadir('ohp'); 
    1617ok($datadir{ozone} eq 'testdata/ohp/ozone', "Can get list of data directory"); 
    17 ok($o->get_datadir('ohp', 'ozone') eq 'testdata/ohp/ozone', 'Can retrive data directory'); 
     18} 
     19 
     20ok(eq_set([ $o->list_typedatadir('ozone') ], [ 'testdata/ohp/ozone', 'testdata/ohp' ]) , 'Can list data directory'); 
     21ok(eq_set([ $o->get_datadir('ohp', 'ozone') ], [ 'testdata/ohp/ozone', 'testdata/ohp' ]) , 'Can retrive data directory'); 
  • trunk/soft/ObsData/testdata/obsdata-conftest

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r22 r25  
    99[ohp] 
    1010description=Observatoire de Haute Provence 
     11datadir=testdata/ohp 
    1112datadir/ozone=testdata/ohp/ozone 
    12  
    1313 
    1414[ozone] 
    1515 
     16[oxygene] 
  • trunk/soft/README

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r11 r25  
     1$Id$ 
     2 
    13ObsData : Perl Libary to manage data files 
    24 
    3 $Id$ 
     5*********** 
     6* Methode * 
     7*********** 
     8 
     9- répertoire d'arrivée des données 
     10    - 1 répertoire par station ! 
     11    - lister les archives présentes 
     12    - filtrer les archives encore à traiter (comment identifier ?) 
     13        - on listes les fichiers de données contenu 
     14        - si une règle de traitement est applicable => applique le traitement 
     15        - sinon => poser le fichier dans les rejets 
     16 
     17Besoin par archive: 
     18    - date de traitement 
     19    - fichiers data 
     20        - regle apliquée 
     21        - destination finale 
     22 
     23[STATION] 
     24source = /sources/archives 
     25 
     26[LIDAR] 
     27match = ^LIDAR.* 
     28properties = ^LIDAR-([^-]*)-([^\.]*)$ date extension 
     29archive_properties = ^LIDAR-([^-]*)-([^\.]*)$ date extension 
     30destination = /foo/%s/name/LIDAR/ date 
Note: See TracChangeset for help on using the changeset viewer.