Legend:
- Unmodified
- Added
- Removed
-
shepherd
r183 r190 22 22 # (e.g. flag HDTV programmes, augment with IMDb etc.) 23 23 24 my $version = '0.2.3 2';24 my $version = '0.2.33'; 25 25 26 26 # Changelog: … … 56 56 # 0.2.31 : split tv_grab_au (install/test/upgrade/enable/disable) from 57 57 # shepherd (grab/reconcile/postprocess) 58 # 0.2.33 : remove logging (tv_grab_au does it for us) 58 59 59 60 BEGIN { *CORE::GLOBAL::die = \&my_die; } … … 133 134 my $config_file = "$CWD/$progname.conf"; 134 135 my $channels_file = "$CWD/channels.conf"; 135 my $log_file = "$CWD/$progname.log";136 136 my $days = 7; 137 137 my $missing; … … 172 172 173 173 &get_remaining_command_line_options; 174 &open_logfile unless ($opt->{nolog});175 174 176 175 &process_setup_commands; … … 190 189 } 191 190 192 &log("Done.\n");193 &close_logfile() unless $opt->{nolog};194 195 191 # --------------------------------------------------------------------------- 196 192 # --- Subroutines … … 205 201 my $used_grabbers = 0; 206 202 207 &log("\nGrabber stage.\n");203 printf "\nGrabber stage.\n"; 208 204 209 205 &analyze_plugin_data("",1); … … 216 212 $components->{$grabber}->{laststatus} = "unknown"; 217 213 218 &log((sprintf "\nSHEPHERD: Using grabber: (%d) %s\n", $used_grabbers, $grabber));214 printf "\nSHEPHERD: Using grabber: (%d) %s\n", $used_grabbers, $grabber; 219 215 220 216 my $output = "$CWD/grabbers/$grabber/output.xmltv"; … … 230 226 if (query_config($grabber, 'category') == 1) 231 227 { 232 &log("$grabber is Category 1: grabbing timeslice.\n")if ($debug);228 printf "$grabber is Category 1: grabbing timeslice.\n" if ($debug); 233 229 234 230 record_requested_chandays($grabber, $timeslice); … … 266 262 else 267 263 { 268 &log("$grabber is category 2: grabbing everything.\n")if ($debug);264 printf "$grabber is category 2: grabbing everything.\n" if ($debug); 269 265 $comm .= " --days $days" if ($days); 270 266 $comm .= " --offset $opt->{offset}" if ($opt->{offset}); … … 276 272 my $retval = 0; 277 273 if ((defined $opt->{dontcallgrabbers}) && ($opt->{dontcallgrabbers})) { 278 &log("SHEPHERD: not calling grabber because of --dontcallgrabbers option, but will instead use existing $output\n");279 &log("SHEPHERD: would have called: $comm\n")if ($debug);274 printf "SHEPHERD: not calling grabber because of --dontcallgrabbers option, but will instead use existing $output\n"; 275 printf "SHEPHERD: would have called: $comm\n" if ($debug); 280 276 } else { 281 &log("SHEPHERD: Excuting command: $comm\n");277 printf "SHEPHERD: Excuting command: $comm\n"; 282 278 chdir "$CWD/grabbers/$grabber/"; 283 279 $retval = call_prog($comm); … … 286 282 287 283 if ($retval != 0) { 288 &log("grabber returned with non-zero return code $retval: assuming it failed.\n");284 printf "grabber returned with non-zero return code $retval: assuming it failed.\n"; 289 285 next; 290 286 } … … 305 301 my $list = List::Compare->new($missing_before, $missing_after); 306 302 my @grabbed = $list->get_symmetric_difference(); 307 &log("Grabbed: " . join (', ', @grabbed) . ".\n")if ($debug);303 printf "Grabbed: " . join (', ', @grabbed) . ".\n" if ($debug); 308 304 record_cached($grabber, @grabbed); 309 305 write_config_file(); … … 316 312 if ($used_grabbers == 0) 317 313 { 318 &log("No valid grabbers installed/enabled!\n");314 printf "No valid grabbers installed/enabled!\n"; 319 315 return; 320 316 } … … 322 318 unless ($grabber_found_all_data) 323 319 { 324 &log("SHEPHERD: Ran through ALL grabbers but still missing data!!! :(\n");320 printf "SHEPHERD: Ran through ALL grabbers but still missing data!!! :(\n"; 325 321 return; 326 322 } … … 360 356 if ($debug) 361 357 { 362 &log((sprintf "Best timeslice: day%s of channels %s (%d chandays).\n",358 printf "Best timeslice: day%s of channels %s (%d chandays).\n", 363 359 ($timeslice->{start} == $timeslice->{stop} ? 364 360 " $timeslice->{start}" : 365 361 "s $timeslice->{start} - $timeslice->{stop}"), 366 362 join(', ', @{$timeslice->{chans}}), 367 $timeslice->{chandays} ));363 $timeslice->{chandays}; 368 364 } 369 365 … … 372 368 if ($debug) 373 369 { 374 &log("Grabber selection:\n");370 printf "Grabber selection:\n"; 375 371 foreach (sort { $gscore->{$b} <=> $gscore->{$a} } keys %$gscore) 376 372 { … … 383 379 if ($opt->{randomize}) 384 380 { 385 &log((sprintf "%15s %6.1f%% %9s %s\n",381 printf "%15s %6.1f%% %9s %s\n", 386 382 $_, 387 383 ($total ? 100* $score / $total : 0), 388 384 "$score pts", 389 $cstr ));385 $cstr; 390 386 } 391 387 else 392 388 { 393 &log((sprintf"%15s %4s pts %s\n",389 printf "%15s %4s pts %s\n", 394 390 $_, 395 391 $score, 396 $cstr ));392 $cstr; 397 393 } 398 394 } … … 413 409 unless ($components->{$grabber}->{lastdata}) 414 410 { 415 &log("Need to build title translation list for transitional grabber $grabber.\n");411 printf "Need to build title translation list for transitional grabber $grabber.\n"; 416 412 return select_grabber($grabber, $gscore) if ($gscore->{$grabber}); 417 &log("WARNING: Can't run $grabber to build title translation list!\n");413 printf "WARNING: Can't run $grabber to build title translation list!\n"; 418 414 } 419 415 } … … 459 455 my ($grabber, $gscore) = @_; 460 456 461 &log("Selected $grabber.\n")if ($debug);457 printf "Selected $grabber.\n" if ($debug); 462 458 if (query_config($grabber, 'category') == 2) 463 459 { … … 497 493 { 498 494 $key = cut_down_missing($grabber); 499 # &log("Grabber $grabber is Category 1: comparing capability to best timeslice.\n")if ($debug);495 # printf "Grabber $grabber is Category 1: comparing capability to best timeslice.\n" if ($debug); 500 496 } 501 497 else 502 498 { 503 499 $key = $missing; 504 # &log("Grabber $grabber is Category 2: comparing capability to all wanted channels and days.\n")if ($debug);500 # printf "Grabber $grabber is Category 2: comparing capability to all wanted channels and days.\n" if ($debug); 505 501 } 506 502 … … 515 511 my $val = supports_day($grabber, $day); 516 512 next unless ($val); 517 # &log("Day $day:")if ($debug);513 # printf "Day $day:" if ($debug); 518 514 foreach my $ch (@{$key->{$day}}) 519 515 { 520 516 if (supports_channel($grabber, $ch, $day)) 521 517 { 522 # &log(" $ch")if ($debug);518 # printf " $ch" if ($debug); 523 519 $hits += $val; 524 520 } 525 521 } 526 # &log("\n")if $debug;522 # printf "\n" if $debug; 527 523 $hits = 1 if ($hits > 0 and $hits < 1); 528 524 } … … 556 552 $score; 557 553 } 558 &log("$str.\n");554 printf "$str.\n"; 559 555 } 560 556 … … 586 582 $total -= $gscore->{$_}; 587 583 $gscore->{$_} = 0; 588 &log("Zeroing grabber $_ due to low data quality.\n")if ($debug);584 printf "Zeroing grabber $_ due to low data quality.\n" if ($debug); 589 585 } 590 586 } … … 611 607 unless (defined $channels_supported) 612 608 { 613 &log("WARNING: Grabber $grabber has no channel support " .614 "specified in config.\n" );609 printf "WARNING: Grabber $grabber has no channel support " . 610 "specified in config.\n"; 615 611 $channels_supported = ''; 616 612 } … … 686 682 if ($debug) 687 683 { 688 &log("Need data for days " . join(", ", sort keys %$m) .689 " ($chandays chandays).\n" );684 printf "Need data for days " . join(", ", sort keys %$m) . 685 " ($chandays chandays).\n"; 690 686 } 691 687 return $m; … … 737 733 my ($grabber, @grabbed) = @_; 738 734 739 &log("Recording cache for grabber $grabber.\n")if ($debug);735 printf "Recording cache for grabber $grabber.\n" if ($debug); 740 736 741 737 my $gcache = $components->{$grabber}->{cached}; … … 788 784 my ($grabber, $slice) = @_; 789 785 790 &log("Recording timeslice request; will not request these chandays " .791 "from $grabber again.\n" )if ($debug);786 printf "Recording timeslice request; will not request these chandays " . 787 "from $grabber again.\n" if ($debug); 792 788 793 789 my @requested; … … 848 844 849 845 if (! -r $output) { 850 &log((sprintf "SHEPHERD: Warning: plugin '%s' output file '%s' does not exist\n",$plugin,$output));846 printf "SHEPHERD: Warning: plugin '%s' output file '%s' does not exist\n",$plugin,$output; 851 847 return; 852 848 } 853 849 854 850 my $this_plugin = $plugin_data->{$plugin}; 855 &log((sprintf "SHEPHERD: Started parsing XMLTV from '%s' in '%s' .. any errors below are from parser:\n",$plugin,$output));851 printf "SHEPHERD: Started parsing XMLTV from '%s' in '%s' .. any errors below are from parser:\n",$plugin,$output; 856 852 eval { $this_plugin->{xmltv} = XMLTV::parsefiles($output); }; 857 &log((sprintf "SHEPHERD: Completed XMLTV parsing from '%s'\n",$plugin));853 printf "SHEPHERD: Completed XMLTV parsing from '%s'\n",$plugin; 858 854 859 855 if (!($this_plugin->{xmltv})) { 860 &log("WARNING: Plugin $plugin didn't seem to return any valid XMLTV!\n");856 printf "WARNING: Plugin $plugin didn't seem to return any valid XMLTV!\n"; 861 857 return; 862 858 } … … 884 880 if (!defined $chan_xml_list{($prog->{channel})}) { 885 881 $this_plugin->{progs_with_unknown_channel}++; 886 &log((sprintf " - WARNING: plugin '%s' returned data for unknown channel '%s': ignored.\n",$plugin,$prog->{channel}));882 printf " - WARNING: plugin '%s' returned data for unknown channel '%s': ignored.\n",$plugin,$prog->{channel}; 887 883 $chan_xml_list{($prog->{channel})} = 1; # so we warn only once 888 884 } … … 901 897 902 898 if (!$t1 || !$t2) { 903 &log((sprintf " - WARNING: plugin '%s' returned programme data with invalid timestamp format: \"%s\": can't parse.\n",904 $plugin,(!$t1 ? $prog->{start} : $prog->{stop}) ))if (!$this_plugin->{progs_with_invalid_date});899 printf " - WARNING: plugin '%s' returned programme data with invalid timestamp format: \"%s\": can't parse.\n", 900 $plugin,(!$t1 ? $prog->{start} : $prog->{stop}) if (!$this_plugin->{progs_with_invalid_date}); 905 901 $this_plugin->{progs_with_invalid_date}++; 906 902 next; … … 943 939 944 940 # print some stats about what we saw! 945 &log((sprintf "SHEPHERD: %s '%s' returned data for %d channels, %d programmes, %dd%02dh%02dm%02ds duration, %s%s\n",941 printf "SHEPHERD: %s '%s' returned data for %d channels, %d programmes, %dd%02dh%02dm%02ds duration, %s%s\n", 946 942 ucfirst($plugintype), $plugin, $seen_channels_with_data, $this_plugin->{programmes}, 947 943 int($this_plugin->{total_duration} / 86400), # days … … 950 946 int($this_plugin->{total_duration} % 60), # sec 951 947 (defined $this_plugin->{earliest_data_seen} ? (strftime "%a %e %b %H:%M - ", localtime($this_plugin->{earliest_data_seen})) : 'no data'), 952 (defined $this_plugin->{latest_data_seen} ? (strftime "%a %e %b %H:%M", localtime($this_plugin->{latest_data_seen})) : '') ));948 (defined $this_plugin->{latest_data_seen} ? (strftime "%a %e %b %H:%M", localtime($this_plugin->{latest_data_seen})) : ''); 953 949 954 950 $this_plugin->{laststatus} = sprintf "%dch/%dpr/%dhrs %s-%s", … … 966 962 { 967 963 my ($analysistype,$quiet) = @_; 968 &log("SHEPHERD: $analysistype:\n")unless $quiet;964 printf "SHEPHERD: $analysistype:\n" unless $quiet; 969 965 970 966 my $total_channels = 0; … … 1108 1104 } 1109 1105 } 1110 &log($statusstring)unless $quiet;1106 printf $statusstring unless $quiet; 1111 1107 1112 1108 delete $channel_data->{$ch}->{analysis} if (defined $channel_data->{$ch}->{analysis}); … … 1114 1110 } 1115 1111 1116 &log((sprintf " > OVERALL: %s\n", ($overall_data_ok ? "PASS" : "FAIL"))) unless $quiet;1112 printf " > OVERALL: %s\n", ($overall_data_ok ? "PASS" : "FAIL") unless $quiet; 1117 1113 1118 1114 return $overall_data_ok; # return 1 for good, 0 for need more … … 1235 1231 sub reconcile_data 1236 1232 { 1237 &log("\nReconciling data:\n\n");1233 printf "\nReconciling data:\n\n"; 1238 1234 1239 1235 my $num_grabbers = 0; … … 1241 1237 my @input_file_list; 1242 1238 1243 &log("Preferred title preferences from '$pref_title_source'\n")1239 printf "Preferred title preferences from '$pref_title_source'\n" 1244 1240 if ((defined $pref_title_source) && 1245 1241 ($plugin_data->{$pref_title_source}) && 1246 1242 ($plugin_data->{$pref_title_source}->{valid})); 1247 1243 1248 &log("Preference for whose data we prefer as follows:\n");1244 printf "Preference for whose data we prefer as follows:\n"; 1249 1245 foreach my $proggy (sort { $components->{$b}->{config}->{quality} <=> $components->{$a}->{config}->{quality} } query_grabbers()) { 1250 1246 if ((!$components->{$proggy}->{disabled}) && ($plugin_data->{$proggy}) && ($plugin_data->{$proggy}->{valid})) { 1251 1247 $num_grabbers++; 1252 &log((sprintf " %d. %s (%s)\n", $num_grabbers, $proggy, $plugin_data->{$proggy}->{output_filename}));1248 printf " %d. %s (%s)\n", $num_grabbers, $proggy, $plugin_data->{$proggy}->{output_filename}; 1253 1249 1254 1250 $input_files .= $plugin_data->{$proggy}->{output_filename}." "; … … 1269 1265 if ((!$reconciler_found_all_data) && ($grabber_found_all_data)) { 1270 1266 # urgh. this reconciler did a bad bad thing ... 1271 &log("SHEPHERD: XML data from reconciler $reconciler appears bogus, will try to use another reconciler\n");1267 printf "SHEPHERD: XML data from reconciler $reconciler appears bogus, will try to use another reconciler\n"; 1272 1268 } else { 1273 &log("SHEPHERD: Data from reconciler $reconciler looks good\n");1269 printf "SHEPHERD: Data from reconciler $reconciler looks good\n"; 1274 1270 $input_postprocess_file = $plugin_data->{$reconciler}->{output_filename}; 1275 1271 } … … 1280 1276 if ($input_postprocess_file eq "") { 1281 1277 # no reconcilers worked!! 1282 &log("SHEPHERD: WARNING: No reconcilers seemed to work! Falling back to concatenating the data together!\n");1278 printf "SHEPHERD: WARNING: No reconcilers seemed to work! Falling back to concatenating the data together!\n"; 1283 1279 1284 1280 my %w_args = (); … … 1304 1300 # first time around: feed in reconciled data ($input_postprocess_file) 1305 1301 1306 &log("\nPostprocessing stage:\n");1302 printf "\nPostprocessing stage:\n"; 1307 1303 1308 1304 foreach my $postprocessor (sort { $components->{$a} <=> $components->{$b} } query_postprocessors()) { … … 1314 1310 if ($found_all_data) { 1315 1311 # accept what this postprocessor did to our output ... 1316 &log("SHEPHERD: accepting output from postprocessor $postprocessor, feeding it into next stage\n");1312 printf "SHEPHERD: accepting output from postprocessor $postprocessor, feeding it into next stage\n"; 1317 1313 $input_postprocess_file = $plugin_data->{$postprocessor}->{output_filename}; 1318 1314 delete $components->{$postprocessor}->{conescutive_failures} if (defined $components->{$postprocessor}->{conescutive_failures}); … … 1321 1317 1322 1318 # urgh. this postprocessor did a bad bad thing ... 1323 &log("SHEPHERD: XML data from postprocessor $postprocessor rejected, using XML from previous stage\n");1319 printf "SHEPHERD: XML data from postprocessor $postprocessor rejected, using XML from previous stage\n"; 1324 1320 1325 1321 if (defined $components->{$postprocessor}->{conescutive_failures}) { … … 1328 1324 $components->{$postprocessor}->{conescutive_failures} = 1; 1329 1325 } 1330 &log((sprintf "SHEPHERD: Postprocessor \"%s\" has now failed %d times in a row. %d more and it will be automatically disabled.\n",1326 printf "SHEPHERD: Postprocessor \"%s\" has now failed %d times in a row. %d more and it will be automatically disabled.\n", 1331 1327 $postprocessor, 1332 1328 $components->{$postprocessor}->{conescutive_failures}, 1333 ($policy{postprocessor_disable_failure_threshold} - $components->{$postprocessor}->{conescutive_failures}) ));1329 ($policy{postprocessor_disable_failure_threshold} - $components->{$postprocessor}->{conescutive_failures}); 1334 1330 1335 1331 if ($components->{$postprocessor}->{conescutive_failures} >= $policy{postprocessor_disable_failure_threshold}) { 1336 &log("SHEPHERD: Disabling Postprocessor \"$postprocessor\".\n");1332 printf "SHEPHERD: Disabling Postprocessor \"$postprocessor\".\n"; 1337 1333 $components->{$postprocessor}->{disabled} = 1; 1338 1334 } … … 1352 1348 $components->{$data_processor_name}->{laststatus} = "unknown"; 1353 1349 1354 &log((sprintf "\nSHEPHERD: Using %s: %s\n",$data_processor_type,$data_processor_name));1350 printf "\nSHEPHERD: Using %s: %s\n",$data_processor_type,$data_processor_name; 1355 1351 1356 1352 my $output = sprintf "%s/%ss/%s/output.xmltv",$CWD,$data_processor_type,$data_processor_name; … … 1371 1367 1372 1368 $comm .= " $input_files"; 1373 &log("SHEPHERD: Excuting command: $comm\n");1369 printf "SHEPHERD: Excuting command: $comm\n"; 1374 1370 1375 1371 my $dir = sprintf "%s/%ss/%s/",$CWD,$data_processor_type,$data_processor_name; … … 1379 1375 1380 1376 if ($retval != 0) { 1381 &log("$data_processor_type returned with non-zero return code $retval: assuming it failed.\n");1377 printf "$data_processor_type returned with non-zero return code $retval: assuming it failed.\n"; 1382 1378 return 0; 1383 1379 } … … 1418 1414 1419 1415 if (!(open(INFILE,"<$input_postprocess_file"))) { 1420 &log((sprintf "WARNING: could not open input file \"%s\": %s\n", $input_postprocess_file, $!));1421 &log("Output XMLTV data may be damanged as a result!\n");1416 printf "WARNING: could not open input file \"%s\": %s\n", $input_postprocess_file, $!; 1417 printf "Output XMLTV data may be damanged as a result!\n"; 1422 1418 } else { 1423 1419 while (<INFILE>) { … … 1428 1424 } 1429 1425 1430 &log("Final output stored in $output_filename.\n");1426 printf "Final output stored in $output_filename.\n"; 1431 1427 } 1432 1428 … … 1489 1485 } 1490 1486 1491 sub open_logfile1492 {1493 printf "Logging to $log_file.\n";1494 open(LOG_FILE,">>$log_file") || die "can't open log file $log_file for writing: $!\n";1495 1496 my $now = localtime(time);1497 printf LOG_FILE "$progname version $version started at $now\n\n";1498 }1499 1500 sub close_logfile1501 {1502 close(LOG_FILE);1503 }1504 1505 sub log1506 {1507 my $entry = shift;1508 print $entry;1509 printf LOG_FILE "%s",$entry unless $opt->{nolog};1510 }1511 1512 1487 sub call_prog 1513 1488 { 1514 1489 my $prog = shift; 1515 1490 if (!(open(PROG,"$prog|"))) { 1516 &log("warning: couldn't exec \"$prog\": $!\n");1491 printf "warning: couldn't exec \"$prog\": $!\n"; 1517 1492 return -1; 1518 1493 } 1519 1494 while(<PROG>) { 1520 &log($_);1495 printf $_; 1521 1496 } 1522 1497 close(PROG); 1523 1498 1524 1499 if ($? == -1) { 1525 &log("Failed to execute prog: $!\n");1500 printf "Failed to execute prog: $!\n"; 1526 1501 return -1; 1527 1502 } elsif ($? & 127) { 1528 &log((sprintf "prog died with signal %d, %s coredump\n",1529 ($? & 127), ( $? & 128) ? "with" : "without"));1503 printf "prog died with signal %d, %s coredump\n", 1504 ($? & 127), (($? & 128) ? "with" : "without"); 1530 1505 return $?; 1531 1506 } else { 1532 &log((sprintf "prog exited with value %d\n", $? >> 8)) if ($debug or $?);1507 printf "prog exited with value %d\n", ($? >> 8) if ($debug or $?); 1533 1508 return ($? >> 8); 1534 1509 } … … 1633 1608 'enable=s' => \$opt->{enable}, 1634 1609 1635 'nolog' => \$opt->{nolog},1636 1637 1610 'days=i' => \$days, 1638 1611 'offset=i' => \$opt->{offset}, … … 1694 1667 --capabilities Report capabilities to XMLTV 1695 1668 1696 --nolog Don't write a logfile1697 1669 }; 1698 1670 exit 0; … … 1710 1682 # check if we are in an eval() 1711 1683 if ($^S) { 1712 printf STDERR" shepherd caught a die() within eval{} from file $file line $line\n";1684 printf " shepherd caught a die() within eval{} from file $file line $line\n"; 1713 1685 } else { 1714 printf STDERR"\nDIE: line %d in file %s\n",$line,$file;1686 printf "\nDIE: line %d in file %s\n",$line,$file; 1715 1687 if ($arg) { 1716 1688 CORE::die($arg,@rest);
