Changeset 84


Ignore:
Timestamp:
12/01/05 00:11:51 (19 years ago)
Author:
thauvin
Message:
  • rename variable, use a more configurable structure to see if a file need to be read
Location:
trunk/soft/ObsData
Files:
2 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.26 to 1.27
    r83 r84  
    6868        close($self->{loghandle}); 
    6969        $self->{loghandle} = undef; 
    70     } 
    71 } 
    72  
    73 sub set_status { 
    74     my ($self, %settings) = @_; 
    75     my %status_default = ( 
    76         archive_new => 1, 
    77         archive_time => 0, 
    78         archive_size => 0, 
    79  
    80         data_new => 1, 
    81         data_configmtime => 0, 
    82  
    83     ); 
    84      
    85     foreach (keys %status_default) { 
    86         $self->{status_make_work}{$_} = defined($settings{$_}) ? $settings{$_} : $status_default{$_}; 
    8770    } 
    8871} 
  • trunk/soft/ObsData/ObsData/Repository.pm

    • Property cvs2svn:cvs-rev changed from 1.22 to 1.23
    r83 r84  
    1212our $CVSID = q$Id$; 
    1313our $CVSREV = (q$Revision$ =~ /^Revision: (.*) $/)[0]; 
     14 
     15my %default_do_if_change = ( 
     16    archive_new         => 1, 
     17    archive_time        => 0, 
     18    archive_size        => 0, 
     19    archive_configmtime => 0, 
     20 
     21    data_new            => 1, 
     22    data_configmtime    => 0, 
     23); 
     24 
     25sub default_do_if_change { 
     26    return %default_do_if_change; 
     27} 
    1428 
    1529=head1 METHODS 
     
    3347        ), 
    3448        dir => $dir, 
     49        do_if_change => {}, 
    3550    }; 
    3651     
     
    6580} 
    6681 
     82sub set_do_if_change { 
     83    my ($self, %settings) = @_; 
     84     
     85    foreach (keys %default_do_if_change) { 
     86        $self->{do_if_change}{$_} = 
     87            defined($settings{$_}) ? $settings{$_} : $default_do_if_change{$_}; 
     88    } 
     89} 
    6790 
    6891sub parse_files { 
     
    106129 
    107130    $ORa->{archivefile} = $archivefile; 
    108      
    109     $ORa->{statusinfo} = {}; 
     131    $ORa->{changes} = {}; 
    110132     
    111133    bless($ORa, $class); 
     
    118140#} 
    119141 
    120 sub status { 
     142sub see_archive_change { 
    121143    my ($self) = @_; 
    122144 
     
    124146 
    125147    if ($self->{status}->SectionExists($self->{archivefile})) { 
    126     } else { 
    127         $self->{statusinfo}{archive_new} = 
    128             $self->loging(0, "%s is new files", $self->{archivefile}); 
    129     } 
    130 } 
    131  
    132 # TODO Define return code for this function, storing result somewhere to 
    133 # pass to child. 
    134 sub file_need_parse { 
    135     my ($self) = @_; 
    136  
    137     my @filestats = stat("$self->{dir}/$self->{archivefile}"); 
    138              
    139     if ($self->{status}->SectionExists($self->{archivefile})) { 
    140         $self->loging(0, "File %s found in status, checking...", $self->{archivefile}); 
    141         my ($mtimeok, $sizeok, $conftimeok) = (0, 0, 0); 
    142         my $olddatatype = $self->{status}->val($self->{archivefile}, 'datatype'); 
    143         my $oldmtime = $self->{status}->val($self->{archivefile}, 'mtime'); 
    144         my $oldsize = $self->{status}->val($self->{archivefile}, 'size'); 
    145         my $oldconftime = $self->{status}->val($self->{archivefile}, 'configtime'); 
    146         if ($oldmtime) { 
     148        if (my $oldmtime = $self->{status}->val($self->{archivefile}, 'mtime')) { 
    147149            if ($oldmtime == $filestats[9]) { 
    148                 $mtimeok = 1; 
     150 
    149151            } elsif ($oldmtime > $filestats[9]) { 
    150152                $self->loging(3,  
     
    154156                ); 
    155157            } else { 
    156                 # Nothing special to say, file is simply more recent     
    157             } 
    158         } 
    159         if (defined($oldsize)) { 
    160             if ($oldsize == $filestats[7]) { 
    161                 $sizeok = 1; 
    162             } else { 
    163                 # Nothing to say, size differ 
    164             } 
    165         } 
    166         
    167         # Comparing time of the conf with time of conf during last process 
    168         # if config has changed, maybe something better will happend 
    169         if (defined($oldconftime) && $self->{obsdata}->config_mtime <= $oldconftime) { 
    170             $conftimeok = 1; 
    171         } 
    172          
    173         #if ($olddatatype) { 
    174         if (defined($oldmtime) && defined($oldsize)) { 
    175             if (! ($sizeok && $mtimeok)) { 
    176                 $self->loging(3, "File %s allready processed but has changed:%s%s", 
     158                $self->{changes}{archive_time} = $self->loging(0,  
     159                    "%s is more recent %d => %d", 
    177160                    $self->{archivefile}, 
    178                     ($sizeok ? "" : sprintf(" size %d => %d", $oldsize, $filestats[7])), 
    179                     ($mtimeok ? "" : sprintf(" mtime %d => %d", $oldmtime, $filestats[9])), 
     161                    $oldmtime, 
     162                    $filestats[9], 
    180163                ); 
    181             } elsif (!$conftimeok) { 
    182                 $self->loging(0, "config has changed since last process: %s vs %d, retrying it", 
    183                     $oldconftime || '(none)', 
    184                     $self->{obsdata}->config_mtime 
     164            } 
     165        } 
     166 
     167        if (defined(my $oldsize = $self->{status}->val($self->{archivefile}, 'size'))) { 
     168            if ($oldsize != $filestats[7]) { 
     169                $self->{changes}{archive_size} = $self->loging(0,  
     170                    "%s size differ %d => %d", 
     171                    $self->{archivefile}, 
     172                    $oldsize, 
     173                    $filestats[7], 
    185174                ); 
    186                 return 1; 
    187             } 
    188             return 0; 
    189         } else { 
    190             if ($sizeok && $mtimeok) { 
    191                 $self->loging(0,  
    192                     "%s was not take into acount, no change skipping", 
    193                     $self->{archivefile} 
     175            } 
     176        } 
     177 
     178        if (defined(my $oldconftime = $self->{status}->val($self->{archivefile}, 'configtime'))) { 
     179            if ($self->{obsdata}->config_mtime > $oldconftime) { 
     180                $self->{changes}{archive_configmtime} = $self->loging(0,  
     181                    "%s config has changed since last processing %d => %d", 
     182                    $self->{archivefile}, 
     183                    $oldconftime, 
     184                    $self->{obsdata}->config_mtime, 
    194185                ); 
    195                 return 0; 
    196             } else { 
    197                 $self->loging(0,  
    198                     "%s file has not been processed, but change, retrying", 
    199                     $self->{archivefile} 
    200                 ); 
    201                 return 1; 
    202             } 
    203         } 
    204          
     186            } 
     187        } 
     188             
    205189    } else { 
    206         $self->loging(0, "%s is new files", $self->{archivefile}); 
    207         $self->update_status; 
    208         return 1; 
    209     } 
     190        $self->{changes}{archive_new} = 
     191            $self->loging(0, "%s is new file", $self->{archivefile}); 
     192    } 
     193} 
     194 
     195# TODO Define return code for this function, storing result somewhere to 
     196# pass to child. 
     197sub file_need_parse { 
     198    my ($self) = @_; 
     199 
     200    $self->see_archive_change; 
     201 
     202    my $need = 0; 
     203    foreach (keys %{$self->{changes}}) { 
     204        if (defined($self->{changes}{$_}) && $self->{do_if_change}{$_}) { 
     205            $self->loging(0, $self->{changes}{$_}); 
     206            $need++; 
     207        } 
     208    } 
     209     
     210    $need 
    210211} 
    211212 
Note: See TracChangeset for help on using the changeset viewer.