Changeset 74

Show
Ignore:
Timestamp:
10/16/06 17:20:07 (7 years ago)
Author:
lincoln
Message:

reconciler_mk2 enhancement: compress logfiles automatically since they are quite large

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • reconcilers/reconciler_mk2

    r73 r74  
    1616#    0.04  17aug06      bug fix: use our own parse_xmltv_date, Date::Manip seems broken 
    1717#                       bug fix: correctly parse some XMLTV rare fields  
     18#    0.05  17aug06      enhancement: compress logfiles automatically since they are quite large 
    1819 
    1920# 
     
    7576 
    7677my $progname = "reconciler_mk2"; 
    77 my $version = "0.04_15aug06"; 
     78my $version = "0.05_17aug06"; 
    7879 
    7980use LWP::UserAgent; 
     
    197198        'lang=s'                => \$opt->{lang}, 
    198199        'option=s'              => \%reclogic, 
     200 
     201        'no-log'                => \$opt->{nolog}, 
    199202 
    200203        'print_listing'         => \$reclogic{debug_print_programme_list}, 
     
    256259 
    257260# go go go! 
    258 open(LOG_FILE,">$opt->{log_file}") || die "can't open log file $opt->{log_file} for writing: $!\n"; 
    259 open(ALT_TITLE_FILE,">$opt->{alt_title_file}") || die "can't open alt-title-file $opt->{alt_title_file} for writing: $!\n"; 
     261unless ($opt->{nolog}) { 
     262        &rotate_logfiles; 
     263 
     264        open(LOG_FILE,">$opt->{log_file}") || die "can't open log file $opt->{log_file} for writing: $!\n"; 
     265        open(ALT_TITLE_FILE,">$opt->{alt_title_file}") || die "can't open alt-title-file $opt->{alt_title_file} for writing: $!\n"; 
     266 
     267        printf ALT_TITLE_FILE "$progname $version\n"; 
     268        printf ALT_TITLE_FILE "This log file contains lists of what title matches were attempted (but didn't match).\n"; 
     269        printf ALT_TITLE_FILE "The intent of this is to keep a log that we can (hopefully) interpret in order to\n"; 
     270        printf ALT_TITLE_FILE "improve the alternateTitle() logic.\n\n"; 
     271} 
    260272 
    261273&log(1,(sprintf "started: %s%soutput %s", 
     
    263275        ($opt->{config_file} ? "default overrides in $opt->{config_file}, " : ""), 
    264276        ($opt->{output_file}))); 
    265 &log(1,(sprintf "  logging to %s, alternate titles to %s",$opt->{log_file},$opt->{alt_title_file})); 
    266  
    267 printf ALT_TITLE_FILE "$progname $version\n"; 
    268 printf ALT_TITLE_FILE "This log file contains lists of what title matches were attempted (but didn't match).\n"; 
    269 printf ALT_TITLE_FILE "The intent of this is to keep a log that we can (hopefully) interpret in order to\n"; 
    270 printf ALT_TITLE_FILE "improve the alternateTitle() logic.\n\n"; 
     277&log(1,(sprintf "  logging to %s, alternate titles to %s",$opt->{log_file},$opt->{alt_title_file})) unless $opt->{nolog}; 
    271278 
    272279&override_settings; 
     
    293300&print_stats; 
    294301 
    295 close(LOG_FILE); 
    296 close(ALT_TITLE_FILE); 
     302unless ($opt->{nolog}) { 
     303        close(LOG_FILE); 
     304        close(ALT_TITLE_FILE); 
     305 
     306        compress_file($opt->{log_file}); 
     307        compress_file($opt->{alt_title_file}); 
     308} 
    297309 
    298310exit(0); 
     
    360372 
    361373###################################################################################################### 
     374 
     375sub rotate_logfiles 
     376{ 
     377        # keep last 4 log files 
     378        foreach my $file ($opt->{log_file}, $opt->{alt_title_file}) { 
     379                my $num; 
     380                for ($num = 4; $num > 0; $num--) { 
     381                        my $f1 = sprintf "%s.%d.gz",$file,$num; 
     382                        my $f2 = sprintf "%s.%d.gz",$file,$num+1; 
     383                        unlink($f2); 
     384                        rename($f1,$f2); 
     385                } 
     386 
     387                my $f1 = sprintf "%s.gz",$file; 
     388                my $f2 = sprintf "%s.1.gz",$file; 
     389                rename($f1,$f2); 
     390        } 
     391} 
     392 
     393###################################################################################################### 
     394 
     395sub compress_file 
     396{ 
     397        my $infile = shift; 
     398        my $outfile = sprintf "%s.gz",$infile; 
     399        my $gz; 
     400 
     401        if (!(open(INFILE,"<$infile"))) { 
     402                warn "could not open file $infile for reading: $!\n"; 
     403                return; 
     404        } 
     405 
     406        if (!($gz = gzopen($outfile,"wb"))) { 
     407                warn "could not open file $outfile for writing: $!\n"; 
     408                return; 
     409        } 
     410 
     411        while (<INFILE>) { 
     412                my $byteswritten = $gz->gzwrite($_); 
     413                if ($byteswritten == 0) { 
     414                        warn "error writing to compressed file: error $gz->gzerror"; 
     415                } 
     416        } 
     417        close(INFILE); 
     418        $gz->gzclose(); 
     419        unlink($infile); 
     420} 
     421 
     422###################################################################################################### 
    362423# if we are supplied a channels_file, then fill in channels we know about from that. 
    363424# this is useful because some grabbers (e.g. oztivo) don't supply a <channels></channels> 
     
    386447        my ($log_to_screen,$entry) = @_; 
    387448        printf STDERR "%s [%d] %s\n",$progname, time,$entry if ($log_to_screen); 
    388         printf LOG_FILE "%s [%d] %s\n",$progname, time,$entry; 
     449        printf LOG_FILE "%s [%d] %s\n",$progname, time,$entry unless $opt->{nolog}; 
    389450} 
    390451 
     
    760821        if (($t2 - $t1) > $reclogic{max_programme_length}) { 
    761822                &log($reclogic{warn_on_invalid_time_in_prog}, 
    762                   (sprintf "WARNING: programme '%s' on channel '%s' from %s had a programme duration (%d) that exceeded max_programme_length (%d): start '%s' stop '%s'; ignored.\n", 
     823                  (sprintf "WARNING: programme '%s' on channel '%s' from %s had a programme duration (%d) that exceeded max_programme_length (%d): start '%s' stop '%s'; ignored.", 
    763824                  $prog_title, $prog_chan, $datafile, ($t2-$t1),  $reclogic{max_programme_length}, 
    764825                  ($prog->{start} ? $prog->{start} : "undef"), ($prog->{stop} ? $prog->{stop} : "undef"))); 
     
    806867                &log($warn,(sprintf "WARNING: file contained more than one programme in same timeslot: channel '%s' start %s, stop %s, programs \"%s\" and \"%s\"; ignored.", 
    807868                        $prog_chan, 
    808                         (strftime "%a %e %b %H:%M",localtime($t1)), 
    809                         (strftime "%H:%M",localtime($t2)), 
     869                        (strftime "%a%e%b%H:%M",localtime($t1)), 
     870                        (strftime "%a%e%b%H:%M",localtime($t2)), 
    810871                        $prog_title, 
    811872                        $in->{dupcheck}->{$source}->{$prog_chan}->{$prog_key})); 
     
    878939                        printf "%-10s %s - %s: %-30s {src %s}\n", 
    879940                                $in->{channels}->{$chan_id}->{pref_desc}, 
    880                                 (strftime "%a%e%b %H:%M", localtime($prog->{start_epoch})), 
    881                                 (strftime "%H:%M", localtime($prog->{stop_epoch})), 
     941                                (strftime "%a%e%b%H:%M", localtime($prog->{start_epoch})), 
     942                                (strftime "%a%e%b%H:%M", localtime($prog->{stop_epoch})), 
    882943                                $progname, 
    883944                                $prog->{datasources} 
     
    903964        &log($reclogic{debug_add_logic}, 
    904965          (sprintf "add_one_programme: adding programme %s-%s \"%s\" with data from %d programmes", 
    905           (strftime "%a %e %b %H:%M",localtime(($m->[0]->{start_epoch}))), 
    906           (strftime "%H:%M",localtime(($m->[0]->{stop_epoch}))), 
     966          (strftime "%a%e%b%H:%M",localtime(($m->[0]->{start_epoch}))), 
     967          (strftime "%a%e%b%H:%M",localtime(($m->[0]->{stop_epoch}))), 
    907968          $m->[0]->{title}->[0]->[0], $num_matching)); 
    908969 
     
    11141175                                &log($reclogic{debug_delete_logic}, 
    11151176                                  (sprintf " - deleting \"%s\" (%s-%s, grabber %d) - within window", 
    1116                                   $prog_title, (strftime "%a%e%b %H:%M", localtime($prog_start)), 
    1117                                   (strftime "%H:%M", localtime($prog_stop)), $prog_grabber)); 
     1177                                  $prog_title, (strftime "%a%e%b%H:%M", localtime($prog_start)), 
     1178                                  (strftime "%a%e%b%H:%M", localtime($prog_stop)), $prog_grabber)); 
    11181179                        } elsif (($prog_start < $del_start) && ($prog_stop > $del_stop)) { 
    11191180                                # 
     
    11321193                                        &log($reclogic{debug_delete_logic}, 
    11331194                                          (sprintf " - deleting \"%s\" (%s-%s, grabber %d) - within window +/- delete_window_smaller_than_prog_window_threshold (%d)", 
    1134                                           $prog_title, (strftime "%a%e%b %H:%M", localtime($prog_start)), 
    1135                                           (strftime "%H:%M", localtime($prog_stop)), $prog_grabber, 
     1195                                          $prog_title, (strftime "%a%e%b%H:%M", localtime($prog_start)), 
     1196                                          (strftime "%a%e%b%H:%M", localtime($prog_stop)), $prog_grabber, 
    11361197                                          $reclogic{delete_window_smaller_than_prog_window_threshold})); 
    11371198                                        $stats{prog_del_overwindow_close_enough}++; 
     
    13221383                        my $alternate_titles = sprintf "channel %s timeslot %s-%s, preferred grabber %d\n", 
    13231384                          $in->{channels}->{$chan_id}->{pref_desc}, 
    1324                           (strftime "%a %e %b %H:%M",localtime(($prog->{start_epoch}))), 
    1325                           (strftime "%H:%M",localtime(($prog->{stop_epoch}))), 
     1385                          (strftime "%a%e%b%H:%M",localtime(($prog->{start_epoch}))), 
     1386                          (strftime "%a%e%b%H:%M",localtime(($prog->{stop_epoch}))), 
    13261387                          $prog->{grabber_num}; 
    13271388 
     
    14001461                                &log($reclogic{debug_reconcile_pass1}, 
    14011462                                  (sprintf "reconcile:   %d programs between %s - %s", 
    1402                                   $num_progs_in_slot, (strftime "%a %e %b %H:%M",localtime($this_prog_start)), 
    1403                                   (strftime "%H:%M",localtime($this_prog_stop)))); 
     1463                                  $num_progs_in_slot, (strftime "%a%e%b%H:%M",localtime($this_prog_start)), 
     1464                                  (strftime "%a%e%b%H:%M",localtime($this_prog_stop)))); 
    14041465 
    14051466                                $stats{rec_start_stop_match}++; 
     
    14391500                                  (sprintf "reconcile: (%d to go) chose programme for %s-%s: \"%s\", looking for alternatives between %s-%s", 
    14401501                                  $in->{total_progs}->{$chan_id}, 
    1441                                   (strftime "%a %e %b %H:%M",localtime($found_prog->{start_epoch})), 
    1442                                   (strftime "%H:%M",localtime($found_prog->{stop_epoch})), $found_prog->{title}->[0]->[0], 
    1443                                   (strftime "%H:%M",localtime($start_window)), 
    1444                                   (strftime "%H:%M",localtime($stop_window)))); 
     1502                                  (strftime "%a%e%b%H:%M",localtime($found_prog->{start_epoch})), 
     1503                                  (strftime "%a%e%b%H:%M",localtime($found_prog->{stop_epoch})), $found_prog->{title}->[0]->[0], 
     1504                                  (strftime "%a%e%b%H:%M",localtime($start_window)), 
     1505                                  (strftime "%a%e%b%H:%M",localtime($stop_window)))); 
    14451506 
    14461507                                foreach my $prog_key2 ( sort { $in->{tree}->{$chan_id}->{$a} <=> $in->{tree}->{$chan_id}->{$b} } keys %{($in->{tree}->{$chan_id})} ) { 
     
    14591520                                                        &log($reclogic{debug_reconcile_pass2}, 
    14601521                                                          (sprintf "reconcile:     found alternative prog: %s-%s, \"%s\"", 
    1461                                                           (strftime "%a%e%b %H:%M",localtime($check_prog->{start_epoch})), 
    1462                                                           (strftime "%H:%M",localtime($check_prog->{stop_epoch})), 
     1522                                                          (strftime "%a%e%b%H:%M",localtime($check_prog->{start_epoch})), 
     1523                                                          (strftime "%a%e%b%H:%M",localtime($check_prog->{stop_epoch})), 
    14631524                                                          $check_prog->{title}->[0]->[0])); 
    14641525                                                } 
  • status

    r73 r74  
    77jrobbo:0.03-r2:grabber 
    88d1:0.6.2.3-r2:grabber 
    9 reconciler_mk2:0.04:reconciler 
     9reconciler_mk2:0.05:reconciler 
    1010imdb_augment_data:0.01:postprocessor