Changeset 274 for obsdata/trunk


Ignore:
Timestamp:
10/27/06 00:30:40 (18 years ago)
Author:
nanardon
Message:
  • perltidyfication (beautify indentation)
Location:
obsdata/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • obsdata/trunk/ObsData.pm

    r273 r274  
    1212use File::Basename; 
    1313 
    14 my @loglevel = ( 
    15     'DEBUG', 
    16     'INFO', 
    17     'RESULT', 
    18     'WARNING', 
    19     'ERROR', 
    20     'FATAL', 
    21 ); 
     14my @loglevel = ( 'DEBUG', 'INFO', 'RESULT', 'WARNING', 'ERROR', 'FATAL', ); 
    2215 
    2316our $VERSION = "0.3.1"; 
    24 our $CVSID = q$Id$; 
    25 our $CVSREV = (q$Revision$ =~ /^Revision: (.*) $/)[0]; 
     17our $CVSID   = q$Id$; 
     18our $CVSREV  = ( q$Revision$ =~ /^Revision: (.*) $/ )[0]; 
    2619 
    2720=head1 NAME 
     
    4437 
    4538sub new { 
    46     my ($class, $configfile, %options) = @_; 
     39    my ( $class, $configfile, %options ) = @_; 
    4740    my $obsdata = { 
    4841        config => new Config::IniFiles( 
    49             -file => $configfile, 
    50             -default => 'global', 
     42            -file          => $configfile, 
     43            -default       => 'global', 
    5144            -allowcontinue => 1 
    5245        ), 
    53         verbose => defined($options{verbose}) ? $options{verbose} : 1, 
    54         logcallback => $options{logcallback}, 
    55         logfile => $options{logfile}, 
    56         dry_run => $options{dry_run}, 
     46        verbose => defined( $options{verbose} ) ? $options{verbose} : 1, 
     47        logcallback          => $options{logcallback}, 
     48        logfile              => $options{logfile}, 
     49        dry_run              => $options{dry_run}, 
    5750        interactive_callback => $options{interactive_callback}, 
    58         processed_lists => [], 
     51        processed_lists      => [], 
    5952    }; 
    6053 
    61     if (!($configfile && -f $configfile && -r _)) { 
     54    if ( !( $configfile && -f $configfile && -r _ ) ) { 
    6255        return undef; 
    6356    } 
     
    6659 
    6760    # directory where to search plugins 
    68     @{$obsdata->{plugindir}} = grep { $_ && -d $_ } ( 
     61    @{ $obsdata->{plugindir} } = grep { $_ && -d $_ } ( 
    6962        $options{plugindir}, 
    7063        dirname($0), 
    71         split(/\s+/, $obsdata->{config}->val('global', 'plugindir') || ''), 
     64        split( /\s+/, $obsdata->{config}->val( 'global', 'plugindir' ) || '' ), 
    7265    ); 
    7366 
    74     $obsdata->{logfile} ||= $obsdata->{config}->val('global', 'logfile') || 'obsdata.log'; 
    75  
    76     bless($obsdata, $class); 
     67    $obsdata->{logfile} ||= $obsdata->{config}->val( 'global', 'logfile' ) 
     68      || 'obsdata.log'; 
     69 
     70    bless( $obsdata, $class ); 
    7771} 
    7872 
     
    8074    my ($self) = @_; 
    8175 
    82     $self->logging(0, "END process: %s (%s)", 
    83         $VERSION, 
    84         $CVSID, 
    85     ); 
    86  
    87     if ($self->{loghandle}) { 
    88         close($self->{loghandle}); 
     76    $self->logging( 0, "END process: %s (%s)", $VERSION, $CVSID, ); 
     77 
     78    if ( $self->{loghandle} ) { 
     79        close( $self->{loghandle} ); 
    8980        $self->{loghandle} = undef; 
    9081    } 
     
    10091    my ($self) = @_; 
    10192 
    102     if (!open($self->{loghandle}, ">> $self->{logfile}")) { 
     93    if ( !open( $self->{loghandle}, ">> $self->{logfile}" ) ) { 
    10394        $self->{loghandle} = undef; 
    104         $self->logging(5, "Can't open log file %s, exiting", "$self->{logfile}"); 
     95        $self->logging( 5, "Can't open log file %s, exiting", 
     96            "$self->{logfile}" ); 
    10597        return 0; 
    10698    } 
    10799 
    108     $self->logging(0, "BEGIN process: %s (%s)", 
    109         $VERSION, 
    110         $CVSID, 
    111     ); 
     100    $self->logging( 0, "BEGIN process: %s (%s)", $VERSION, $CVSID, ); 
    112101 
    113102    my $path = `pwd`; 
    114103    chomp($path); 
    115     $self->logging(0, "Using config file `%s' (%s)", 
    116         $self->{config}->GetFileName(), 
    117         $path, 
     104    $self->logging( 
     105        0, 
     106        "Using config file `%s' (%s)", 
     107        $self->{config}->GetFileName(), $path, 
    118108    ); 
    119      
     109 
    120110    $self->load_plugins() or return 0; 
    121      
     111 
    122112    return 1; 
    123113} 
     
    131121sub load_plugins { 
    132122    my ($self) = @_; 
    133      
    134     $self->logging(0, 
     123 
     124    $self->logging( 
     125        0, 
    135126        "Plugin will be searched in: %s", 
    136         join(', ', @{$self->{plugindir}}), 
     127        join( ', ', @{ $self->{plugindir} } ), 
    137128    ); 
    138          
    139     foreach my $datatype ($self->list_datatype()) { 
     129 
     130    foreach my $datatype ( $self->list_datatype() ) { 
    140131        foreach my $plugin (qw/match_plugin/) { 
    141             my ($plugfile, @plugarg) =  
    142                 split(/\s+/, $self->getvalue($datatype, $plugin) ||''); 
    143             $plugfile or next; # if no plugin, skipping 
     132            my ( $plugfile, @plugarg ) = 
     133              split( /\s+/, $self->getvalue( $datatype, $plugin ) || '' ); 
     134            $plugfile or next;    # if no plugin, skipping 
    144135            my ($plugfilename) = grep { -f $_ } 
    145                 map { "$_/$plugfile" } @{$self->{plugindir}}; 
    146             if (!$plugfilename) { 
    147                 $self->logging(5, 
    148                     "Cannot find plugin %s (%s) for %s datatype", 
    149                     $plugfile, 
    150                     $plugin, 
    151                     $datatype, 
    152                 ); 
     136              map { "$_/$plugfile" } @{ $self->{plugindir} }; 
     137            if ( !$plugfilename ) { 
     138                $self->logging( 5, "Cannot find plugin %s (%s) for %s datatype", 
     139                    $plugfile, $plugin, $datatype, ); 
    153140                return 0; 
    154141            } 
    155142            my $sub = do $plugfilename; 
    156143            if ($@) { 
    157                 $self->logging(4, 
     144                $self->logging( 4, 
    158145                    "Cannot load plugin %s for %s: %s, exiting !", 
    159                     $plugin, 
    160                     $datatype, 
    161                     $@, 
     146                    $plugin, $datatype, $@, ); 
     147                return 0; 
     148            } 
     149            if ( $sub && ref $sub eq 'CODE' ) { 
     150                $self->{plugin}{$datatype}{$plugin} = { 
     151                    code => $sub, 
     152                    arg  => \@plugarg, 
     153                }; 
     154                $self->logging( 0, "loading plugin %s for %s (%s)", 
     155                    $plugin, $datatype, $sub, ); 
     156            } 
     157            else { 
     158                $self->logging( 
     159                    4, "Cannot load plugin %s for %s (is %s)", 
     160                    $plugin, $datatype, $sub ? ref $sub : 'undef or empty', 
    162161                ); 
    163                 return 0; 
    164             } 
    165             if ($sub && ref $sub eq 'CODE') { 
    166                 $self->{plugin}{$datatype}{$plugin} = { 
    167                    code => $sub, 
    168                    arg => \@plugarg, 
    169                 }; 
    170                 $self->logging(0, 
    171                     "loading plugin %s for %s (%s)", 
    172                     $plugin, 
    173                     $datatype, 
    174                     $sub, 
    175                 ); 
    176             } else { 
    177                 $self->logging(4, 
    178                     "Cannot load plugin %s for %s (is %s)", 
    179                     $plugin, 
    180                     $datatype, 
    181                     $sub ? ref $sub : 'undef or empty', 
    182                 ); 
    183162            } 
    184163        } 
     
    194173 
    195174sub get_sub_plugin { 
    196     my ($self, $datatype, $plugintype) = @_; 
    197     if (exists($self->{plugin}{$datatype}{$plugintype})) { 
     175    my ( $self, $datatype, $plugintype ) = @_; 
     176    if ( exists( $self->{plugin}{$datatype}{$plugintype} ) ) { 
    198177        my $ref = $self->{plugin}{$datatype}{$plugintype}; 
    199         return($ref->{code}, @{$ref->{arg}}); 
    200     } else { 
     178        return ( $ref->{code}, @{ $ref->{arg} } ); 
     179    } 
     180    else { 
    201181        return undef; 
    202182    } 
     
    213193 
    214194sub logging { 
    215     my ($self, $level, $fmt, @val) = @_; 
    216     my $msg = sprintf($fmt, @val); 
     195    my ( $self, $level, $fmt, @val ) = @_; 
     196    my $msg = sprintf( $fmt, @val ); 
    217197    my $logh = $self->{loghandle}; 
    218     if ($self->{logcallback}) { 
    219         $self->{logcallback}->($level, $msg); 
    220     } 
    221     if($level >= 0 && $level >= $self->{verbose}) { 
     198    if ( $self->{logcallback} ) { 
     199        $self->{logcallback}->( $level, $msg ); 
     200    } 
     201    if ( $level >= 0 && $level >= $self->{verbose} ) { 
    222202        if ($logh) { 
    223             printf $logh  
    224                 "%-9s %s %s\n",  
    225                 sprintf("[%s]", $self->loglevel($level)), 
    226                 strftime("%b %d %H:%M:%S %Y", gmtime), 
    227                 $msg; 
    228         } 
    229     } 
    230     $msg 
     203            printf $logh "%-9s %s %s\n", 
     204              sprintf( "[%s]", $self->loglevel($level) ), 
     205              strftime( "%b %d %H:%M:%S %Y", gmtime ), $msg; 
     206        } 
     207    } 
     208    $msg; 
    231209} 
    232210 
     
    240218    my $l = pop(@_); 
    241219    defined($l) or $l = pop(@_); 
    242     return $loglevel[ $l ] || "?????"; 
     220    return $loglevel[$l] || "?????"; 
    243221} 
    244222 
     
    254232    my ($self) = @_; 
    255233    my $result = 1; 
    256     foreach my $g ($self->{config}->GroupMembers('Obs')) { 
     234    foreach my $g ( $self->{config}->GroupMembers('Obs') ) { 
    257235        my ($obs) = $g =~ /\S+\s+(.*)/; 
    258         if (!$self->{config}->SectionExists($obs)) { 
     236        if ( !$self->{config}->SectionExists($obs) ) { 
    259237            print STDERR "E: '$obs' is listed as Obs but it does not exists\n"; 
    260238            next; 
    261239        } 
    262         foreach my $param ($self->{config}->Parameters($obs)) { 
    263         } 
    264         foreach my $datatype ($self->list_datatype) { 
     240        foreach my $param ( $self->{config}->Parameters($obs) ) { 
     241        } 
     242        foreach my $datatype ( $self->list_datatype ) { 
    265243            foreach my $var (qw(match match_archive)) { 
    266                 my $regexp = $self->getvalue($datatype, $var) or next; # next ? are we sure ? 
    267                 eval { qr/$regexp/ }; # Many thanks Rafael 
     244                my $regexp = $self->getvalue( $datatype, $var ) 
     245                  or next;    # next ? are we sure ? 
     246                eval { qr/$regexp/ };    # Many thanks Rafael 
    268247                if ($@) { 
    269                     $self->logging(4, "error in regexp for %s: '%s': %s", 
    270                         $datatype, 
    271                         $regexp, 
    272                         $@, 
    273                     ); 
     248                    $self->logging( 4, "error in regexp for %s: '%s': %s", 
     249                        $datatype, $regexp, $@, ); 
    274250                    $result = 0; 
     251 
    275252                    # TODO set this reg unavalable 
    276253                } 
     
    278255        } 
    279256    } 
    280     return($result); 
     257    return ($result); 
    281258} 
    282259 
     
    288265 
    289266sub getvalue { 
    290     my ($self, $section, $var, $default) = @_; 
    291     $self->{config}->val($section, $var, $default); 
     267    my ( $self, $section, $var, $default ) = @_; 
     268    $self->{config}->val( $section, $var, $default ); 
    292269} 
    293270 
     
    300277sub config_mtime { 
    301278    my ($self) = @_; 
    302     return $self->{configmtime} ||= (stat($self->{config}->GetFileName))[9]; 
     279    return $self->{configmtime} ||= ( stat( $self->{config}->GetFileName ) )[9]; 
    303280} 
    304281 
     
    312289    my ($self) = @_; 
    313290    grep { $self->{config}->SectionExists($_) } 
    314         map { s/^\S+\s+//; $_ } 
    315         $self->{config}->GroupMembers('Obs'); 
     291      map { s/^\S+\s+//; $_ } $self->{config}->GroupMembers('Obs'); 
    316292} 
    317293 
     
    323299 
    324300sub is_obs { 
    325     my ($self, $obs) = @_; 
    326     scalar(grep { $_ eq "Obs $obs" } $self->{config}->GroupMembers('Obs')); 
     301    my ( $self, $obs ) = @_; 
     302    scalar( grep { $_ eq "Obs $obs" } $self->{config}->GroupMembers('Obs') ); 
    327303} 
    328304 
     
    334310 
    335311sub list_obsdatadir { 
    336     my ($self, $obs) = @_; 
     312    my ( $self, $obs ) = @_; 
    337313    $self->is_obs($obs) or return undef; 
    338     map { m,^datadir/(.*),; ( ($1 || "") => $self->{config}->val($obs, $_) ) } 
    339         grep { m,^datadir/, || $_ eq 'datadir' } 
    340         $self->{config}->Parameters($obs) 
     314    map { 
     315        m,^datadir/(.*),; 
     316        ( ( $1 || "" ) => $self->{config}->val( $obs, $_ ) ) 
     317      } 
     318      grep { m,^datadir/, || $_ eq 'datadir' } 
     319      $self->{config}->Parameters($obs); 
    341320} 
    342321 
     
    348327 
    349328sub list_typedatadir { 
    350     my ($self, $type) = @_; 
     329    my ( $self, $type ) = @_; 
    351330    my %dirs; 
    352     foreach my $obs ($self->list_obs) { 
    353         $dirs{$_} = 1 foreach(grep { $_ } $self->get_datadir($obs, $type)); 
    354     } 
    355     keys %dirs;  
    356          
     331    foreach my $obs ( $self->list_obs ) { 
     332        $dirs{$_} = 1 foreach ( grep { $_ } $self->get_datadir( $obs, $type ) ); 
     333    } 
     334    keys %dirs; 
     335 
    357336} 
    358337 
     
    364343 
    365344sub get_datadir { 
    366     my ($self, $obs, $type) = @_; 
     345    my ( $self, $obs, $type ) = @_; 
    367346    $self->is_obs($obs) or return undef; 
    368     grep { defined($_) } ($self->getvalue($obs, "datadir/$type"), $self->getvalue($obs, "datadir")); 
     347    grep { defined($_) } ( 
     348        $self->getvalue( $obs, "datadir/$type" ), 
     349        $self->getvalue( $obs, "datadir" ) 
     350    ); 
    369351} 
    370352 
     
    378360    my ($self) = @_; 
    379361    grep { $_ ne 'global' } 
    380     grep { $_ !~ /^Obs\s+/ } 
    381     grep { !$self->is_obs($_) } $self->{config}->Sections; 
     362      grep { $_ !~ /^Obs\s+/ } 
     363      grep { !$self->is_obs($_) } $self->{config}->Sections; 
    382364} 
    383365 
     
    391373 
    392374sub get_obs_data_handle { 
    393     my ($self, $obs, $datatype) = @_; 
    394  
    395     my $dir = $self->getvalue($obs, ($datatype ? "datadir/$datatype" : "datadir")); 
    396     if (!$dir) { 
    397         $self->logging(4, 
    398             "Can't find data directory for %s, type: %s", 
    399             $obs, $datatype || '(none)' 
    400         ); 
     375    my ( $self, $obs, $datatype ) = @_; 
     376 
     377    my $dir = 
     378      $self->getvalue( $obs, ( $datatype ? "datadir/$datatype" : "datadir" ) ); 
     379    if ( !$dir ) { 
     380        $self->logging( 4, "Can't find data directory for %s, type: %s", 
     381            $obs, $datatype || '(none)' ); 
    401382        return undef; 
    402383    } 
    403384    my $or = ObsData::Repository::dir->new( 
    404385        { 
    405             obsdata => $self, 
    406             dir => $dir, 
    407             obs => $obs, 
     386            obsdata  => $self, 
     387            dir      => $dir, 
     388            obs      => $obs, 
    408389            datatype => $datatype, 
    409390            dry_run => $self->{dry_run}, # FIXME does this have a better place ? 
    410             patern => $self->getvalue( 
    411                 $obs, 
    412                 ($datatype ? "searchfiles/$datatype" : "searchfiles") 
     391            patern  => $self->getvalue( 
     392                $obs, ( $datatype ? "searchfiles/$datatype" : "searchfiles" ) 
    413393            ), 
    414394            statusfile => $self->getvalue( 
    415                 $obs,  
    416                 ($datatype ? "index/$datatype" : "index"), 
     395                $obs, ( $datatype ? "index/$datatype" : "index" ), 
    417396                "$dir/obsdata.ini" 
    418397            ), 
    419398        } 
    420399    ); 
    421     if (!defined($or)) { 
    422         $self->logging(4, "Can't parse %s, check directory exists", $dir); 
     400    if ( !defined($or) ) { 
     401        $self->logging( 4, "Can't parse %s, check directory exists", $dir ); 
    423402        return undef; 
    424403    } 
    425      
    426     return($or); 
     404 
     405    return ($or); 
    427406} 
    428407 
     
    434413 
    435414sub process_obs { 
    436     my ($self, $obs) = @_; 
     415    my ( $self, $obs ) = @_; 
    437416    my %datadir = $self->list_obsdatadir($obs); 
    438     $self->logging(0, "Starting %s() for %s", (caller(0))[3], $obs); 
    439      
    440     foreach my $datatype (keys %datadir) { 
    441         my $or = $self->get_obs_data_handle($obs, $datatype); 
     417    $self->logging( 0, "Starting %s() for %s", ( caller(0) )[3], $obs ); 
     418 
     419    foreach my $datatype ( keys %datadir ) { 
     420        my $or = $self->get_obs_data_handle( $obs, $datatype ); 
    442421        $or or next; 
    443422        $or->process; 
     
    446425 
    447426sub processed { 
    448     my ($self, $obs, $archive, $datafile, $datatype, $dest) = @_; 
    449     push(@{$self->{processed_lists}}, 
     427    my ( $self, $obs, $archive, $datafile, $datatype, $dest ) = @_; 
     428    push( 
     429        @{ $self->{processed_lists} }, 
    450430        { 
    451             obs => $obs, 
    452             archive => $archive, 
     431            obs      => $obs, 
     432            archive  => $archive, 
    453433            datafile => $datafile, 
    454434            datatype => $datatype, 
     
    456436        } 
    457437    ); 
    458     $self->logging( 
    459         2, "Extraction of %s/%s done as %s", 
    460         $archive, 
    461         $datafile, 
    462         $dest, 
    463     ) if ($dest); 
     438    $self->logging( 2, "Extraction of %s/%s done as %s", 
     439        $archive, $datafile, $dest, ) 
     440      if ($dest); 
    464441} 
    465442 
     
    467444    my ($self) = @_; 
    468445    my $result = { 
    469         all => [], 
     446        all   => [], 
    470447        users => {}, 
    471448    }; 
    472449 
    473     foreach my $entry (@{$self->{processed_lists}}) { 
     450    foreach my $entry ( @{ $self->{processed_lists} } ) { 
    474451        my %people = map { $_ => 1 } grep { $_ } ( 
    475             ($entry->{datatype} ? 
    476                 split(/\s*,\s*/, $self->getvalue($entry->{datatype}, 'reportto') || "") : 
    477                 split(/\s*,\s*/, $self->getvalue('global', 'nodestreportto') || "") 
     452            ( 
     453                $entry->{datatype} 
     454                ? split( /\s*,\s*/, 
     455                    $self->getvalue( $entry->{datatype}, 'reportto' ) || "" ) 
     456                : split( 
     457                    /\s*,\s*/, 
     458                    $self->getvalue( 'global', 'nodestreportto' ) || "" 
     459                ) 
    478460            ), 
    479             split(/\s*,\s*/, $self->getvalue($entry->{obs}, 'reportto') || ""), 
    480             split(/\s*,\s*/, $self->getvalue('global', 'allreportto') || "") 
     461            split( 
     462                /\s*,\s*/, $self->getvalue( $entry->{obs}, 'reportto' ) || "" 
     463            ), 
     464            split( 
     465                /\s*,\s*/, $self->getvalue( 'global', 'allreportto' ) || "" 
     466            ) 
    481467        ); 
    482468        keys %people or next; 
    483         foreach my $p (keys %people) { 
    484             push(@{$result->{users}{$p}}, $entry); 
    485         } 
    486     } 
    487  
    488     foreach my $p (keys(%{$result->{users} || {}})) { 
     469        foreach my $p ( keys %people ) { 
     470            push( @{ $result->{users}{$p} }, $entry ); 
     471        } 
     472    } 
     473 
     474    foreach my $p ( keys( %{ $result->{users} || {} } ) ) { 
    489475        my %obs_entries = (); 
    490         foreach (@{$result->{users}{$p}}) { 
    491             push(@{$obs_entries{$_->{obs}}},  $_); 
    492         } 
    493  
    494         foreach my $obs (keys %obs_entries) { 
     476        foreach ( @{ $result->{users}{$p} } ) { 
     477            push( @{ $obs_entries{ $_->{obs} } }, $_ ); 
     478        } 
     479 
     480        foreach my $obs ( keys %obs_entries ) { 
    495481            my %datatype_entries = (); 
    496             foreach (@{$obs_entries{$obs}}) { 
    497                 push(@{$datatype_entries{$_->{datatype} || '!'}}, $_); 
     482            foreach ( @{ $obs_entries{$obs} } ) { 
     483                push( @{ $datatype_entries{ $_->{datatype} || '!' } }, $_ ); 
    498484            } 
    499485 
    500486            my %msg = ( 
    501                 Subject => 'ObsData Report: ' . $obs, 
    502                 To => $p, 
     487                Subject             => 'ObsData Report: ' . $obs, 
     488                To                  => $p, 
    503489                'X-ObsData-Version' => $VERSION, 
    504                 'Content-Type' => "TEXT/PLAIN;\n  charset=ISO-8859-1", 
     490                'Content-Type'      => "TEXT/PLAIN;\n  charset=ISO-8859-1", 
    505491                'Content-Transfer-Encoding' => 'QUOTED-PRINTABLE', 
    506492                From => 'ObsData <robot@aero.jussieu.fr>', 
    507493            ); 
    508494            my $message = ""; 
    509             foreach my $d (sort keys(%datatype_entries)) { 
    510                 if ($d eq '!') { 
     495            foreach my $d ( sort keys(%datatype_entries) ) { 
     496                if ( $d eq '!' ) { 
    511497                    $message .= "\nNot proceed:\n"; 
    512                     foreach (@{$datatype_entries{$d} || []}) { 
    513                         $message .= sprintf("  file %s from %s\n", 
    514                             $_->{datafile}, 
    515                             $_->{archive}, 
    516                         ); 
    517                     } 
    518                 } else { 
    519                     $message .= "\nDataType: $d\n"; 
    520                     foreach (@{$datatype_entries{$d} || []}) { 
    521                         $message .= sprintf("  file %s from %s => %s\n", 
    522                             $_->{datafile}, 
    523                             $_->{archive}, 
    524                             $_->{destfile}, 
    525                         ); 
     498                    foreach ( @{ $datatype_entries{$d} || [] } ) { 
     499                        $message .= sprintf( "  file %s from %s\n", 
     500                            $_->{datafile}, $_->{archive}, ); 
    526501                    } 
    527502                } 
     503                else { 
     504                    $message .= "\nDataType: $d\n"; 
     505                    foreach ( @{ $datatype_entries{$d} || [] } ) { 
     506                        $message .= sprintf( "  file %s from %s => %s\n", 
     507                            $_->{datafile}, $_->{archive}, $_->{destfile}, ); 
     508                    } 
     509                } 
    528510            } 
    529511            sendmail( 
    530512                %msg, 
    531                 smtp => 'mailhost', 
     513                smtp    => 'mailhost', 
    532514                Message => encode_qp($message), 
    533             ) or $self->log(4, "Cannot send mail to %s: %s", 
     515              ) 
     516              or $self->log( 
     517                4,        "Cannot send mail to %s: %s", 
    534518                $msg{To}, $Mail::Sendmail::error, 
    535             ); 
     519              ); 
    536520        } 
    537521    } 
     
    542526    my ($self) = @_; 
    543527    my %datastype; 
    544     foreach my $entry (@{$self->{processed_lists}}) { 
     528    foreach my $entry ( @{ $self->{processed_lists} } ) { 
    545529        $entry->{datatype} or next; 
    546         push(@{$datastype{$entry->{datatype}}}, $entry); 
    547     } 
    548  
    549     foreach my $datatype (keys %datastype) { 
    550         my $command = $self->getvalue($datatype, 'postexec'); 
    551         $self->logging(0, 'postexec for %s is %s', 
    552             $datatype, 
    553             $command ? "`$command'" : 'not set, skipping', 
     530        push( @{ $datastype{ $entry->{datatype} } }, $entry ); 
     531    } 
     532 
     533    foreach my $datatype ( keys %datastype ) { 
     534        my $command = $self->getvalue( $datatype, 'postexec' ); 
     535        $self->logging( 
     536            0, 'postexec for %s is %s', 
     537            $datatype, $command ? "`$command'" : 'not set, skipping', 
    554538        ); 
    555539        if ($command) { 
    556             if (open(my $posthandle, "| $command")) { 
    557                 foreach (@{$datastype{$datatype}}) { 
     540            if ( open( my $posthandle, "| $command" ) ) { 
     541                foreach ( @{ $datastype{$datatype} } ) { 
    558542                    print $posthandle "$_->{destfile}\n" or do { 
    559                         $self->logging(4, "cannot write to postexec handle for `%s': %s", 
    560                             $datatype, 
    561                             $!, 
    562                         ); 
     543                        $self->logging( 4, 
     544                            "cannot write to postexec handle for `%s': %s", 
     545                            $datatype, $!, ); 
    563546                        last; 
    564547                    }; 
    565548                } 
    566549                my $exitstatus = close($posthandle); 
    567                 $self->logging($exitstatus ? 0 : 4, 
     550                $self->logging( 
     551                    $exitstatus ? 0 : 4, 
    568552                    "postexec for %s exit %s", 
    569553                    $datatype, 
    570                     $exitstatus ? "correctly" : "with failure : " . ($! ? ($!) : "(??)"), 
     554                    $exitstatus 
     555                    ? "correctly" 
     556                    : "with failure : " . ( $! ? ($!) : "(??)" ), 
    571557                ); 
    572             } else { 
    573                 $self->logging(4, "Cannot exec post `%s' for `%s'", 
    574                     $command, 
    575                     $datatype, 
    576                 ); 
     558            } 
     559            else { 
     560                $self->logging( 4, "Cannot exec post `%s' for `%s'", 
     561                    $command, $datatype, ); 
    577562                next; 
    578563            } 
     
    593578 
    594579=cut 
     580 
  • obsdata/trunk/ObsData/Archive.pm

    r240 r274  
    1313 
    1414our $CVSID = q$Id$; 
    15 our $CVSREV = (q$Revision$ =~ /^Revision: (.*) $/)[0]; 
     15our $CVSREV = ( q$Revision$ =~ /^Revision: (.*) $/ )[0]; 
    1616 
    1717my $error = {}; 
     
    2020 
    2121sub register { 
    22     my ($rule, $class, $priority) = @_; 
     22    my ( $rule, $class, $priority ) = @_; 
    2323    push( 
    2424        @ObsData::Archive::dynload, 
    2525        { 
    26             rule => $rule, 
    27             class => $class, 
     26            rule     => $rule, 
     27            class    => $class, 
    2828            priority => $priority, 
    2929        } 
     
    3535    my ($module) = @_; 
    3636    eval { require $module }; 
    37     return($@ ? 0 : 1); 
     37    return ( $@ ? 0 : 1 ); 
    3838} 
    3939 
    4040sub new { 
    41     my ($class, $archive, %options) = @_; 
     41    my ( $class, $archive, %options ) = @_; 
    4242    my $beclass; 
    4343 
    44     if (!$archive) { 
     44    if ( !$archive ) { 
    4545        seterror("No archive to read"); 
    4646        return undef; 
    4747    } 
    48     if (!-r $archive) { 
     48    if ( !-r $archive ) { 
    4949        seterror("No such file or directory"); 
    5050        return undef; 
    5151    } 
    5252    my $o; 
    53      
    54     foreach (keys %options) { 
     53 
     54    foreach ( keys %options ) { 
    5555        $o->{$_} = $options{$_}; 
    5656    } 
    5757    $o->{archive} = $archive; 
    58      
     58 
    5959    for ($archive) { 
    60         foreach my $r (sort { $a->{priority} <=> $b->{priority} } @ObsData::Archive::dynload) { 
    61             if (ref($r->{rule}) eq 'CODE' ? 
    62                 $r->{rule}->($_) : 
    63                 /$r->{rule}/) { 
     60        foreach my $r ( sort { $a->{priority} <=> $b->{priority} } 
     61            @ObsData::Archive::dynload ) 
     62        { 
     63            if ( 
     64                ref( $r->{rule} ) eq 'CODE' 
     65                ? $r->{rule}->($_) 
     66                : /$r->{rule}/ 
     67              ) 
     68            { 
    6469                $beclass = $r->{class}; 
    6570                last; 
     
    6772        } 
    6873    } 
    69      
     74 
    7075    if ($beclass) { 
    7176        my $obj; 
     77 
    7278        # eval("require $class\:\:$beclass;"); 
    7379        eval("\$obj = $class\:\:$beclass->new(\$o);"); 
     
    8389 
    8490sub seterror { 
    85     my ($package, $filename, $line) = caller; 
     91    my ( $package, $filename, $line ) = caller; 
    8692    $error = { 
    87         'package' => $package, 
     93        'package'  => $package, 
    8894        'filename' => $filename, 
    89         'line' => $line, 
    90         'error' => $_[1] || $_[0], 
     95        'line'     => $line, 
     96        'error'    => $_[1] || $_[0], 
    9197    }; 
    9298} 
     
    97103 
    98104sub new { 
    99     my ($class, $o) = @_; 
    100     bless($o, $class); 
     105    my ( $class, $o ) = @_; 
     106    bless( $o, $class ); 
    101107} 
    102108 
     
    107113sub ls { 
    108114    my ($self) = @_; 
    109     seterror("ls not implement in class " . ref($self)); 
     115    seterror( "ls not implement in class " . ref($self) ); 
    110116    return; 
    111117} 
    112118 
    113119sub extract { 
    114     my ($self, $file, $dest) = @_; 
    115     seterror("extract not implement in class " . ref($self)); 
     120    my ( $self, $file, $dest ) = @_; 
     121    seterror( "extract not implement in class " . ref($self) ); 
    116122    return; 
    117123} 
     
    121127sub _tempdir { 
    122128    my ($self) = @_; 
    123     $self->{tmpdir} || $ENV{TMPDIR} 
     129    $self->{tmpdir} || $ENV{TMPDIR}; 
    124130} 
    125131 
  • obsdata/trunk/ObsData/Archive/Compressed.pm

    r164 r274  
    1212 
    1313sub new { 
    14     my ($class, $options) = @_; 
     14    my ( $class, $options ) = @_; 
    1515 
    16     if (!$options->{uncomp}) { 
    17         for ($options->{archive}) { 
     16    if ( !$options->{uncomp} ) { 
     17        for ( $options->{archive} ) { 
    1818            /\.(Z|gz)$/ and $options->{uncomp} = 'gzip -dc'; 
    19             /\.bz2$/ and $options->{uncomp} = 'bzip2 -dc'; 
     19            /\.bz2$/    and $options->{uncomp} = 'bzip2 -dc'; 
    2020        } 
    2121    } 
    22      
    23     bless($options, $class); 
     22 
     23    bless( $options, $class ); 
    2424} 
    2525 
     
    3535 
    3636sub extract { 
    37     my ($self, $file, $dest) = @_; 
     37    my ( $self, $file, $dest ) = @_; 
     38 
    3839    # the devel should specify the file he want 
    3940    # as the basic contains only 1 file... this does not matter 
    4041 
    41     my ($fh, $fname); 
    42      
     42    my ( $fh, $fname ); 
     43 
    4344    if ($dest) { 
    4445        $fname = $dest; 
    45         open($fh, '>', $dest) or do { 
     46        open( $fh, '>', $dest ) or do { 
    4647            $self->seterror("Can't uncompress archive: $!"); 
    4748            return undef; 
    4849        }; 
    49     } else { 
    50         ($fh, $fname) = tempfile( 
    51             DIR => $self->_tempdir, 
     50    } 
     51    else { 
     52        ( $fh, $fname ) = tempfile( 
     53            DIR    => $self->_tempdir, 
    5254            UNLINK => 1, 
    53         ) or do { 
     55          ) 
     56          or do { 
    5457            $self->seterror("Can't create temp file: $!"); 
    5558            return undef; 
    56         }; 
     59          }; 
    5760    } 
    5861 
    59     open(my $sourcefh, "$self->{uncomp} '$self->{archive}' 2>/dev/null |") or return undef; 
    60      
    61     if(!copy($sourcefh, $fh)) { 
     62    open( my $sourcefh, "$self->{uncomp} '$self->{archive}' 2>/dev/null |" ) 
     63      or return undef; 
     64 
     65    if ( !copy( $sourcefh, $fh ) ) { 
    6266        $self->seterror("Can't copy file to destination: $!"); 
    6367        unlink($fname); 
    6468        return undef; 
    6569    } 
    66      
     70 
    6771    close($fh); 
    68     if(!close($sourcefh)) { 
    69         $self->seterror("$self->{uncomp} exit with error" . ($! ? (" " . $!) : "")); 
     72    if ( !close($sourcefh) ) { 
     73        $self->seterror( 
     74            "$self->{uncomp} exit with error" . ( $! ? ( " " . $! ) : "" ) ); 
    7075        unlink($fname); 
    7176        return undef; 
    7277    } 
    73     $fname 
     78    $fname; 
    7479} 
    7580 
    76 ObsData::Archive::register(sub { $_[0] =~ /\.(gz|Z|bz2)$/i }, 'Compressed', 5); 
     81ObsData::Archive::register( sub { $_[0] =~ /\.(gz|Z|bz2)$/i }, 'Compressed', 
     82    5 ); 
  • obsdata/trunk/ObsData/Archive/FlatFile.pm

    r164 r274  
    1212 
    1313sub new { 
    14     my ($class, $options) = @_; 
    15     bless($options, $class); 
     14    my ( $class, $options ) = @_; 
     15    bless( $options, $class ); 
    1616} 
    1717 
     
    2727 
    2828sub extract { 
    29     my ($self, $file, $dest) = @_; 
     29    my ( $self, $file, $dest ) = @_; 
     30 
    3031    # the devel should specify the file he want 
    3132    # as the basic contains only 1 file... this does not matter 
    3233 
    33     my ($fh, $fname); 
    34      
     34    my ( $fh, $fname ); 
     35 
    3536    if ($dest) { 
    3637        $fname = $dest; 
    37         if(!open($fh, '>', $dest)) { 
     38        if ( !open( $fh, '>', $dest ) ) { 
    3839            $self->seterror($!); 
    3940            return undef; 
    4041        } 
    41     } else { 
    42         ($fh, $fname) = tempfile( 
    43             DIR => $self->_tempdir, 
     42    } 
     43    else { 
     44        ( $fh, $fname ) = tempfile( 
     45            DIR    => $self->_tempdir, 
    4446            UNLINK => 1, 
    45         ) or do { 
     47          ) 
     48          or do { 
    4649            $self->seterror("Can't create tempfile: $!"); 
    4750            return undef; 
    48         }; 
     51          }; 
    4952    } 
    50      
    51     if(!copy($self->{archive}, $fh)) { 
     53 
     54    if ( !copy( $self->{archive}, $fh ) ) { 
    5255        unlink($fname); 
    5356        $self->seterror("Cant copy the archive: $!"); 
    5457        return undef; 
    5558    } 
    56      
     59 
    5760    close($fh); 
    58     $fname 
     61    $fname; 
    5962} 
    6063 
    61 ObsData::Archive::register('.*', 'FlatFile', 10); 
     64ObsData::Archive::register( '.*', 'FlatFile', 10 ); 
  • obsdata/trunk/ObsData/Archive/Lha.pm

    r247 r274  
    1212 
    1313sub new { 
    14     my ($class, $options) = @_; 
    15     bless($options, $class); 
     14    my ( $class, $options ) = @_; 
     15    bless( $options, $class ); 
    1616} 
    1717 
     
    2222sub ls { 
    2323    my ($self) = @_; 
    24     open(my $hlha, '-|', "lha '$self->{archive}'") or do { 
     24    open( my $hlha, '-|', "lha '$self->{archive}'" ) or do { 
    2525        $self->seterror("Can't read lha/lzh file: $!"); 
    2626        return undef; 
     
    2929    <$hlha>; 
    3030    <$hlha> =~ /^-{9}/ or return; 
    31     while(<$hlha>) { 
     31    while (<$hlha>) { 
    3232        chomp; 
    3333        /^(\[\w*\]|(-|d|l|c|b)((-|r)(-|w)(-|x)){3} [^-])/ or next; 
    3434        /^.{51}(.*)$/; 
    35         push(@list, $1); 
     35        push( @list, $1 ); 
    3636    } 
    3737    close($hlha); 
     
    4040 
    4141sub extract { 
    42     my ($self, $file, $dest) = @_; 
    43      
     42    my ( $self, $file, $dest ) = @_; 
     43 
    4444    $file or return undef; 
    45      
     45 
    4646    my $dir = tempdir(); 
    4747 
    48     if (system("lha xfw=$dir '$self->{archive}' '$file'")) { 
    49          $self->seterror("Can't uncompress archive: $!"); 
    50          return undef; 
     48    if ( system("lha xfw=$dir '$self->{archive}' '$file'") ) { 
     49        $self->seterror("Can't uncompress archive: $!"); 
     50        return undef; 
    5151    } 
    52      
     52 
    5353    if ($dest) { 
    54         open(my $fh, '>', $dest) or do { 
     54        open( my $fh, '>', $dest ) or do { 
    5555            $self->seterror("Can't uncompress archive: $!"); 
    5656            return undef; 
    5757        }; 
    58         open(my $sourcefh, '<', "$dir/$file") or do { 
     58        open( my $sourcefh, '<', "$dir/$file" ) or do { 
    5959            $self->seterror("Can't open temp file for reading: $!"); 
    6060            return undef; 
    6161        }; 
    6262 
    63         if(!copy($sourcefh, $fh)) { 
     63        if ( !copy( $sourcefh, $fh ) ) { 
    6464            $self->seterror("Can't copy file to destination: $!"); 
    6565            unlink("$dir/$file"); 
     
    6969        close($sourcefh); 
    7070    } 
    71      
     71 
    7272    return $dest || "$dir/$file"; 
    7373} 
    7474 
    75 ObsData::Archive::register(sub { $_[0] =~ /\.(lzh|lha)$/i }, 'Lha', 0); 
     75ObsData::Archive::register( sub { $_[0] =~ /\.(lzh|lha)$/i }, 'Lha', 0 ); 
  • obsdata/trunk/ObsData/Archive/Rar.pm

    r247 r274  
    1212 
    1313sub new { 
    14     my ($class, $options) = @_; 
    15     bless($options, $class); 
     14    my ( $class, $options ) = @_; 
     15    bless( $options, $class ); 
    1616} 
    1717 
     
    2222sub ls { 
    2323    my ($self) = @_; 
    24     open(my $hrar, '-|', "unrar lb '$self->{archive}'") or do { 
     24    open( my $hrar, '-|', "unrar lb '$self->{archive}'" ) or do { 
    2525        $self->seterror("Can't read rar file: $!"); 
    2626        return undef; 
    2727    }; 
    2828    my @list; 
    29     while(<$hrar>) { 
     29    while (<$hrar>) { 
    3030        chomp; 
    31         push(@list, $_); 
     31        push( @list, $_ ); 
    3232    } 
    3333    close($hrar); 
     
    3636 
    3737sub extract { 
    38     my ($self, $file, $dest) = @_; 
     38    my ( $self, $file, $dest ) = @_; 
    3939 
    4040    $file or return undef; 
    41      
    42     my ($fh, $fname); 
    43      
     41 
     42    my ( $fh, $fname ); 
     43 
    4444    if ($dest) { 
    4545        $fname = $dest; 
    46         open($fh, '>', $dest) or do { 
     46        open( $fh, '>', $dest ) or do { 
    4747            $self->seterror("Can't uncompress archive: $!"); 
    4848            return undef; 
    4949        }; 
    50     } else { 
    51         ($fh, $fname) = tempfile( 
    52             DIR => $self->_tempdir, 
     50    } 
     51    else { 
     52        ( $fh, $fname ) = tempfile( 
     53            DIR    => $self->_tempdir, 
    5354            UNLINK => 1, 
    54         ) or do { 
     55          ) 
     56          or do { 
    5557            $self->seterror("Can't create temp file: $!"); 
    5658            return undef; 
    57         }; 
     59          }; 
    5860    } 
    5961 
    60     open(my $sourcefh, "unrar p -ierr '$self->{archive}' '$file' 2>/dev/null |") or return undef; 
    61      
    62     if(!copy($sourcefh, $fh)) { 
     62    open( my $sourcefh, 
     63        "unrar p -ierr '$self->{archive}' '$file' 2>/dev/null |" ) 
     64      or return undef; 
     65 
     66    if ( !copy( $sourcefh, $fh ) ) { 
    6367        $self->seterror("Can't copy file to destination: $!"); 
    6468        unlink($fname); 
    6569        return undef; 
    6670    } 
    67      
     71 
    6872    close($fh); 
     73 
    6974    # FIXME unrar sucks, does return a proper exit status on error (allways 0) 
    70     if(!close($sourcefh)) { 
    71         $self->seterror("unrar -p exit with error" . ($! ? (" " . $!) : "")); 
     75    if ( !close($sourcefh) ) { 
     76        $self->seterror( 
     77            "unrar -p exit with error" . ( $! ? ( " " . $! ) : "" ) ); 
    7278        unlink($fname); 
    7379        return undef; 
    7480    } 
    75     $fname 
     81    $fname; 
    7682} 
    7783 
    78 ObsData::Archive::register(sub { $_[0] =~ /\.rar$/i }, 'Rar', 0); 
     84ObsData::Archive::register( sub { $_[0] =~ /\.rar$/i }, 'Rar', 0 ); 
  • obsdata/trunk/ObsData/Archive/Tar.pm

    r247 r274  
    1313 
    1414sub new { 
    15     my ($class, $options) = @_; 
     15    my ( $class, $options ) = @_; 
    1616 
    17     if (!$options->{uncomp}) { 
    18         for ($options->{archive}) { 
     17    if ( !$options->{uncomp} ) { 
     18        for ( $options->{archive} ) { 
    1919            /\.(Z|gz)$/ and $options->{uncomp} = 'gzip -dc'; 
    20             /\.bz2$/ and $options->{uncomp} = 'bzip2 -dc'; 
     20            /\.bz2$/    and $options->{uncomp} = 'bzip2 -dc'; 
    2121        } 
    2222    } 
    2323    $options->{uncomp} ||= 'cat'; 
    24     bless($options, $class); 
     24    bless( $options, $class ); 
    2525} 
    2626 
     
    3131sub ls { 
    3232    my ($self) = @_; 
    33     open(my $htar, '-|', "$self->{uncomp} '$self->{archive}' | tar tf -") or do { 
     33    open( my $htar, '-|', "$self->{uncomp} '$self->{archive}' | tar tf -" ) 
     34      or do { 
    3435        seterror("Can't read tar file: $!"); 
    3536        return undef; 
    36     }; 
     37      }; 
    3738    my @list; 
    38     while(<$htar>) { 
     39    while (<$htar>) { 
    3940        chomp; 
    40         push(@list, $_); 
     41        push( @list, $_ ); 
    4142    } 
    4243    close($htar); 
     
    4546 
    4647sub extract { 
    47     my ($self, $file, $dest) = @_; 
     48    my ( $self, $file, $dest ) = @_; 
    4849 
    4950    $file or return undef; 
    50      
    51     my $tempdir = tempdir(); 
    52     my $here = getcwd(); 
    53     my $abs_path = Cwd::abs_path($self->{archive}); 
     51 
     52    my $tempdir  = tempdir(); 
     53    my $here     = getcwd(); 
     54    my $abs_path = Cwd::abs_path( $self->{archive} ); 
    5455    my $abs_dest = Cwd::abs_path($dest); 
    55      
    56     if(!chdir($tempdir)) { 
     56 
     57    if ( !chdir($tempdir) ) { 
    5758        $self->seterror("Can't chdir: $!"); 
    5859        return undef; 
     
    6465        return undef; 
    6566    }; 
    66      
     67 
    6768    if ($dest) { 
    68         open(my $fh, '>', $abs_dest) or return undef; 
    69         if(!copy("$tempdir/$file", $fh)) { 
     69        open( my $fh, '>', $abs_dest ) or return undef; 
     70        if ( !copy( "$tempdir/$file", $fh ) ) { 
    7071            $self->seterror("Can't copy file to destination: $!"); 
    7172            unlink($abs_dest); 
     
    7778        chdir($here); 
    7879        return $dest; 
    79     } else { 
     80    } 
     81    else { 
    8082        chdir($here); 
    8183        return "$tempdir/$file"; 
     
    8688    sub { 
    8789        $_[0] =~ /\.tar\.(gz|bz2|Z)$/i; 
    88     },  
    89     'Tar',  
     90    }, 
     91    'Tar', 
    9092    0 
    9193); 
  • obsdata/trunk/ObsData/Archive/Zip.pm

    r247 r274  
    1212 
    1313sub new { 
    14     my ($class, $options) = @_; 
    15     bless($options, $class); 
     14    my ( $class, $options ) = @_; 
     15    bless( $options, $class ); 
    1616} 
    1717 
     
    2222sub ls { 
    2323    my ($self) = @_; 
    24     open(my $hzip, '-|', "zipinfo -1 '$self->{archive}'") or do { 
     24    open( my $hzip, '-|', "zipinfo -1 '$self->{archive}'" ) or do { 
    2525        $self->seterror("Can't read zip file: $!"); 
    2626        return undef; 
    2727    }; 
    2828    my @list; 
    29     while(<$hzip>) { 
     29    while (<$hzip>) { 
    3030        chomp; 
    31         push(@list, $_); 
     31        push( @list, $_ ); 
    3232    } 
    3333    close($hzip); 
     
    3636 
    3737sub extract { 
    38     my ($self, $file, $dest) = @_; 
     38    my ( $self, $file, $dest ) = @_; 
    3939 
    4040    $file or return undef; 
    41      
    42     my ($fh, $fname); 
    43      
     41 
     42    my ( $fh, $fname ); 
     43 
    4444    if ($dest) { 
    4545        $fname = $dest; 
    46         open($fh, '>', $dest) or do { 
     46        open( $fh, '>', $dest ) or do { 
    4747            $self->seterror("Can't uncompress archive: $!"); 
    4848            return undef; 
    4949        }; 
    50     } else { 
    51         ($fh, $fname) = tempfile( 
    52             DIR => $self->_tempdir, 
     50    } 
     51    else { 
     52        ( $fh, $fname ) = tempfile( 
     53            DIR    => $self->_tempdir, 
    5354            UNLINK => 1, 
    54         ) or do { 
     55          ) 
     56          or do { 
    5557            $self->seterror("Can't create temp file: $!"); 
    5658            return undef; 
    57         }; 
     59          }; 
    5860    } 
    5961 
    60     open(my $sourcefh, "unzip -p '$self->{archive}' '$file' 2>/dev/null |") or return undef; 
    61      
    62     if(!copy($sourcefh, $fh)) { 
     62    open( my $sourcefh, "unzip -p '$self->{archive}' '$file' 2>/dev/null |" ) 
     63      or return undef; 
     64 
     65    if ( !copy( $sourcefh, $fh ) ) { 
    6366        $self->seterror("Can't copy file to destination: $!"); 
    6467        unlink($fname); 
    6568        return undef; 
    6669    } 
    67      
     70 
    6871    close($fh); 
    69     if(!close($sourcefh)) { 
    70         $self->seterror("unzip -p exit with error" . ($! ? (" " . $!) : "")); 
     72    if ( !close($sourcefh) ) { 
     73        $self->seterror( 
     74            "unzip -p exit with error" . ( $! ? ( " " . $! ) : "" ) ); 
    7175        unlink($fname); 
    7276        return undef; 
     
    7680} 
    7781 
    78 ObsData::Archive::register(sub { $_[0] =~ /\.zip$/i }, 'Zip', 5); 
     82ObsData::Archive::register( sub { $_[0] =~ /\.zip$/i }, 'Zip', 5 ); 
  • obsdata/trunk/ObsData/Event.pm

    r167 r274  
    3131 
    3232sub new { 
    33     my ($class, $id, $message) = @_; 
    34      
    35     if(!($id && $message)) { 
     33    my ( $class, $id, $message ) = @_; 
     34 
     35    if ( !( $id && $message ) ) { 
    3636        return undef; 
    3737    } 
    38      
     38 
    3939    bless( 
    4040        { 
    41             id => $id, 
    42             message => $message, 
    43             test => {}, 
     41            id         => $id, 
     42            message    => $message, 
     43            test       => {}, 
    4444            test_order => [], 
    4545        }, 
     
    5656sub id { 
    5757    my ($self) = @_; 
    58     return($self->{id}); 
     58    return ( $self->{id} ); 
    5959} 
    6060 
     
    6767sub message { 
    6868    my ($self) = @_; 
    69     return($self->{message}); 
     69    return ( $self->{message} ); 
    7070} 
    7171 
     
    7777 
    7878sub add_test { 
    79     my ($self, $test_id, $message, $result) = @_; 
    80     if (!exists($self->{test}{$test_id})) { 
    81         push(@{$self->{test_order}}, $test_id); 
     79    my ( $self, $test_id, $message, $result ) = @_; 
     80    if ( !exists( $self->{test}{$test_id} ) ) { 
     81        push( @{ $self->{test_order} }, $test_id ); 
    8282    } 
    8383    $self->{test}{$test_id}{message} ||= $message; 
     
    9393sub list_test { 
    9494    my ($self) = @_; 
    95     return(@{$self->{test_order}}); 
     95    return ( @{ $self->{test_order} } ); 
    9696} 
    9797 
     
    103103 
    104104sub test_message { 
    105     my ($self, $test_id) = @_; 
    106     return($self->{test}{$test_id}{message}); 
     105    my ( $self, $test_id ) = @_; 
     106    return ( $self->{test}{$test_id}{message} ); 
    107107} 
    108108 
     
    114114 
    115115sub test_result { 
    116     my ($self, $test_id) = @_; 
    117     return($self->{test}{$test_id}{result}); 
     116    my ( $self, $test_id ) = @_; 
     117    return ( $self->{test}{$test_id}{result} ); 
    118118} 
    119119 
  • obsdata/trunk/ObsData/Repository.pm

    r272 r274  
    1414 
    1515our $CVSID = q$Id$; 
    16 our $CVSREV = (q$Revision$ =~ /^Revision: (.*) $/)[0]; 
     16our $CVSREV = ( q$Revision$ =~ /^Revision: (.*) $/ )[0]; 
    1717 
    1818=head1 METHODS 
     
    6767 
    6868sub new { 
    69     my ($class, $parent, %param) = @_; 
    70  
    71     my $or = { %$parent }; 
    72     foreach (keys %param) { 
     69    my ( $class, $parent, %param ) = @_; 
     70 
     71    my $or = {%$parent}; 
     72    foreach ( keys %param ) { 
    7373        $or->{$_} = $param{$_}; 
    7474    } 
    75      
     75 
    7676    $or->{obsdata} or die "Error #1de8d015, please insult programmer"; 
    77     $or->{dir} or die "No dir given"; 
    78     -d $or->{dir} or return undef; 
    79      
     77    $or->{dir}     or die "No dir given"; 
     78    -d $or->{dir}  or return undef; 
     79 
    8080    $or->{status} ||= new Config::IniFiles( 
    81         -file => (($or->{statusfile} && -f $or->{statusfile}) ? $or->{statusfile} : undef), 
     81        -file => ( 
     82            ( $or->{statusfile} && -f $or->{statusfile} ) 
     83            ? $or->{statusfile} 
     84            : undef 
     85        ), 
     86 
    8287        # -default => '.', # Is this a good idea 
    8388    ); 
    84     $or->{statusfile} ||= $or->{status}->GetFileName; 
     89    $or->{statusfile}           ||= $or->{status}->GetFileName; 
    8590    $or->{interactive_callback} ||= $or->{obsdata}->{interactive_callback}; 
    8691 
    87     bless($or, $class); 
     92    bless( $or, $class ); 
    8893 
    8994    $or; 
     
    9297sub DESTROY { 
    9398    my ($self) = @_; 
    94     $self->logging(0, "Destroy ObsData::Repository for %s", ref($self)); 
     99    $self->logging( 0, "Destroy ObsData::Repository for %s", ref($self) ); 
    95100    $self->save_status; 
    96101} 
     
    103108 
    104109sub mydir { 
    105     $_[0]->{dir} 
     110    $_[0]->{dir}; 
    106111} 
    107112 
     
    115120    my ($self) = @_; 
    116121    $self->{status}->AddSection('.'); 
    117     $self->{status}->SetSectionComment('.', 
    118         $ObsData::CVSID, 
    119         $ObsData::Repository::CVSID, 
    120         scalar(localtime), 
    121     ); 
     122    $self->{status} 
     123      ->SetSectionComment( '.', $ObsData::CVSID, $ObsData::Repository::CVSID, 
     124        scalar(localtime), ); 
    122125 
    123126    my $hostname = `hostname`; 
    124127    chomp($hostname); 
    125     $self->{status}->newval('.', 'hostname', $hostname); 
    126     $self->{status}->SetParameterComment( 
    127         '.', 
    128         'hostname', 
    129         'The computer host name' 
    130     ); 
    131  
    132     $self->{status}->newval('.', 'directory', $self->{dir}); 
    133     $self->{status}->SetParameterComment( 
    134         '.', 
    135         'directory',  
    136         'Directory where archive where located' 
    137     ); 
    138      
    139     $self->{status}->newval('.', 'runfrom', getcwd()); 
    140     $self->{status}->SetParameterComment( 
    141         '.', 
    142         'runfrom', 
    143         'The current directory' 
    144     ); 
     128    $self->{status}->newval( '.', 'hostname', $hostname ); 
     129    $self->{status} 
     130      ->SetParameterComment( '.', 'hostname', 'The computer host name' ); 
     131 
     132    $self->{status}->newval( '.', 'directory', $self->{dir} ); 
     133    $self->{status}->SetParameterComment( '.', 'directory', 
     134        'Directory where archive where located' ); 
     135 
     136    $self->{status}->newval( '.', 'runfrom', getcwd() ); 
     137    $self->{status} 
     138      ->SetParameterComment( '.', 'runfrom', 'The current directory' ); 
    145139} 
    146140 
     
    154148    my ($self) = @_; 
    155149    $self->{statusfile} or return; 
    156     if (!$self->{dry_run}) { 
    157         $self->logging(0, 
    158             "Writing status file: %s", 
    159             $self->{statusfile}, 
    160         ); 
     150    if ( !$self->{dry_run} ) { 
     151        $self->logging( 0, "Writing status file: %s", $self->{statusfile}, ); 
    161152        $self->update_global_status; 
    162         $self->{status}->WriteConfig($self->{statusfile}); 
     153        $self->{status}->WriteConfig( $self->{statusfile} ); 
    163154    } 
    164155} 
     
    172163 
    173164sub dump_status { 
    174     my ($self, $output) = @_; 
     165    my ( $self, $output ) = @_; 
    175166    $self->update_global_status; 
    176167    $self->{status}->WriteConfig($output); 
     
    203194 
    204195sub new { 
    205     my ($class, $infos, %param) = @_; 
    206  
    207     my $or = ObsData::Repository->new($infos, %param) or return; 
    208  
    209     bless($or, $class); 
     196    my ( $class, $infos, %param ) = @_; 
     197 
     198    my $or = ObsData::Repository->new( $infos, %param ) or return; 
     199 
     200    bless( $or, $class ); 
    210201} 
    211202 
     
    220211    my @files; 
    221212 
    222     if (!-d $self->{dir}) { 
    223         $self->logging(3, 
    224             "directory %s does not exists", 
    225             $self->{dir}, 
    226         ); 
     213    if ( !-d $self->{dir} ) { 
     214        $self->logging( 3, "directory %s does not exists", $self->{dir}, ); 
    227215        return; 
    228216    } 
    229217 
    230218    my $patern = $self->{patern} || '*'; 
    231     foreach my $f (glob("$self->{dir}/$patern")) { 
    232  
    233         -f $f or next; # skip no regular files 
    234         $f =~ m/obsdata\.ini$/ and next; # avoid default status file 
    235          
     219    foreach my $f ( glob("$self->{dir}/$patern") ) { 
     220 
     221        -f $f or next;    # skip no regular files 
     222        $f =~ m/obsdata\.ini$/ and next;    # avoid default status file 
     223 
    236224        my $bf = $f; 
    237225        $bf =~ s!^\Q$self->{dir}\E/*!!; 
    238         push(@files, $bf); 
    239     } 
    240     @files 
     226        push( @files, $bf ); 
     227    } 
     228    @files; 
    241229} 
    242230 
     
    250238    my ($self) = @_; 
    251239 
    252     grep { $_ ne '.' } $self->{status}->Sections 
     240    grep { $_ ne '.' } $self->{status}->Sections; 
    253241} 
    254242 
     
    261249sub process { 
    262250    my ($self) = @_; 
    263     $self->logging(0, "%s() start for %s", (caller(0))[3], $self->{dir}); 
    264  
    265     foreach my $file ($self->findfile) { 
    266         my $orda = ObsData::Repository::dir::archive->new( 
    267             $self, 
    268             archivefile => $file, 
    269         ); 
    270  
    271         my $oe = ObsData::Event->new('do_archive', "Should I parse $file"); 
    272          
    273         $oe->add_test('archive_exists', 
    274             $self->{status}->SectionExists($orda->{archivefile}) ? 
    275             ("Archive file found in index", 1) : 
    276             ("Archive file not found in index", 0) 
    277         ); 
    278          
    279         if (defined(my $oldsize = $orda->getvalue('size'))) { 
    280             my $size = (stat("$orda->{dir}/$orda->{archivefile}"))[7]; 
    281              
    282             $oe->add_test('archive_size', 
    283                 ($size <=> $oldsize) == 0 ? 
    284                 (sprintf("size does not differ (%d)", $size), 1) : 
    285                 (sprintf("differ %d => %d", $oldsize, $size), 0) 
    286             ); 
    287         } 
    288  
    289         if (defined(my $oldmtime = $orda->getvalue('mtime'))) { 
    290             my $mtime = (stat("$orda->{dir}/$orda->{archivefile}"))[9]; 
    291             $oe->add_test('archive_mtime', 
    292                 ($mtime <=> $oldmtime) == 0 ? 
    293                 (sprintf("mtime does not differ (%d)", $mtime), 1) : 
    294                 (sprintf("differ %d => %d", $oldmtime, $mtime), 0) 
    295             ); 
    296         } 
    297          
     251    $self->logging( 0, "%s() start for %s", ( caller(0) )[3], $self->{dir} ); 
     252 
     253    foreach my $file ( $self->findfile ) { 
     254        my $orda = 
     255          ObsData::Repository::dir::archive->new( $self, archivefile => $file, 
     256          ); 
     257 
     258        my $oe = ObsData::Event->new( 'do_archive', "Should I parse $file" ); 
     259 
     260        $oe->add_test( 'archive_exists', 
     261            $self->{status}->SectionExists( $orda->{archivefile} ) 
     262            ? ( "Archive file found in index", 1 ) 
     263            : ( "Archive file not found in index", 0 ) ); 
     264 
     265        if ( defined( my $oldsize = $orda->getvalue('size') ) ) { 
     266            my $size = ( stat("$orda->{dir}/$orda->{archivefile}") )[7]; 
     267 
     268            $oe->add_test( 'archive_size', 
     269                  ( $size <=> $oldsize ) == 0 
     270                ? ( sprintf( "size does not differ (%d)", $size ), 1 ) 
     271                : ( sprintf( "differ %d => %d", $oldsize, $size ), 0 ) ); 
     272        } 
     273 
     274        if ( defined( my $oldmtime = $orda->getvalue('mtime') ) ) { 
     275            my $mtime = ( stat("$orda->{dir}/$orda->{archivefile}") )[9]; 
     276            $oe->add_test( 'archive_mtime', 
     277                  ( $mtime <=> $oldmtime ) == 0 
     278                ? ( sprintf( "mtime does not differ (%d)", $mtime ), 1 ) 
     279                : ( sprintf( "differ %d => %d", $oldmtime, $mtime ), 0 ) ); 
     280        } 
     281 
    298282        $orda->ask_user($oe) or next; 
    299          
     283 
    300284        $orda->process; 
    301285    } 
     
    304288sub get_archives_from_status { 
    305289    my ($self) = @_; 
    306     map { 
    307         ObsData::Repository::dir::archive->new( 
    308             $self, 
    309             archivefile => $_, 
    310         )  
    311     } $self->list_archive_from_status(); 
     290    map { ObsData::Repository::dir::archive->new( $self, archivefile => $_, ) } 
     291      $self->list_archive_from_status(); 
    312292} 
    313293 
     
    337317 
    338318sub new { 
    339     my ($class, $infos, %param) = @_; 
    340  
    341     my $or = ObsData::Repository->new($infos, %param) or return; 
     319    my ( $class, $infos, %param ) = @_; 
     320 
     321    my $or = ObsData::Repository->new( $infos, %param ) or return; 
     322 
    342323    # dir directory to parse 
    343324    $or->{archivefile} or die "No archivefile given"; 
     
    345326    # $or->{interactive_callback} 
    346327    $or->{_cache_checks} = {}; 
    347      
    348     $or->logging(0, 
    349         "Preparing to parse %s/%s", 
    350          $or->{dir}, 
    351          $or->{archivefile} 
    352     ); 
    353  
    354     bless($or, $class); 
     328 
     329    $or->logging( 0, "Preparing to parse %s/%s", 
     330        $or->{dir}, $or->{archivefile} ); 
     331 
     332    bless( $or, $class ); 
    355333} 
    356334 
    357335sub DESTROY { 
    358336    my ($self) = @_; 
    359     $self->logging(0, "Destroy ObsData::Repository for %s", ref($self)); 
    360     if ($self->{status_changed}) { 
    361         $self->save_status 
     337    $self->logging( 0, "Destroy ObsData::Repository for %s", ref($self) ); 
     338    if ( $self->{status_changed} ) { 
     339        $self->save_status; 
    362340    } 
    363341} 
     
    370348 
    371349sub archivefile { 
    372     $_[0]->{archivefile} 
     350    $_[0]->{archivefile}; 
    373351} 
    374352 
     
    381359sub load_archive { 
    382360    my ($self) = @_; 
    383     if ($self->{Oarchive}) { 
     361    if ( $self->{Oarchive} ) { 
    384362        return 1; 
    385     } else { 
    386         $self->{Oarchive} = ObsData::Archive->new("$self->{dir}/$self->{archivefile}"); 
    387         if ($self->{Oarchive}) { 
    388             $self->logging(0, 
    389                 "Archive %s/%s properly load", 
    390                 $self->{dir}, $self->{archivefile} 
    391             ); 
     363    } 
     364    else { 
     365        $self->{Oarchive} = 
     366          ObsData::Archive->new("$self->{dir}/$self->{archivefile}"); 
     367        if ( $self->{Oarchive} ) { 
     368            $self->logging( 0, "Archive %s/%s properly load", 
     369                $self->{dir}, $self->{archivefile} ); 
    392370            return 1; 
    393         } else { 
    394             $self->logging(4,  
    395                 "Can't handle archive %s/%s: %s, skipping", 
    396                 $self->{dir}, $self->{archivefile}, 
    397                 ObsData::Archive->error 
    398             ); 
     371        } 
     372        else { 
     373            $self->logging( 4, "Can't handle archive %s/%s: %s, skipping", 
     374                $self->{dir}, $self->{archivefile}, ObsData::Archive->error ); 
    399375            return 0; 
    400376        } 
     
    411387sub archive { 
    412388    my ($self) = @_; 
    413     if ($self->load_archive()) { 
     389    if ( $self->load_archive() ) { 
    414390        return $self->{Oarchive}; 
    415     } else { 
     391    } 
     392    else { 
    416393        return undef; 
    417394    } 
     
    425402 
    426403sub getvalue { 
    427     my ($self, $var, $default) = @_; 
    428     return $self->{status}->val($self->{archivefile}, $var, $default); 
     404    my ( $self, $var, $default ) = @_; 
     405    return $self->{status}->val( $self->{archivefile}, $var, $default ); 
    429406} 
    430407 
     
    436413 
    437414sub setvalue { 
    438     my ($self, $var, $val, $comment) = @_; 
    439     if (!$self->{status}->SectionExists($self->{archivefile})) { 
    440         $self->{status}->AddSection($self->{archivefile}); 
    441     } 
    442     $self->{status}->newval($self->{archivefile}, $var, $val) if(defined($val)); 
    443     $self->{status}->SetParameterComment( 
    444         $self->{archivefile}, $var, $comment 
    445     ) if(defined($comment)); 
     415    my ( $self, $var, $val, $comment ) = @_; 
     416    if ( !$self->{status}->SectionExists( $self->{archivefile} ) ) { 
     417        $self->{status}->AddSection( $self->{archivefile} ); 
     418    } 
     419    $self->{status}->newval( $self->{archivefile}, $var, $val ) 
     420      if ( defined($val) ); 
     421    $self->{status}->SetParameterComment( $self->{archivefile}, $var, $comment ) 
     422      if ( defined($comment) ); 
    446423    $self->{status_changed} = 1; 
    447424} 
     
    454431 
    455432sub get_data_value { 
    456     my ($self, $datafile, $var, $default) = @_; 
    457     return $self->getvalue( 
    458         sprintf('data_%s_%s', $var, $datafile), 
    459         $default 
    460     ); 
     433    my ( $self, $datafile, $var, $default ) = @_; 
     434    return $self->getvalue( sprintf( 'data_%s_%s', $var, $datafile ), 
     435        $default ); 
    461436} 
    462437 
     
    468443 
    469444sub set_data_value { 
    470     my ($self, $datafile, $var, $val, $comment) = @_; 
    471     $self->setvalue( 
    472         sprintf('data_%s_%s', $var, $datafile), 
    473         $val, 
    474         $comment 
    475     ); 
     445    my ( $self, $datafile, $var, $val, $comment ) = @_; 
     446    $self->setvalue( sprintf( 'data_%s_%s', $var, $datafile ), $val, $comment ); 
    476447} 
    477448 
     
    488459 
    489460sub default_choice { 
    490     my ($self, $oevent) = @_; 
    491  
    492     for ($oevent->id) { 
     461    my ( $self, $oevent ) = @_; 
     462 
     463    for ( $oevent->id ) { 
    493464        /^do_archive$/ and do { 
    494             return($oevent->test_result('archive_exists') ? 0 : 1); 
     465            return ( $oevent->test_result('archive_exists') ? 0 : 1 ); 
    495466            last; 
    496467        }; 
    497468        /^do_data$/ and do { 
    498             return 1; # TODO 
     469            return 1;    # TODO 
    499470            last; 
    500471        }; 
    501472        /^overwrite$/ and do { 
    502             return($oevent->test_result('dest_exists') ? 0 : 1); 
     473            return ( $oevent->test_result('dest_exists') ? 0 : 1 ); 
    503474            last; 
    504475        }; 
     
    514485 
    515486sub ask_user { 
    516     my ($self, $oevent) = @_; 
    517  
    518     $self->logging(0, "Event(%s): %s", 
    519         $oevent->id, 
    520         $oevent->message); 
    521     foreach ($oevent->list_test) { 
    522         $self->logging(0, "  (%s) %s: %s", 
     487    my ( $self, $oevent ) = @_; 
     488 
     489    $self->logging( 0, "Event(%s): %s", $oevent->id, $oevent->message ); 
     490    foreach ( $oevent->list_test ) { 
     491        $self->logging( 
     492            0, "  (%s) %s: %s", 
    523493            $_, 
    524494            $oevent->test_message($_), 
     
    528498 
    529499    my $res = 
    530         $self->{interactive_callback} ? 
    531         $self->{interactive_callback}->($self, $oevent) : 
    532         $self->default_choice($oevent); 
    533  
    534     $self->logging(0, "Event(%s): Result: %s", $oevent->id, $res); 
    535     return($res); 
     500        $self->{interactive_callback} 
     501      ? $self->{interactive_callback}->( $self, $oevent ) 
     502      : $self->default_choice($oevent); 
     503 
     504    $self->logging( 0, "Event(%s): Result: %s", $oevent->id, $res ); 
     505    return ($res); 
    536506} 
    537507 
     
    544514sub list_archive { 
    545515    my ($self) = @_; 
    546     if (my $archive = $self->archive) { 
     516    if ( my $archive = $self->archive ) { 
    547517        return $archive->ls(); 
    548     } else { 
     518    } 
     519    else { 
    549520        return undef; 
    550521    } 
     
    560531    my ($self) = @_; 
    561532    my @filestats = stat("$self->{dir}/$self->{archivefile}"); 
    562      
    563     $self->setvalue('mtime', $filestats[9]); 
    564     $self->setvalue('size', $filestats[7]); 
    565     $self->setvalue('configtime', $self->{obsdata}->config_mtime); 
     533 
     534    $self->setvalue( 'mtime',      $filestats[9] ); 
     535    $self->setvalue( 'size',       $filestats[7] ); 
     536    $self->setvalue( 'configtime', $self->{obsdata}->config_mtime ); 
    566537} 
    567538 
     
    575546 
    576547sub match_data_type { 
    577     my ($self, $datafile) =  @_; 
    578     foreach my $datatype (($self->{datatype}) || $self->{obsdata}->list_datatype) { 
    579         my $regexp = $self->{obsdata}->getvalue($datatype, 'match') or next; 
     548    my ( $self, $datafile ) = @_; 
     549    foreach 
     550      my $datatype ( ( $self->{datatype} ) || $self->{obsdata}->list_datatype ) 
     551    { 
     552        my $regexp = $self->{obsdata}->getvalue( $datatype, 'match' ) or next; 
    580553        my @data = $datafile =~ /$regexp/; 
    581554        my @dataar = $self->archive_match($datatype); 
    582         my ($pret, %parg) = $self->get_info_from_plugin($datatype, $datafile); 
     555        my ( $pret, %parg ) = 
     556          $self->get_info_from_plugin( $datatype, $datafile ); 
     557 
    583558        # if no regexp => return undef 
    584559        # if regexp and match, @dataar contain something 
    585         # if regexp no match, @dataar is empty  
    586         if (@data && (@dataar || !defined($dataar[0])) && (!defined($pret) || $pret)) { 
    587             return ($datatype, \@data, \@dataar, \%parg); 
     560        # if regexp no match, @dataar is empty 
     561        if (   @data 
     562            && ( @dataar         || !defined( $dataar[0] ) ) 
     563            && ( !defined($pret) || $pret ) ) 
     564        { 
     565            return ( $datatype, \@data, \@dataar, \%parg ); 
    588566        } 
    589567    } 
     
    597575 
    598576sub archive_match { 
    599     my ($self, $datatype) = @_; 
    600     my $regexp = $self->{obsdata}->getvalue($datatype, 'match_archive') or return undef; 
     577    my ( $self, $datatype ) = @_; 
     578    my $regexp = $self->{obsdata}->getvalue( $datatype, 'match_archive' ) 
     579      or return undef; 
    601580    my @data = $self->{archivefile} =~ /$regexp/; 
    602581    return @data; 
     
    613592 
    614593sub get_info_from_plugin { 
    615     my ($self, $datatype, $datafile) = @_; 
    616      
     594    my ( $self, $datatype, $datafile ) = @_; 
     595 
    617596    my %val; 
    618      
    619     my ($sub, @args) = $self->{obsdata}->get_sub_plugin( 
    620         $datatype, 
    621         'match_plugin' 
    622     ); 
     597 
     598    my ( $sub, @args ) = 
     599      $self->{obsdata}->get_sub_plugin( $datatype, 'match_plugin' ); 
    623600    if ($sub) { 
    624         $self->logging(0, 
    625             "Found plugin %s for %s, running it", 
    626             'match_plugin', 
    627             $datatype, 
    628         ); 
    629         my ($exitstatus, @result) = $sub->( 
    630             $self, 
    631             'match_plugin', 
    632             $datafile, 
    633             $datatype, 
    634             @args, 
    635         ); 
     601        $self->logging( 0, "Found plugin %s for %s, running it", 
     602            'match_plugin', $datatype, ); 
     603        my ( $exitstatus, @result ) = 
     604          $sub->( $self, 'match_plugin', $datafile, $datatype, @args, ); 
    636605        if ($exitstatus) { 
    637             if (@result % 2 == 0) { 
    638                 $self->logging(0, 
    639                     "Plugin %s for %s exit with %s (%d values)", 
    640                     'match_plugin', 
    641                     $datatype, 
    642                     $exitstatus, 
    643                     scalar(@result), 
    644                 ); 
    645                 return(1, @result); 
    646             } else { 
    647                 $self->logging(4, 
    648                     "Plugin %s for %s return impair values %d", 
    649                     $datatype, 
    650                     $exitstatus, 
    651                     scalar(@result), 
    652                 ); 
     606            if ( @result % 2 == 0 ) { 
     607                $self->logging( 0, "Plugin %s for %s exit with %s (%d values)", 
     608                    'match_plugin', $datatype, $exitstatus, scalar(@result), ); 
     609                return ( 1, @result ); 
     610            } 
     611            else { 
     612                $self->logging( 4, "Plugin %s for %s return impair values %d", 
     613                    $datatype, $exitstatus, scalar(@result), ); 
    653614                return undef; 
    654615            } 
    655         } else { 
    656             $self->logging(0, 
    657                 "Plugin %s of %s exit with null, skipping", 
    658                 'match_plugin', 
    659                 $datatype, 
    660             ); 
     616        } 
     617        else { 
     618            $self->logging( 0, "Plugin %s of %s exit with null, skipping", 
     619                'match_plugin', $datatype, ); 
    661620            return 0; 
    662621        } 
    663     } else { 
     622    } 
     623    else { 
    664624        return undef; 
    665625    } 
     
    678638 
    679639sub build_dest_filename { 
    680     my ($self, $datafile) = @_; 
    681     my ($datatype, $data, $dataar, $parg) = $self->match_data_type($datafile); 
    682      
    683     if (! $datatype) { 
     640    my ( $self, $datafile ) = @_; 
     641    my ( $datatype, $data, $dataar, $parg ) = $self->match_data_type($datafile); 
     642 
     643    if ( !$datatype ) { 
    684644        return; 
    685645    } 
    686646 
    687     my %val = %{$parg || {}}; 
    688  
    689     my $dest = $self->{obsdata}->getvalue($datatype, 'dest'); 
    690     my @matcharg = split(/\s+/, $self->{obsdata}->getvalue($datatype, 'matcharg') || ''); 
    691     my @matcharg_ar = split(/\s+/, $self->{obsdata}->getvalue($datatype, 'matcharg_archive') || ''); 
    692     my @destarg = split(/\s+/, $self->{obsdata}->getvalue($datatype, 'destarg') || ''); 
     647    my %val = %{ $parg || {} }; 
     648 
     649    my $dest = $self->{obsdata}->getvalue( $datatype, 'dest' ); 
     650    my @matcharg = 
     651      split( /\s+/, $self->{obsdata}->getvalue( $datatype, 'matcharg' ) || '' ); 
     652    my @matcharg_ar = 
     653      split( /\s+/, 
     654        $self->{obsdata}->getvalue( $datatype, 'matcharg_archive' ) || '' ); 
     655    my @destarg = 
     656      split( /\s+/, $self->{obsdata}->getvalue( $datatype, 'destarg' ) || '' ); 
    693657    my @gmtime = gmtime; 
    694658 
     
    699663        $val{$_} = shift(@$dataar); 
    700664    } 
     665 
    701666    # FIXME Is this need ? 
    702667    # foreach (keys %{$magic_words || {}}) { 
    703668    #    $val{'$' . $_} = $magic_words->{$_}; 
    704669    #} 
    705      
    706     $val{'$datafile'} = $datafile; 
     670 
     671    $val{'$datafile'}    = $datafile; 
    707672    $val{'$archivefile'} = $self->{archivefile}; 
    708     ($val{'$basedatafile'}) = $datafile =~ m:([^/]*)$:; 
    709     my $destfile = sprintf( 
    710         $dest, 
    711         map { m/^%/ ? strftime($_, @gmtime) : $val{$_} || '' } grep { defined($_) } @destarg, 
     673    ( $val{'$basedatafile'} ) = $datafile =~ m:([^/]*)$:; 
     674    my $destfile = sprintf( $dest, 
     675        map { m/^%/ ? strftime( $_, @gmtime ) : $val{$_} || '' } 
     676          grep { defined($_) } @destarg, 
    712677    ); 
    713     if (!$destfile) { 
    714         $self->logging(4, "Can evaluate destination file from %s, %s", 
     678    if ( !$destfile ) { 
     679        $self->logging( 
     680            4, 
     681            "Can evaluate destination file from %s, %s", 
    715682            $dest, 
    716             join(", ", map { m/^%/ ? strftime($_, @gmtime) : $val{$_} } @destarg) 
     683            join( ", ", 
     684                map { m/^%/ ? strftime( $_, @gmtime ) : $val{$_} } @destarg ) 
    717685        ); 
    718         return(); 
    719     } 
    720     return($datatype, $destfile); 
     686        return (); 
     687    } 
     688    return ( $datatype, $destfile ); 
    721689} 
    722690 
     
    730698 
    731699sub get_data_dest { 
    732     my ($self, $datafile) = @_; 
    733  
    734     my ($t, $d) = $self->build_dest_filename( 
    735         $datafile, 
    736         $self->{datatype} 
    737     ); 
    738     $self->logging(0, "%s/%s file, datatype %s, destination %s", 
    739         $self->{archivefile}, 
    740         $datafile, 
     700    my ( $self, $datafile ) = @_; 
     701 
     702    my ( $t, $d ) = $self->build_dest_filename( $datafile, $self->{datatype} ); 
     703    $self->logging( 
     704        0, "%s/%s file, datatype %s, destination %s", 
     705        $self->{archivefile}, $datafile, 
    741706        $t || '(none)', 
    742707        $d || '(none)', 
    743708    ); 
    744709    if ($t) { 
    745         $self->set_data_value($datafile, 'type', $t); 
    746     } 
    747     return($t, $d); 
     710        $self->set_data_value( $datafile, 'type', $t ); 
     711    } 
     712    return ( $t, $d ); 
    748713} 
    749714 
     
    762727 
    763728sub extract_data { 
     729 
    764730    # $datatype, informationnal only here 
    765     my ($self, $datafile, $datatype, $destfile) = @_; 
     731    my ( $self, $datafile, $datatype, $destfile ) = @_; 
    766732    $self->load_archive or return 0; 
    767733    my $ltime = time; 
     
    771737        'processtime', 
    772738        $ltime, 
    773         scalar(localtime($ltime)) . 
    774         ", $ObsData::VERSION: $ObsData::CVSREV, $ObsData::Repository::CVSREV", 
     739        scalar( localtime($ltime) ) 
     740          . ", $ObsData::VERSION: $ObsData::CVSREV, $ObsData::Repository::CVSREV", 
    775741    ); 
    776     $self->set_data_value( 
    777         $datafile, 
    778         'processversion', 
    779         $ObsData::VERSION, 
    780     ); 
    781     
    782     if (!$destfile) { 
    783         $self->logging(3, 
    784             "%s/%s has no destination", 
    785             $self->{archivefile}, $datafile, 
    786         ); 
    787         $self->{obsdata}->processed( 
    788             $self->{obs}, 
    789             $self->{archivefile}, 
    790             $datafile, 
    791         ); 
     742    $self->set_data_value( $datafile, 'processversion', $ObsData::VERSION, ); 
     743 
     744    if ( !$destfile ) { 
     745        $self->logging( 3, "%s/%s has no destination", 
     746            $self->{archivefile}, $datafile, ); 
     747        $self->{obsdata} 
     748          ->processed( $self->{obs}, $self->{archivefile}, $datafile, ); 
    792749        return 0; 
    793750    } 
    794     
    795     my $oe = ObsData::Event->new('overwrite', 
    796         "Should I overwrite $destfile" 
    797     ); 
    798  
    799     $oe->add_test( 
    800         'dest_exists', 
    801         -e $destfile ? ("$destfile exists", 1) : ("$destfile don't exists", 0) 
    802     ); 
     751 
     752    my $oe = ObsData::Event->new( 'overwrite', "Should I overwrite $destfile" ); 
     753 
     754    $oe->add_test( 'dest_exists', 
     755        -e $destfile 
     756        ? ( "$destfile exists", 1 ) 
     757        : ( "$destfile don't exists", 0 ) ); 
    803758    $self->ask_user($oe) or return 0; 
    804      
    805     $self->logging(0, 
    806         "Trying to extract %s from %s/%s", 
    807         $destfile, 
    808         $self->{archivefile}, $datafile 
    809     ); 
    810  
    811     my ($dirname) = $destfile =~ m!(?:(.*)/)?(.*)$!; #! vim syntax sux 
    812      
    813     if ($dirname && ! -d $dirname) { 
    814         $self->logging(1, "Creating directory %s", $dirname); 
    815         if ($self->{dry_run}) { 
    816             $self->logging(1, 
    817                 "Testing mode, assume %s was correctly created", 
    818                 $dirname 
    819             ); 
    820         } else { 
     759 
     760    $self->logging( 0, "Trying to extract %s from %s/%s", 
     761        $destfile, $self->{archivefile}, $datafile ); 
     762 
     763    my ($dirname) = $destfile =~ m!(?:(.*)/)?(.*)$!;    #! vim syntax sux 
     764 
     765    if ( $dirname && !-d $dirname ) { 
     766        $self->logging( 1, "Creating directory %s", $dirname ); 
     767        if ( $self->{dry_run} ) { 
     768            $self->logging( 1, "Testing mode, assume %s was correctly created", 
     769                $dirname ); 
     770        } 
     771        else { 
    821772            eval { File::Path::mkpath($dirname) }; 
    822             if($@) { 
    823                 $self->logging( 
    824                     4, "Can't create directory %s: %s",  
    825                     $dirname, 
    826                     $@ 
    827                 ); 
     773            if ($@) { 
     774                $self->logging( 4, "Can't create directory %s: %s", 
     775                    $dirname, $@ ); 
    828776                return 0; 
    829777            } 
     
    831779    } 
    832780 
    833     if ($self->{dry_run}) { 
    834         $self->logging(2, 
    835             "Testing mode, %s/%s would be extracted as %s", 
    836             $self->{archivefile}, 
    837             $datafile, 
    838             $destfile, 
    839         ); 
    840     } else { 
    841         if ($self->{Oarchive}->extract($datafile, $destfile)) { 
    842             $self->set_data_value($datafile, 'dest', $destfile); 
    843             $self->{obsdata}->processed( 
    844                 $self->{obs}, 
    845                 $self->{archivefile}, 
    846                 $datafile, 
    847                 $datatype, 
    848                 $destfile, 
    849             ); 
    850         } else { 
     781    if ( $self->{dry_run} ) { 
     782        $self->logging( 2, "Testing mode, %s/%s would be extracted as %s", 
     783            $self->{archivefile}, $datafile, $destfile, ); 
     784    } 
     785    else { 
     786        if ( $self->{Oarchive}->extract( $datafile, $destfile ) ) { 
     787            $self->set_data_value( $datafile, 'dest', $destfile ); 
     788            $self->{obsdata} 
     789              ->processed( $self->{obs}, $self->{archivefile}, $datafile, 
     790                $datatype, $destfile, ); 
     791        } 
     792        else { 
    851793            $self->logging( 
    852794                4, "Can't extract %s/%s to %s: %s", 
     
    857799        } 
    858800    } 
    859      
     801 
    860802    return 1; 
    861803} 
     
    870812    my ($self) = @_; 
    871813 
    872     foreach my $data ($self->list_archive) { 
    873         my $oe = ObsData::Event->new('do_data', 
    874             "Should I extract $data from $self->{archivefile}" 
    875         ); 
    876         $oe->add_test('data_extracted', 
    877             $self->get_data_value($data, 'dest') ? 
    878             ('Data was already extract', 1) : 
    879             ('Data was not already extract', 0) 
    880         ); 
    881    
     814    foreach my $data ( $self->list_archive ) { 
     815        my $oe = 
     816          ObsData::Event->new( 'do_data', 
     817            "Should I extract $data from $self->{archivefile}" ); 
     818        $oe->add_test( 'data_extracted', 
     819            $self->get_data_value( $data, 'dest' ) 
     820            ? ( 'Data was already extract', 1 ) 
     821            : ( 'Data was not already extract', 0 ) ); 
     822 
    882823        $self->ask_user($oe) or next; 
    883824 
    884         $self->extract_data($data, $self->get_data_dest($data)); 
    885     } 
    886      
     825        $self->extract_data( $data, $self->get_data_dest($data) ); 
     826    } 
     827 
    887828    $self->update_status; 
    888829 
     
    892833sub list_data_from_status { 
    893834    my ($self) = @_; 
    894     map { m/data_processtime_(.*)/; $1 } grep { 
    895         $_ && index($_, 'data_processtime_') == 0 
    896     } $self->{status}->Parameters($self->{archivefile}) 
     835    map { m/data_processtime_(.*)/; $1 } 
     836      grep { $_ && index( $_, 'data_processtime_' ) == 0 } 
     837      $self->{status}->Parameters( $self->{archivefile} ); 
    897838} 
    898839 
    899840sub data_extracted { 
    900     my ($self, $data) = @_; 
    901     return $self->get_data_value($data, 'dest'); 
     841    my ( $self, $data ) = @_; 
     842    return $self->get_data_value( $data, 'dest' ); 
    902843} 
    903844 
Note: See TracChangeset for help on using the changeset viewer.