Changeset 145
- Timestamp:
- 10/25/06 06:19:25 (7 years ago)
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
shepherd
r144 r145 3 3 # "Shepherd" 4 4 5 my $version = '0.2.2 4';5 my $version = '0.2.25'; 6 6 7 7 # A wrapper for various Aussie TV guide data grabbers … … 37 37 # explicitly tell reconciler the preferred _title_ source 38 38 # 0.2.24 : logging and log files 39 # 0.2.25 : use open-with-pipe rather than system() and look at 40 # return codes from called programmes 39 41 40 42 BEGIN { *CORE::GLOBAL::die = \&my_die; } … … 202 204 } 203 205 204 unless ($opt->{nolog}) { 205 &rotate_logfiles; 206 open(LOG_FILE,">$log_file") || die "can't open log file $log_file for writing: $!\n"; 207 } 206 &open_logfile unless ($opt->{nolog}); 208 207 209 208 # --------------------------------------------------------------------------- … … 323 322 $comm .= " @ARGV" if (@ARGV); 324 323 324 my $retval = 0; 325 325 if ((defined $opt->{dontcallgrabbers}) && ($opt->{dontcallgrabbers})) { 326 326 &log("SHEPHERD: not calling grabber because of --dontcallgrabbers option, but will instead use existing $output\n"); … … 329 329 &log("SHEPHERD: Excuting command: $comm\n"); 330 330 chdir "$CWD/grabbers/$grabber/"; 331 system($comm);331 $retval = call_prog($comm); 332 332 chdir $CWD; 333 } 334 335 if ($retval != 0) { 336 &log("grabber returned with non-zero return code $retval: assuming it failed.\n"); 337 next; 333 338 } 334 339 … … 1006 1011 $data->{missing} = 0; 1007 1012 1013 my $already_missing = ""; 1014 my $already_missing_last = ""; 1015 1008 1016 for my $slotnum (0..($policy{num_timeslots}-1)) { 1009 1017 my $bucket_start_offset = ($slotnum * $policy{timeslot_size}); … … 1024 1032 1025 1033 $data->{day}->[$day]->{day_ok} = 1; # until proven otherwise 1034 1035 # day changed, dump any 'already_missing' data 1036 if ($already_missing ne "") { 1037 $already_missing .= sprintf "-%02d:%02d", 1038 int($already_missing_last/3600),int(($already_missing_last%3600)/60) 1039 if ($already_missing_last ne ""); 1040 push(@{($data->{missing_all})}, $already_missing); 1041 $already_missing = ""; 1042 $already_missing_last = ""; 1043 } 1026 1044 } 1027 1045 … … 1029 1047 if ((defined $channel_data->{$ch}->{timeslots}[$slotnum]) && 1030 1048 ($channel_data->{$ch}->{timeslots}[$slotnum] > 0)) { 1049 1050 # if we have missing data queued up, push it now 1051 if ($already_missing ne "") { 1052 $already_missing .= sprintf "-%02d:%02d", 1053 int($already_missing_last/3600),int(($already_missing_last%3600)/60) 1054 if ($already_missing_last ne ""); 1055 push(@{($data->{missing_all})}, $already_missing); 1056 $already_missing = ""; 1057 $already_missing_last = ""; 1058 } 1059 1031 1060 $data->{day}->[$day]->{have} += $policy{timeslot_size}; 1032 1061 $data->{have} += $policy{timeslot_size}; … … 1044 1073 1045 1074 # store details of where we are missing data 1046 push(@{($data->{missing_all})}, "$day:$bucket_seconds_offset"); 1075 if ($already_missing eq "") { 1076 $already_missing = sprintf "#%d/%02d:%02d", $day, 1077 int($bucket_seconds_offset/3600),int(($bucket_seconds_offset%3600)/60); 1078 $already_missing_last = $bucket_seconds_offset + $policy{timeslot_size} - 1; 1079 } else { 1080 $already_missing_last = $bucket_seconds_offset + $policy{timeslot_size} - 1; 1081 } 1082 1047 1083 $data->{day}->[$day]->{missing} += $policy{timeslot_size}; 1048 1084 $data->{missing} += $policy{timeslot_size}; … … 1069 1105 } 1070 1106 1071 my $statusstring = sprintf "ch %s: have %s (%s)%s", 1107 # if we have missing data queued up, push it now 1108 if ($already_missing ne "") { 1109 $already_missing .= sprintf "-%02d:%02d", 1110 int($already_missing_last/3600),int(($already_missing_last%3600)/60) 1111 if ($already_missing_last ne ""); 1112 push(@{($data->{missing_all})}, $already_missing); 1113 $already_missing = ""; 1114 $already_missing_last = ""; 1115 } 1116 1117 my $statusstring = sprintf "ch %s: %s (%s)%s", 1072 1118 $ch, pretty_duration($data->{have}), $data->{data_ok} ? "pass" : "fail", 1073 1119 ($data->{missing} ? " missing" : ""); … … 1093 1139 if ($day->{missing_other} > 0); 1094 1140 } else { 1095 $statusstring .= "all ";1141 $statusstring .= "all[!]"; 1096 1142 } 1097 1143 … … 1100 1146 } 1101 1147 &log(" > $statusstring\n") unless $quiet; 1148 1149 &log("[debug] Missing the following bucket slots for this $ch: ". 1150 join(" ",(@{($data->{missing_all})}))."\n") 1151 if ($data->{missing} > 0); 1102 1152 1103 1153 delete $channel_data->{$ch}->{analysis} if (defined $channel_data->{$ch}->{analysis}); … … 1331 1381 my $dir = sprintf "%s/%ss/%s/",$CWD,$data_processor_type,$data_processor_name; 1332 1382 chdir $dir; 1333 system($comm);1383 my $retval = call_prog($comm); 1334 1384 chdir $CWD; 1385 1386 if ($retval != 0) { 1387 &log("$data_processor_type returned with non-zero return code $retval: assuming it failed.\n"); 1388 return 0; 1389 } 1335 1390 1336 1391 # … … 1498 1553 1499 1554 # Make component executable 1500 system('chmod u+x ' . $newfile);1555 chmod 0755,$newfile; 1501 1556 1502 1557 -d $ARCHIVE_DIR or mkdir $ARCHIVE_DIR or die "Cannot create directory $ARCHIVE_DIR: $!"; … … 1562 1617 1563 1618 chdir($testdir); 1564 system("$proggyexec --ready");1619 my $result = call_prog("$proggyexec --ready"); 1565 1620 chdir ($CWD); 1566 1621 1567 my $result = $?;1568 1622 print "Return value: $result\n" if ($debug); 1569 1623 … … 1717 1771 } 1718 1772 1773 sub open_logfile 1774 { 1775 &rotate_logfiles; 1776 printf "Logging to $log_file.\n"; 1777 open(LOG_FILE,">$log_file") || die "can't open log file $log_file for writing: $!\n"; 1778 } 1779 1719 1780 sub close_logfile 1720 1781 { … … 1727 1788 my $entry = shift; 1728 1789 print $entry; 1729 printf LOG_FILE "%s %s",time,$entry unless $opt->{nolog}; 1730 } 1731 1790 printf LOG_FILE "%s",$entry unless $opt->{nolog}; 1791 } 1792 1793 sub call_prog 1794 { 1795 my $prog = shift; 1796 if (!(open(PROG,"$prog|"))) { 1797 &log("warning: couldn't exec \"$prog\": $!\n"); 1798 return -1; 1799 } 1800 while(<PROG>) { 1801 &log($_); 1802 } 1803 close(PROG); 1804 1805 if ($? == -1) { 1806 &log("Failed to execute prog: $!\n"); 1807 return -1; 1808 } elsif ($? & 127) { 1809 &log((sprintf "prog died with signal %d, %s coredump\n", 1810 ($? & 127), ($? & 128) ? "with" : "without")); 1811 return $?; 1812 } else { 1813 &log((sprintf "prog exited with value %d\n", $? >> 8)); 1814 return ($? >> 8); 1815 } 1816 } 1732 1817 1733 1818 # ----------------------------------------- -
status
r144 r145 1 shepherd:0.2.2 4:shepherd1 shepherd:0.2.25:shepherd 2 2 grabber:rex:3.3.5-r2 3 3 grabber:oztivo:0.8-r2
