Changeset 87


Ignore:
Timestamp:
12/01/05 15:22:59 (19 years ago)
Author:
thauvin
Message:
  • start to make class independant
Location:
trunk/soft/ObsData
Files:
4 added
3 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.28 to 1.29
    r85 r87  
    277277    foreach my $datatype (keys %datadir) { 
    278278        my $or = ObsData::Repository::dir->new( 
    279             $self, 
    280             $datadir{$datatype}, 
    281             obs => $obs, 
    282             datatype => $datatype, 
     279            { 
     280                obsdata => $self, 
     281                dir => $datadir{$datatype}, 
     282                obs => $obs, 
     283                datatype => $datatype, 
     284                statusfile => "$datadir{$datatype}/obsdata.ini" 
     285            } 
    283286        ); 
    284287        if (!defined($or)) { 
  • trunk/soft/ObsData/ObsData/Repository.pm

    • Property cvs2svn:cvs-rev changed from 1.25 to 1.26
    r86 r87  
    3434 
    3535sub new { 
    36     my ($class, $infos) = @_; 
    37  
     36    my ($class, $infos, %param) = @_; 
     37 
     38    my $or = { %$infos }; 
     39    foreach (keys %param) { 
     40        $or->{$_} = $param{$_}; 
     41    } 
     42     
    3843    # $infos-> 
    3944    # obsdata ObsData object 
    40     $infos->{obsdata} or die "Error #1de8d015, please insult programmer"; 
     45    $or->{obsdata} or die "Error #1de8d015, please insult programmer"; 
    4146    # datatype search directly fot it 
    4247    # obs station, informationnal only 
     48    # statusfile 
    4349    # status Config::IniFile object to store extraction info 
    4450     
    45     bless($infos, $class); 
     51    $or->{status} ||= new Config::IniFiles( 
     52        -file => (($or->{statusfile} && -f $or->{statusfile}) ? $or->{statusfile} : undef), 
     53        # -default => '.', # Is this a good idea 
     54    ); 
     55     
     56    bless($or, $class); 
    4657} 
    4758 
     
    5465sub save_status { 
    5566    my ($self) = @_; 
     67    $self->{statusfile} or return; 
    5668    $self->{status}->AddSection('.'); 
    5769    $self->{status}->SetSectionComment('.', 
     
    6173    ); 
    6274 
    63     $self->{status}->WriteConfig("$self->{dir}/obsdata.ini"); 
     75    $self->{status}->WriteConfig($self->{statusfile}); 
    6476} 
    6577 
     
    8395 
    8496sub new { 
    85     my ($class, $obsdata, $dir, %info) = @_; 
    86  
    87     $obsdata or die "Error #1de8d015, please insult programmer"; 
    88  
    89     $dir && -d $dir or return undef; 
    90  
    91     my $OR = { 
    92         obsdata => $obsdata, 
    93         status => new Config::IniFiles( 
    94             -file => (-f $dir . "/obsdata.ini" ? ($dir . "/obsdata.ini") : undef), 
    95             # -default => '.', # Is this a good idea 
    96         ), 
    97         dir => $dir, 
    98         do_if_change => {}, 
    99     }; 
    100      
    101     foreach my $inf (qw(obs datatype)) { 
    102         $OR->{$inf} = $info{$inf}; 
    103     } 
    104  
    105     bless($OR, $class); 
     97    my ($class, $infos, %param) = @_; 
     98 
     99    my $or = ObsData::Repository->new($infos, %param); 
     100    # dir directory to parse 
     101    # patern glob() over file 
     102    $or->{dir} or die "No dir given"; 
     103 
     104    bless($or, $class); 
     105} 
     106 
     107sub findfile { 
     108    my ($self) = @_; 
     109    my @files; 
     110 
     111    if (!-d $self->{dir}) { 
     112        $self->loging(3, 
     113            "directory %s does not exists", 
     114            $self->{dir}, 
     115        ); 
     116        return; 
     117    } 
     118 
     119    my $patern = $self->{patern} || '*'; 
     120    foreach my $f (glob("$self->{dir}/$patern")) { 
     121 
     122        -f $f or next; # skip no regular files 
     123         
     124        my $bf = $f; 
     125        $bf =~ s!^\Q$self->{dir}\E/*!!; 
     126        push(@files, $bf); 
     127    } 
     128    @files 
    106129} 
    107130 
     
    109132    my ($self) = @_; 
    110133    $self->loging(0, "%s() start for %s", (caller(0))[3], $self->{dir}); 
    111     if(opendir(my $dirhandle, $self->{dir})) { 
    112         while (my $file = readdir($dirhandle)) { 
    113             if ($file eq '..' || $file eq '.' ) { # Hope that's ok for everybody 
    114                 next; 
    115             } 
    116  
    117             if (!-f "$self->{dir}/$file") { 
    118                 next; # Not regular file, link are follow (stat) 
    119             } 
    120  
    121             if ($file eq 'obsdata.ini') { 
    122                 next; # skipping status file 
    123             } 
    124  
    125             my $archive = ObsData::Repository::dir::archive->new( 
    126                 $self, 
    127                 $file 
    128             ); 
    129             $archive->parse_archive; 
    130             # $self->install_file($file, $destfile); 
    131         } 
    132         close($dirhandle); 
    133     } else { 
    134         $self->loging(5, "can't open directory %s set for %s", $self->{dir}, $self->{obs}); 
     134 
     135    foreach my $file ($self->findfile) { 
     136        my $orda = ObsData::Repository::dir::archive->new( 
     137            $self, 
     138            archivefile => $file, 
     139        ); 
     140        $orda->parse_archive; 
    135141    } 
    136142} 
     
    141147 
    142148sub new { 
    143     my ($class, $parent, $archivefile) = @_; 
    144      
    145     my $ORa = { %$parent }; 
    146  
    147     $ORa->{archivefile} = $archivefile; 
    148     $ORa->{changes} = {}; 
    149      
    150     bless($ORa, $class); 
     149    my ($class, $infos, %param) = @_; 
     150 
     151    my $or = ObsData::Repository->new($infos, %param); 
     152    # dir directory to parse 
     153    # patern glob() over file 
     154    $or->{dir} or die "No dir given"; 
     155    $or->{archivefile} or die "No archivefile given"; 
     156 
     157    bless($or, $class); 
    151158} 
    152159 
     
    260267        my $data = ObsData::Repository::dir::archive::data->new( 
    261268            $self, 
    262             $datafile, 
     269            datafile => $datafile, 
    263270        ); 
    264271        $data->dispatch; 
     
    271278 
    272279sub new { 
    273     my ($class, $parent, $datafile) = @_; 
    274      
    275     my $ORad = { %$parent }; 
    276  
    277     $ORad->{datafile} = $datafile; 
    278      
    279     bless($ORad, $class); 
     280    my ($class, $infos, %param) = @_; 
     281 
     282    my $or = ObsData::Repository->new($infos, %param); 
     283    # dir directory to parse 
     284    # patern glob() over file 
     285    $or->{datafile} or die "No datafile given"; 
     286 
     287    bless($or, $class); 
    280288} 
    281289 
  • trunk/soft/ObsData/t/OR-02.t

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r85 r87  
    33use Test::More tests => 4; 
    44use File::Temp qw(tempdir); 
    5 use ObsData::Repository; 
    65 
    76use_ok('ObsData'); 
     
    98 
    109my $o = ObsData->new('testdata/obsdata-conftest', logfile => "testdata/obsdata.log"); 
    11 my $or = ObsData::Repository::dir->new( 
    12     $o, 
    13     "testdata", 
     10my $or = ObsData::Repository->new( 
     11    {  
     12        obsdata => $o, 
     13    } 
    1414); 
    1515 
Note: See TracChangeset for help on using the changeset viewer.