Changeset 274 for obsdata/trunk
- Timestamp:
- 10/27/06 00:30:40 (18 years ago)
- Location:
- obsdata/trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
obsdata/trunk/ObsData.pm
r273 r274 12 12 use File::Basename; 13 13 14 my @loglevel = ( 15 'DEBUG', 16 'INFO', 17 'RESULT', 18 'WARNING', 19 'ERROR', 20 'FATAL', 21 ); 14 my @loglevel = ( 'DEBUG', 'INFO', 'RESULT', 'WARNING', 'ERROR', 'FATAL', ); 22 15 23 16 our $VERSION = "0.3.1"; 24 our $CVSID = q$Id$;25 our $CVSREV = (q$Revision$ =~ /^Revision: (.*) $/)[0];17 our $CVSID = q$Id$; 18 our $CVSREV = ( q$Revision$ =~ /^Revision: (.*) $/ )[0]; 26 19 27 20 =head1 NAME … … 44 37 45 38 sub new { 46 my ( $class, $configfile, %options) = @_;39 my ( $class, $configfile, %options ) = @_; 47 40 my $obsdata = { 48 41 config => new Config::IniFiles( 49 -file => $configfile,50 -default => 'global',42 -file => $configfile, 43 -default => 'global', 51 44 -allowcontinue => 1 52 45 ), 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}, 57 50 interactive_callback => $options{interactive_callback}, 58 processed_lists => [],51 processed_lists => [], 59 52 }; 60 53 61 if ( !($configfile && -f $configfile && -r _)) {54 if ( !( $configfile && -f $configfile && -r _ ) ) { 62 55 return undef; 63 56 } … … 66 59 67 60 # directory where to search plugins 68 @{ $obsdata->{plugindir}} = grep { $_ && -d $_ } (61 @{ $obsdata->{plugindir} } = grep { $_ && -d $_ } ( 69 62 $options{plugindir}, 70 63 dirname($0), 71 split( /\s+/, $obsdata->{config}->val('global', 'plugindir') || ''),64 split( /\s+/, $obsdata->{config}->val( 'global', 'plugindir' ) || '' ), 72 65 ); 73 66 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 ); 77 71 } 78 72 … … 80 74 my ($self) = @_; 81 75 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} ); 89 80 $self->{loghandle} = undef; 90 81 } … … 100 91 my ($self) = @_; 101 92 102 if ( !open($self->{loghandle}, ">> $self->{logfile}")) {93 if ( !open( $self->{loghandle}, ">> $self->{logfile}" ) ) { 103 94 $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}" ); 105 97 return 0; 106 98 } 107 99 108 $self->logging(0, "BEGIN process: %s (%s)", 109 $VERSION, 110 $CVSID, 111 ); 100 $self->logging( 0, "BEGIN process: %s (%s)", $VERSION, $CVSID, ); 112 101 113 102 my $path = `pwd`; 114 103 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, 118 108 ); 119 109 120 110 $self->load_plugins() or return 0; 121 111 122 112 return 1; 123 113 } … … 131 121 sub load_plugins { 132 122 my ($self) = @_; 133 134 $self->logging(0, 123 124 $self->logging( 125 0, 135 126 "Plugin will be searched in: %s", 136 join( ', ', @{$self->{plugindir}}),127 join( ', ', @{ $self->{plugindir} } ), 137 128 ); 138 139 foreach my $datatype ( $self->list_datatype()) {129 130 foreach my $datatype ( $self->list_datatype() ) { 140 131 foreach my $plugin (qw/match_plugin/) { 141 my ( $plugfile, @plugarg) =142 split(/\s+/, $self->getvalue($datatype, $plugin) ||'');143 $plugfile or next; # if no plugin, skipping132 my ( $plugfile, @plugarg ) = 133 split( /\s+/, $self->getvalue( $datatype, $plugin ) || '' ); 134 $plugfile or next; # if no plugin, skipping 144 135 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, ); 153 140 return 0; 154 141 } 155 142 my $sub = do $plugfilename; 156 143 if ($@) { 157 $self->logging( 4,144 $self->logging( 4, 158 145 "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', 162 161 ); 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 );183 162 } 184 163 } … … 194 173 195 174 sub 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} ) ) { 198 177 my $ref = $self->{plugin}{$datatype}{$plugintype}; 199 return($ref->{code}, @{$ref->{arg}}); 200 } else { 178 return ( $ref->{code}, @{ $ref->{arg} } ); 179 } 180 else { 201 181 return undef; 202 182 } … … 213 193 214 194 sub 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 ); 217 197 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} ) { 222 202 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; 231 209 } 232 210 … … 240 218 my $l = pop(@_); 241 219 defined($l) or $l = pop(@_); 242 return $loglevel[ $l] || "?????";220 return $loglevel[$l] || "?????"; 243 221 } 244 222 … … 254 232 my ($self) = @_; 255 233 my $result = 1; 256 foreach my $g ( $self->{config}->GroupMembers('Obs')) {234 foreach my $g ( $self->{config}->GroupMembers('Obs') ) { 257 235 my ($obs) = $g =~ /\S+\s+(.*)/; 258 if ( !$self->{config}->SectionExists($obs)) {236 if ( !$self->{config}->SectionExists($obs) ) { 259 237 print STDERR "E: '$obs' is listed as Obs but it does not exists\n"; 260 238 next; 261 239 } 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 ) { 265 243 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 268 247 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, $@, ); 274 250 $result = 0; 251 275 252 # TODO set this reg unavalable 276 253 } … … 278 255 } 279 256 } 280 return ($result);257 return ($result); 281 258 } 282 259 … … 288 265 289 266 sub 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 ); 292 269 } 293 270 … … 300 277 sub config_mtime { 301 278 my ($self) = @_; 302 return $self->{configmtime} ||= ( stat($self->{config}->GetFileName))[9];279 return $self->{configmtime} ||= ( stat( $self->{config}->GetFileName ) )[9]; 303 280 } 304 281 … … 312 289 my ($self) = @_; 313 290 grep { $self->{config}->SectionExists($_) } 314 map { s/^\S+\s+//; $_ } 315 $self->{config}->GroupMembers('Obs'); 291 map { s/^\S+\s+//; $_ } $self->{config}->GroupMembers('Obs'); 316 292 } 317 293 … … 323 299 324 300 sub 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') ); 327 303 } 328 304 … … 334 310 335 311 sub list_obsdatadir { 336 my ( $self, $obs) = @_;312 my ( $self, $obs ) = @_; 337 313 $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); 341 320 } 342 321 … … 348 327 349 328 sub list_typedatadir { 350 my ( $self, $type) = @_;329 my ( $self, $type ) = @_; 351 330 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 357 336 } 358 337 … … 364 343 365 344 sub get_datadir { 366 my ( $self, $obs, $type) = @_;345 my ( $self, $obs, $type ) = @_; 367 346 $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 ); 369 351 } 370 352 … … 378 360 my ($self) = @_; 379 361 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; 382 364 } 383 365 … … 391 373 392 374 sub 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)' ); 401 382 return undef; 402 383 } 403 384 my $or = ObsData::Repository::dir->new( 404 385 { 405 obsdata => $self,406 dir => $dir,407 obs => $obs,386 obsdata => $self, 387 dir => $dir, 388 obs => $obs, 408 389 datatype => $datatype, 409 390 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" ) 413 393 ), 414 394 statusfile => $self->getvalue( 415 $obs, 416 ($datatype ? "index/$datatype" : "index"), 395 $obs, ( $datatype ? "index/$datatype" : "index" ), 417 396 "$dir/obsdata.ini" 418 397 ), 419 398 } 420 399 ); 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 ); 423 402 return undef; 424 403 } 425 426 return ($or);404 405 return ($or); 427 406 } 428 407 … … 434 413 435 414 sub process_obs { 436 my ( $self, $obs) = @_;415 my ( $self, $obs ) = @_; 437 416 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 ); 442 421 $or or next; 443 422 $or->process; … … 446 425 447 426 sub 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} }, 450 430 { 451 obs => $obs,452 archive => $archive,431 obs => $obs, 432 archive => $archive, 453 433 datafile => $datafile, 454 434 datatype => $datatype, … … 456 436 } 457 437 ); 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); 464 441 } 465 442 … … 467 444 my ($self) = @_; 468 445 my $result = { 469 all => [],446 all => [], 470 447 users => {}, 471 448 }; 472 449 473 foreach my $entry ( @{$self->{processed_lists}}) {450 foreach my $entry ( @{ $self->{processed_lists} } ) { 474 451 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 ) 478 460 ), 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 ) 481 467 ); 482 468 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} || {} } ) ) { 489 475 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 ) { 495 481 my %datatype_entries = (); 496 foreach ( @{$obs_entries{$obs}}) {497 push( @{$datatype_entries{$_->{datatype} || '!'}}, $_);482 foreach ( @{ $obs_entries{$obs} } ) { 483 push( @{ $datatype_entries{ $_->{datatype} || '!' } }, $_ ); 498 484 } 499 485 500 486 my %msg = ( 501 Subject => 'ObsData Report: ' . $obs,502 To => $p,487 Subject => 'ObsData Report: ' . $obs, 488 To => $p, 503 489 'X-ObsData-Version' => $VERSION, 504 'Content-Type' => "TEXT/PLAIN;\n charset=ISO-8859-1",490 'Content-Type' => "TEXT/PLAIN;\n charset=ISO-8859-1", 505 491 'Content-Transfer-Encoding' => 'QUOTED-PRINTABLE', 506 492 From => 'ObsData <robot@aero.jussieu.fr>', 507 493 ); 508 494 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 '!' ) { 511 497 $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}, ); 526 501 } 527 502 } 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 } 528 510 } 529 511 sendmail( 530 512 %msg, 531 smtp => 'mailhost',513 smtp => 'mailhost', 532 514 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", 534 518 $msg{To}, $Mail::Sendmail::error, 535 );519 ); 536 520 } 537 521 } … … 542 526 my ($self) = @_; 543 527 my %datastype; 544 foreach my $entry ( @{$self->{processed_lists}}) {528 foreach my $entry ( @{ $self->{processed_lists} } ) { 545 529 $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', 554 538 ); 555 539 if ($command) { 556 if ( open(my $posthandle, "| $command")) {557 foreach ( @{$datastype{$datatype}}) {540 if ( open( my $posthandle, "| $command" ) ) { 541 foreach ( @{ $datastype{$datatype} } ) { 558 542 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, $!, ); 563 546 last; 564 547 }; 565 548 } 566 549 my $exitstatus = close($posthandle); 567 $self->logging($exitstatus ? 0 : 4, 550 $self->logging( 551 $exitstatus ? 0 : 4, 568 552 "postexec for %s exit %s", 569 553 $datatype, 570 $exitstatus ? "correctly" : "with failure : " . ($! ? ($!) : "(??)"), 554 $exitstatus 555 ? "correctly" 556 : "with failure : " . ( $! ? ($!) : "(??)" ), 571 557 ); 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, ); 577 562 next; 578 563 } … … 593 578 594 579 =cut 580 -
obsdata/trunk/ObsData/Archive.pm
r240 r274 13 13 14 14 our $CVSID = q$Id$; 15 our $CVSREV = ( q$Revision$ =~ /^Revision: (.*) $/)[0];15 our $CVSREV = ( q$Revision$ =~ /^Revision: (.*) $/ )[0]; 16 16 17 17 my $error = {}; … … 20 20 21 21 sub register { 22 my ( $rule, $class, $priority) = @_;22 my ( $rule, $class, $priority ) = @_; 23 23 push( 24 24 @ObsData::Archive::dynload, 25 25 { 26 rule => $rule,27 class => $class,26 rule => $rule, 27 class => $class, 28 28 priority => $priority, 29 29 } … … 35 35 my ($module) = @_; 36 36 eval { require $module }; 37 return ($@ ? 0 : 1);37 return ( $@ ? 0 : 1 ); 38 38 } 39 39 40 40 sub new { 41 my ( $class, $archive, %options) = @_;41 my ( $class, $archive, %options ) = @_; 42 42 my $beclass; 43 43 44 if ( !$archive) {44 if ( !$archive ) { 45 45 seterror("No archive to read"); 46 46 return undef; 47 47 } 48 if ( !-r $archive) {48 if ( !-r $archive ) { 49 49 seterror("No such file or directory"); 50 50 return undef; 51 51 } 52 52 my $o; 53 54 foreach ( keys %options) {53 54 foreach ( keys %options ) { 55 55 $o->{$_} = $options{$_}; 56 56 } 57 57 $o->{archive} = $archive; 58 58 59 59 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 { 64 69 $beclass = $r->{class}; 65 70 last; … … 67 72 } 68 73 } 69 74 70 75 if ($beclass) { 71 76 my $obj; 77 72 78 # eval("require $class\:\:$beclass;"); 73 79 eval("\$obj = $class\:\:$beclass->new(\$o);"); … … 83 89 84 90 sub seterror { 85 my ( $package, $filename, $line) = caller;91 my ( $package, $filename, $line ) = caller; 86 92 $error = { 87 'package' => $package,93 'package' => $package, 88 94 'filename' => $filename, 89 'line' => $line,90 'error' => $_[1] || $_[0],95 'line' => $line, 96 'error' => $_[1] || $_[0], 91 97 }; 92 98 } … … 97 103 98 104 sub new { 99 my ( $class, $o) = @_;100 bless( $o, $class);105 my ( $class, $o ) = @_; 106 bless( $o, $class ); 101 107 } 102 108 … … 107 113 sub ls { 108 114 my ($self) = @_; 109 seterror( "ls not implement in class " . ref($self));115 seterror( "ls not implement in class " . ref($self) ); 110 116 return; 111 117 } 112 118 113 119 sub 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) ); 116 122 return; 117 123 } … … 121 127 sub _tempdir { 122 128 my ($self) = @_; 123 $self->{tmpdir} || $ENV{TMPDIR} 129 $self->{tmpdir} || $ENV{TMPDIR}; 124 130 } 125 131 -
obsdata/trunk/ObsData/Archive/Compressed.pm
r164 r274 12 12 13 13 sub new { 14 my ( $class, $options) = @_;14 my ( $class, $options ) = @_; 15 15 16 if ( !$options->{uncomp}) {17 for ( $options->{archive}) {16 if ( !$options->{uncomp} ) { 17 for ( $options->{archive} ) { 18 18 /\.(Z|gz)$/ and $options->{uncomp} = 'gzip -dc'; 19 /\.bz2$/ and $options->{uncomp} = 'bzip2 -dc';19 /\.bz2$/ and $options->{uncomp} = 'bzip2 -dc'; 20 20 } 21 21 } 22 23 bless( $options, $class);22 23 bless( $options, $class ); 24 24 } 25 25 … … 35 35 36 36 sub extract { 37 my ($self, $file, $dest) = @_; 37 my ( $self, $file, $dest ) = @_; 38 38 39 # the devel should specify the file he want 39 40 # as the basic contains only 1 file... this does not matter 40 41 41 my ( $fh, $fname);42 42 my ( $fh, $fname ); 43 43 44 if ($dest) { 44 45 $fname = $dest; 45 open( $fh, '>', $dest) or do {46 open( $fh, '>', $dest ) or do { 46 47 $self->seterror("Can't uncompress archive: $!"); 47 48 return undef; 48 49 }; 49 } else { 50 ($fh, $fname) = tempfile( 51 DIR => $self->_tempdir, 50 } 51 else { 52 ( $fh, $fname ) = tempfile( 53 DIR => $self->_tempdir, 52 54 UNLINK => 1, 53 ) or do { 55 ) 56 or do { 54 57 $self->seterror("Can't create temp file: $!"); 55 58 return undef; 56 };59 }; 57 60 } 58 61 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 ) ) { 62 66 $self->seterror("Can't copy file to destination: $!"); 63 67 unlink($fname); 64 68 return undef; 65 69 } 66 70 67 71 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" . ( $! ? ( " " . $! ) : "" ) ); 70 75 unlink($fname); 71 76 return undef; 72 77 } 73 $fname 78 $fname; 74 79 } 75 80 76 ObsData::Archive::register(sub { $_[0] =~ /\.(gz|Z|bz2)$/i }, 'Compressed', 5); 81 ObsData::Archive::register( sub { $_[0] =~ /\.(gz|Z|bz2)$/i }, 'Compressed', 82 5 ); -
obsdata/trunk/ObsData/Archive/FlatFile.pm
r164 r274 12 12 13 13 sub new { 14 my ( $class, $options) = @_;15 bless( $options, $class);14 my ( $class, $options ) = @_; 15 bless( $options, $class ); 16 16 } 17 17 … … 27 27 28 28 sub extract { 29 my ($self, $file, $dest) = @_; 29 my ( $self, $file, $dest ) = @_; 30 30 31 # the devel should specify the file he want 31 32 # as the basic contains only 1 file... this does not matter 32 33 33 my ( $fh, $fname);34 34 my ( $fh, $fname ); 35 35 36 if ($dest) { 36 37 $fname = $dest; 37 if (!open($fh, '>', $dest)) {38 if ( !open( $fh, '>', $dest ) ) { 38 39 $self->seterror($!); 39 40 return undef; 40 41 } 41 } else { 42 ($fh, $fname) = tempfile( 43 DIR => $self->_tempdir, 42 } 43 else { 44 ( $fh, $fname ) = tempfile( 45 DIR => $self->_tempdir, 44 46 UNLINK => 1, 45 ) or do { 47 ) 48 or do { 46 49 $self->seterror("Can't create tempfile: $!"); 47 50 return undef; 48 };51 }; 49 52 } 50 51 if (!copy($self->{archive}, $fh)) {53 54 if ( !copy( $self->{archive}, $fh ) ) { 52 55 unlink($fname); 53 56 $self->seterror("Cant copy the archive: $!"); 54 57 return undef; 55 58 } 56 59 57 60 close($fh); 58 $fname 61 $fname; 59 62 } 60 63 61 ObsData::Archive::register( '.*', 'FlatFile', 10);64 ObsData::Archive::register( '.*', 'FlatFile', 10 ); -
obsdata/trunk/ObsData/Archive/Lha.pm
r247 r274 12 12 13 13 sub new { 14 my ( $class, $options) = @_;15 bless( $options, $class);14 my ( $class, $options ) = @_; 15 bless( $options, $class ); 16 16 } 17 17 … … 22 22 sub ls { 23 23 my ($self) = @_; 24 open( my $hlha, '-|', "lha '$self->{archive}'") or do {24 open( my $hlha, '-|', "lha '$self->{archive}'" ) or do { 25 25 $self->seterror("Can't read lha/lzh file: $!"); 26 26 return undef; … … 29 29 <$hlha>; 30 30 <$hlha> =~ /^-{9}/ or return; 31 while (<$hlha>) {31 while (<$hlha>) { 32 32 chomp; 33 33 /^(\[\w*\]|(-|d|l|c|b)((-|r)(-|w)(-|x)){3} [^-])/ or next; 34 34 /^.{51}(.*)$/; 35 push( @list, $1);35 push( @list, $1 ); 36 36 } 37 37 close($hlha); … … 40 40 41 41 sub extract { 42 my ( $self, $file, $dest) = @_;43 42 my ( $self, $file, $dest ) = @_; 43 44 44 $file or return undef; 45 45 46 46 my $dir = tempdir(); 47 47 48 if ( system("lha xfw=$dir '$self->{archive}' '$file'")) {49 50 48 if ( system("lha xfw=$dir '$self->{archive}' '$file'") ) { 49 $self->seterror("Can't uncompress archive: $!"); 50 return undef; 51 51 } 52 52 53 53 if ($dest) { 54 open( my $fh, '>', $dest) or do {54 open( my $fh, '>', $dest ) or do { 55 55 $self->seterror("Can't uncompress archive: $!"); 56 56 return undef; 57 57 }; 58 open( my $sourcefh, '<', "$dir/$file") or do {58 open( my $sourcefh, '<', "$dir/$file" ) or do { 59 59 $self->seterror("Can't open temp file for reading: $!"); 60 60 return undef; 61 61 }; 62 62 63 if (!copy($sourcefh, $fh)) {63 if ( !copy( $sourcefh, $fh ) ) { 64 64 $self->seterror("Can't copy file to destination: $!"); 65 65 unlink("$dir/$file"); … … 69 69 close($sourcefh); 70 70 } 71 71 72 72 return $dest || "$dir/$file"; 73 73 } 74 74 75 ObsData::Archive::register( sub { $_[0] =~ /\.(lzh|lha)$/i }, 'Lha', 0);75 ObsData::Archive::register( sub { $_[0] =~ /\.(lzh|lha)$/i }, 'Lha', 0 ); -
obsdata/trunk/ObsData/Archive/Rar.pm
r247 r274 12 12 13 13 sub new { 14 my ( $class, $options) = @_;15 bless( $options, $class);14 my ( $class, $options ) = @_; 15 bless( $options, $class ); 16 16 } 17 17 … … 22 22 sub ls { 23 23 my ($self) = @_; 24 open( my $hrar, '-|', "unrar lb '$self->{archive}'") or do {24 open( my $hrar, '-|', "unrar lb '$self->{archive}'" ) or do { 25 25 $self->seterror("Can't read rar file: $!"); 26 26 return undef; 27 27 }; 28 28 my @list; 29 while (<$hrar>) {29 while (<$hrar>) { 30 30 chomp; 31 push( @list, $_);31 push( @list, $_ ); 32 32 } 33 33 close($hrar); … … 36 36 37 37 sub extract { 38 my ( $self, $file, $dest) = @_;38 my ( $self, $file, $dest ) = @_; 39 39 40 40 $file or return undef; 41 42 my ( $fh, $fname);43 41 42 my ( $fh, $fname ); 43 44 44 if ($dest) { 45 45 $fname = $dest; 46 open( $fh, '>', $dest) or do {46 open( $fh, '>', $dest ) or do { 47 47 $self->seterror("Can't uncompress archive: $!"); 48 48 return undef; 49 49 }; 50 } else { 51 ($fh, $fname) = tempfile( 52 DIR => $self->_tempdir, 50 } 51 else { 52 ( $fh, $fname ) = tempfile( 53 DIR => $self->_tempdir, 53 54 UNLINK => 1, 54 ) or do { 55 ) 56 or do { 55 57 $self->seterror("Can't create temp file: $!"); 56 58 return undef; 57 };59 }; 58 60 } 59 61 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 ) ) { 63 67 $self->seterror("Can't copy file to destination: $!"); 64 68 unlink($fname); 65 69 return undef; 66 70 } 67 71 68 72 close($fh); 73 69 74 # 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" . ( $! ? ( " " . $! ) : "" ) ); 72 78 unlink($fname); 73 79 return undef; 74 80 } 75 $fname 81 $fname; 76 82 } 77 83 78 ObsData::Archive::register( sub { $_[0] =~ /\.rar$/i }, 'Rar', 0);84 ObsData::Archive::register( sub { $_[0] =~ /\.rar$/i }, 'Rar', 0 ); -
obsdata/trunk/ObsData/Archive/Tar.pm
r247 r274 13 13 14 14 sub new { 15 my ( $class, $options) = @_;15 my ( $class, $options ) = @_; 16 16 17 if ( !$options->{uncomp}) {18 for ( $options->{archive}) {17 if ( !$options->{uncomp} ) { 18 for ( $options->{archive} ) { 19 19 /\.(Z|gz)$/ and $options->{uncomp} = 'gzip -dc'; 20 /\.bz2$/ and $options->{uncomp} = 'bzip2 -dc';20 /\.bz2$/ and $options->{uncomp} = 'bzip2 -dc'; 21 21 } 22 22 } 23 23 $options->{uncomp} ||= 'cat'; 24 bless( $options, $class);24 bless( $options, $class ); 25 25 } 26 26 … … 31 31 sub ls { 32 32 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 { 34 35 seterror("Can't read tar file: $!"); 35 36 return undef; 36 };37 }; 37 38 my @list; 38 while (<$htar>) {39 while (<$htar>) { 39 40 chomp; 40 push( @list, $_);41 push( @list, $_ ); 41 42 } 42 43 close($htar); … … 45 46 46 47 sub extract { 47 my ( $self, $file, $dest) = @_;48 my ( $self, $file, $dest ) = @_; 48 49 49 50 $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} ); 54 55 my $abs_dest = Cwd::abs_path($dest); 55 56 if (!chdir($tempdir)) {56 57 if ( !chdir($tempdir) ) { 57 58 $self->seterror("Can't chdir: $!"); 58 59 return undef; … … 64 65 return undef; 65 66 }; 66 67 67 68 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 ) ) { 70 71 $self->seterror("Can't copy file to destination: $!"); 71 72 unlink($abs_dest); … … 77 78 chdir($here); 78 79 return $dest; 79 } else { 80 } 81 else { 80 82 chdir($here); 81 83 return "$tempdir/$file"; … … 86 88 sub { 87 89 $_[0] =~ /\.tar\.(gz|bz2|Z)$/i; 88 }, 89 'Tar', 90 }, 91 'Tar', 90 92 0 91 93 ); -
obsdata/trunk/ObsData/Archive/Zip.pm
r247 r274 12 12 13 13 sub new { 14 my ( $class, $options) = @_;15 bless( $options, $class);14 my ( $class, $options ) = @_; 15 bless( $options, $class ); 16 16 } 17 17 … … 22 22 sub ls { 23 23 my ($self) = @_; 24 open( my $hzip, '-|', "zipinfo -1 '$self->{archive}'") or do {24 open( my $hzip, '-|', "zipinfo -1 '$self->{archive}'" ) or do { 25 25 $self->seterror("Can't read zip file: $!"); 26 26 return undef; 27 27 }; 28 28 my @list; 29 while (<$hzip>) {29 while (<$hzip>) { 30 30 chomp; 31 push( @list, $_);31 push( @list, $_ ); 32 32 } 33 33 close($hzip); … … 36 36 37 37 sub extract { 38 my ( $self, $file, $dest) = @_;38 my ( $self, $file, $dest ) = @_; 39 39 40 40 $file or return undef; 41 42 my ( $fh, $fname);43 41 42 my ( $fh, $fname ); 43 44 44 if ($dest) { 45 45 $fname = $dest; 46 open( $fh, '>', $dest) or do {46 open( $fh, '>', $dest ) or do { 47 47 $self->seterror("Can't uncompress archive: $!"); 48 48 return undef; 49 49 }; 50 } else { 51 ($fh, $fname) = tempfile( 52 DIR => $self->_tempdir, 50 } 51 else { 52 ( $fh, $fname ) = tempfile( 53 DIR => $self->_tempdir, 53 54 UNLINK => 1, 54 ) or do { 55 ) 56 or do { 55 57 $self->seterror("Can't create temp file: $!"); 56 58 return undef; 57 };59 }; 58 60 } 59 61 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 ) ) { 63 66 $self->seterror("Can't copy file to destination: $!"); 64 67 unlink($fname); 65 68 return undef; 66 69 } 67 70 68 71 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" . ( $! ? ( " " . $! ) : "" ) ); 71 75 unlink($fname); 72 76 return undef; … … 76 80 } 77 81 78 ObsData::Archive::register( sub { $_[0] =~ /\.zip$/i }, 'Zip', 5);82 ObsData::Archive::register( sub { $_[0] =~ /\.zip$/i }, 'Zip', 5 ); -
obsdata/trunk/ObsData/Event.pm
r167 r274 31 31 32 32 sub new { 33 my ( $class, $id, $message) = @_;34 35 if (!($id && $message)) {33 my ( $class, $id, $message ) = @_; 34 35 if ( !( $id && $message ) ) { 36 36 return undef; 37 37 } 38 38 39 39 bless( 40 40 { 41 id => $id,42 message => $message,43 test => {},41 id => $id, 42 message => $message, 43 test => {}, 44 44 test_order => [], 45 45 }, … … 56 56 sub id { 57 57 my ($self) = @_; 58 return ($self->{id});58 return ( $self->{id} ); 59 59 } 60 60 … … 67 67 sub message { 68 68 my ($self) = @_; 69 return ($self->{message});69 return ( $self->{message} ); 70 70 } 71 71 … … 77 77 78 78 sub 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 ); 82 82 } 83 83 $self->{test}{$test_id}{message} ||= $message; … … 93 93 sub list_test { 94 94 my ($self) = @_; 95 return (@{$self->{test_order}});95 return ( @{ $self->{test_order} } ); 96 96 } 97 97 … … 103 103 104 104 sub 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} ); 107 107 } 108 108 … … 114 114 115 115 sub 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} ); 118 118 } 119 119 -
obsdata/trunk/ObsData/Repository.pm
r272 r274 14 14 15 15 our $CVSID = q$Id$; 16 our $CVSREV = ( q$Revision$ =~ /^Revision: (.*) $/)[0];16 our $CVSREV = ( q$Revision$ =~ /^Revision: (.*) $/ )[0]; 17 17 18 18 =head1 METHODS … … 67 67 68 68 sub 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 ) { 73 73 $or->{$_} = $param{$_}; 74 74 } 75 75 76 76 $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 80 80 $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 82 87 # -default => '.', # Is this a good idea 83 88 ); 84 $or->{statusfile} ||= $or->{status}->GetFileName;89 $or->{statusfile} ||= $or->{status}->GetFileName; 85 90 $or->{interactive_callback} ||= $or->{obsdata}->{interactive_callback}; 86 91 87 bless( $or, $class);92 bless( $or, $class ); 88 93 89 94 $or; … … 92 97 sub DESTROY { 93 98 my ($self) = @_; 94 $self->logging( 0, "Destroy ObsData::Repository for %s", ref($self));99 $self->logging( 0, "Destroy ObsData::Repository for %s", ref($self) ); 95 100 $self->save_status; 96 101 } … … 103 108 104 109 sub mydir { 105 $_[0]->{dir} 110 $_[0]->{dir}; 106 111 } 107 112 … … 115 120 my ($self) = @_; 116 121 $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), ); 122 125 123 126 my $hostname = `hostname`; 124 127 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' ); 145 139 } 146 140 … … 154 148 my ($self) = @_; 155 149 $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}, ); 161 152 $self->update_global_status; 162 $self->{status}->WriteConfig( $self->{statusfile});153 $self->{status}->WriteConfig( $self->{statusfile} ); 163 154 } 164 155 } … … 172 163 173 164 sub dump_status { 174 my ( $self, $output) = @_;165 my ( $self, $output ) = @_; 175 166 $self->update_global_status; 176 167 $self->{status}->WriteConfig($output); … … 203 194 204 195 sub 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 ); 210 201 } 211 202 … … 220 211 my @files; 221 212 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}, ); 227 215 return; 228 216 } 229 217 230 218 my $patern = $self->{patern} || '*'; 231 foreach my $f ( glob("$self->{dir}/$patern")) {232 233 -f $f or next; # skip no regular files234 $f =~ m/obsdata\.ini$/ and next; # avoid default status file235 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 236 224 my $bf = $f; 237 225 $bf =~ s!^\Q$self->{dir}\E/*!!; 238 push( @files, $bf);239 } 240 @files 226 push( @files, $bf ); 227 } 228 @files; 241 229 } 242 230 … … 250 238 my ($self) = @_; 251 239 252 grep { $_ ne '.' } $self->{status}->Sections 240 grep { $_ ne '.' } $self->{status}->Sections; 253 241 } 254 242 … … 261 249 sub process { 262 250 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 298 282 $orda->ask_user($oe) or next; 299 283 300 284 $orda->process; 301 285 } … … 304 288 sub get_archives_from_status { 305 289 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(); 312 292 } 313 293 … … 337 317 338 318 sub 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 342 323 # dir directory to parse 343 324 $or->{archivefile} or die "No archivefile given"; … … 345 326 # $or->{interactive_callback} 346 327 $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 ); 355 333 } 356 334 357 335 sub DESTROY { 358 336 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; 362 340 } 363 341 } … … 370 348 371 349 sub archivefile { 372 $_[0]->{archivefile} 350 $_[0]->{archivefile}; 373 351 } 374 352 … … 381 359 sub load_archive { 382 360 my ($self) = @_; 383 if ( $self->{Oarchive}) {361 if ( $self->{Oarchive} ) { 384 362 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} ); 392 370 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 ); 399 375 return 0; 400 376 } … … 411 387 sub archive { 412 388 my ($self) = @_; 413 if ( $self->load_archive()) {389 if ( $self->load_archive() ) { 414 390 return $self->{Oarchive}; 415 } else { 391 } 392 else { 416 393 return undef; 417 394 } … … 425 402 426 403 sub 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 ); 429 406 } 430 407 … … 436 413 437 414 sub 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, $comment445 ) 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) ); 446 423 $self->{status_changed} = 1; 447 424 } … … 454 431 455 432 sub 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 ); 461 436 } 462 437 … … 468 443 469 444 sub 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 ); 476 447 } 477 448 … … 488 459 489 460 sub default_choice { 490 my ( $self, $oevent) = @_;491 492 for ( $oevent->id) {461 my ( $self, $oevent ) = @_; 462 463 for ( $oevent->id ) { 493 464 /^do_archive$/ and do { 494 return ($oevent->test_result('archive_exists') ? 0 : 1);465 return ( $oevent->test_result('archive_exists') ? 0 : 1 ); 495 466 last; 496 467 }; 497 468 /^do_data$/ and do { 498 return 1; # TODO469 return 1; # TODO 499 470 last; 500 471 }; 501 472 /^overwrite$/ and do { 502 return ($oevent->test_result('dest_exists') ? 0 : 1);473 return ( $oevent->test_result('dest_exists') ? 0 : 1 ); 503 474 last; 504 475 }; … … 514 485 515 486 sub 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", 523 493 $_, 524 494 $oevent->test_message($_), … … 528 498 529 499 my $res = 530 $self->{interactive_callback} ?531 $self->{interactive_callback}->($self, $oevent) :532 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); 536 506 } 537 507 … … 544 514 sub list_archive { 545 515 my ($self) = @_; 546 if ( my $archive = $self->archive) {516 if ( my $archive = $self->archive ) { 547 517 return $archive->ls(); 548 } else { 518 } 519 else { 549 520 return undef; 550 521 } … … 560 531 my ($self) = @_; 561 532 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 ); 566 537 } 567 538 … … 575 546 576 547 sub 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; 580 553 my @data = $datafile =~ /$regexp/; 581 554 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 583 558 # if no regexp => return undef 584 559 # 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 ); 588 566 } 589 567 } … … 597 575 598 576 sub 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; 601 580 my @data = $self->{archivefile} =~ /$regexp/; 602 581 return @data; … … 613 592 614 593 sub get_info_from_plugin { 615 my ( $self, $datatype, $datafile) = @_;616 594 my ( $self, $datatype, $datafile ) = @_; 595 617 596 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' ); 623 600 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, ); 636 605 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), ); 653 614 return undef; 654 615 } 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, ); 661 620 return 0; 662 621 } 663 } else { 622 } 623 else { 664 624 return undef; 665 625 } … … 678 638 679 639 sub 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 ) { 684 644 return; 685 645 } 686 646 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' ) || '' ); 693 657 my @gmtime = gmtime; 694 658 … … 699 663 $val{$_} = shift(@$dataar); 700 664 } 665 701 666 # FIXME Is this need ? 702 667 # foreach (keys %{$magic_words || {}}) { 703 668 # $val{'$' . $_} = $magic_words->{$_}; 704 669 #} 705 706 $val{'$datafile'} = $datafile;670 671 $val{'$datafile'} = $datafile; 707 672 $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, 712 677 ); 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", 715 682 $dest, 716 join(", ", map { m/^%/ ? strftime($_, @gmtime) : $val{$_} } @destarg) 683 join( ", ", 684 map { m/^%/ ? strftime( $_, @gmtime ) : $val{$_} } @destarg ) 717 685 ); 718 return ();719 } 720 return ($datatype, $destfile);686 return (); 687 } 688 return ( $datatype, $destfile ); 721 689 } 722 690 … … 730 698 731 699 sub 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, 741 706 $t || '(none)', 742 707 $d || '(none)', 743 708 ); 744 709 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 ); 748 713 } 749 714 … … 762 727 763 728 sub extract_data { 729 764 730 # $datatype, informationnal only here 765 my ( $self, $datafile, $datatype, $destfile) = @_;731 my ( $self, $datafile, $datatype, $destfile ) = @_; 766 732 $self->load_archive or return 0; 767 733 my $ltime = time; … … 771 737 'processtime', 772 738 $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", 775 741 ); 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, ); 792 749 return 0; 793 750 } 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 ) ); 803 758 $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 { 821 772 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, $@ ); 828 776 return 0; 829 777 } … … 831 779 } 832 780 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 { 851 793 $self->logging( 852 794 4, "Can't extract %s/%s to %s: %s", … … 857 799 } 858 800 } 859 801 860 802 return 1; 861 803 } … … 870 812 my ($self) = @_; 871 813 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 882 823 $self->ask_user($oe) or next; 883 824 884 $self->extract_data( $data, $self->get_data_dest($data));885 } 886 825 $self->extract_data( $data, $self->get_data_dest($data) ); 826 } 827 887 828 $self->update_status; 888 829 … … 892 833 sub list_data_from_status { 893 834 my ($self) = @_; 894 map { m/data_processtime_(.*)/; $1 } grep {895 $_ && index($_, 'data_processtime_') == 0896 } $self->{status}->Parameters($self->{archivefile})835 map { m/data_processtime_(.*)/; $1 } 836 grep { $_ && index( $_, 'data_processtime_' ) == 0 } 837 $self->{status}->Parameters( $self->{archivefile} ); 897 838 } 898 839 899 840 sub 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' ); 902 843 } 903 844
Note: See TracChangeset
for help on using the changeset viewer.