Changeset 1474


Ignore:
Timestamp:
09/24/13 17:05:08 (4 years ago)
Author:
mbarry
Message:

shepherd v1.9.0: Add "autorefresh"

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/applications/shepherd

    r1471 r1474  
    22 
    33our $progname = 'shepherd'; 
    4 my $version = '1.8.8'; 
     4my $version = '1.9.0'; 
    55 
    66# tv_grab_au 
     
    7373our $pref_title_source; 
    7474my $last_successful_run; 
     75my $last_successful_refresh; 
    7576our $hd_to_sds; 
    7677 
     
    265266    { 
    266267        &postprocess_data unless ($opt->{skippost}); 
    267         &output_data; 
     268        &output_data(); 
    268269        &finalize_stats; 
    269270        &report_stats; 
     
    885886    unless ($opt->{dontcallgrabbers}) 
    886887    { 
    887         $last_successful_run = time; 
    888         my $total_wanted = $plugin_data->{$progname}->{total_duration} + $plugin_data->{$progname}->{total_missing}; 
    889         $last_successful_run_data = ($total_wanted ? 100* $plugin_data->{$progname}->{total_duration} / $total_wanted : 0); 
    890  
    891         $last_successful_runs->{$last_successful_run} = $last_successful_run_data; 
     888        unless ($opt->{'autorefresh'}) 
     889        { 
     890            $last_successful_run = time; 
     891            my $total_wanted = $plugin_data->{$progname}->{total_duration} + $plugin_data->{$progname}->{total_missing}; 
     892            $last_successful_run_data = ($total_wanted ? 100* $plugin_data->{$progname}->{total_duration} / $total_wanted : 0); 
     893            $last_successful_runs->{$last_successful_run} = $last_successful_run_data; 
     894        } 
     895        $last_successful_refresh = time; 
    892896    } 
    893897} 
     
    11021106} 
    11031107 
    1104 # if last run was successful and was less than 22 hours ago, refuse to run. 
    1105 # there's really no point calling shepherd more frequently than this. 
     1108# If the last run was successful and was less than 22 hours ago, refuse to run. 
     1109# There's really no point calling shepherd more frequently than this. 
     1110# 
     1111# However, as of v1.9.0, we also do a "refresh" of the current day by default 
     1112# if it's been less than 22 hours since the last full run, but more than 4 hours 
     1113# since the last refresh. A refresh just updates the current day. 
     1114# 
    11061115sub check_last_run 
    11071116{ 
     
    11091118    my $last_ran_secs_ago = time - $last_successful_run; 
    11101119 
    1111     &log(0,"\n".ucfirst($progname)." last ran successfully ".pretty_duration($last_ran_secs_ago)." ago.\n"); 
     1120    &log(0,"\n".ucfirst($progname)." last successfully completed a full run ".pretty_duration($last_ran_secs_ago)." ago.\n"); 
    11121121 
    11131122    return if ($last_ran_secs_ago > (22*60*60)); 
     
    11531162    } 
    11541163 
    1155     &log("!! Shepherd has successfully completed a run less than 22 hours ago.\n" . 
    1156          "!! Exiting to avoid wasting time and bandwidth.\n\n"); 
     1164    &log("!! Will not re-run since last full run was less than 22 hours ago.\n"); 
     1165 
     1166    if (!$last_successful_refresh or $last_successful_refresh < $last_successful_run) 
     1167    { 
     1168        $last_successful_refresh = $last_successful_run; 
     1169    } 
     1170    my $last_refreshed_secs_ago = time - $last_successful_refresh; 
     1171    if ($last_successful_refresh != $last_successful_run) 
     1172    { 
     1173        &log("\nShepherd last successfully refreshed " . &pretty_duration($last_refreshed_secs_ago) . " ago.\n"); 
     1174    } 
     1175    if ($last_refreshed_secs_ago > (4*60*60)) 
     1176    { 
     1177        if ($opt->{'days'} and $days != 1) 
     1178        { 
     1179            &log("!! Will not autorefresh due to user-supplied '--days' option.\n"); 
     1180        } 
     1181        elsif ($opt->{'noautorefresh'}) 
     1182        { 
     1183            &log("!! Will not autorefresh due to '--noautorefresh' option.\n"); 
     1184        } 
     1185        elsif ((localtime)[2] >= 23) 
     1186        { 
     1187            &log("!! Will not autorefresh due to lateness of current time (11PM+).\n"); 
     1188        } 
     1189        else 
     1190        { 
     1191            &log("\n*** Autorefreshing today's data! ***\n"); 
     1192            $days = $opt->{'days'} = 1; 
     1193            $opt->{'autorefresh'} = 1; 
     1194            unless ($opt->{'output'}) 
     1195            { 
     1196                $output_filename = "$CWD/refresh.xmltv"; 
     1197                &test_output_file(); 
     1198            } 
     1199            return; 
     1200        } 
     1201    } 
     1202    else 
     1203    { 
     1204        &log("!! Last refresh was less than 4 hours ago.\n"); 
     1205    } 
     1206 
     1207    &log("\n!! Exiting to avoid wasting time and bandwidth.\n\n"); 
    11571208 
    11581209    if (defined $opt->{'refresh-mythtv'}) 
     
    11621213    else 
    11631214    { 
    1164         &log("If you wish Shepherd to re-output the data it gathered last run,\n" . 
     1215        &log("If you wish Shepherd to re-output the data it gathered last full run,\n" . 
    11651216         "use the --reoutput option (e.g. 'tv_grab_au --reoutput'). To do this\n" . 
    11661217         "via mythfilldatabase, use 'mythfilldatabase -- --reoutput'. (Or,\n". 
     
    19121963{ 
    19131964    write_file($config_file, 'configuration',  
    1914         [$region,  $pref_title_source,  $want_paytv_channels,  $sysid,  $last_successful_run, $last_successful_run_data, $last_successful_runs, $sources, $components,  $components_pending_install,  $pending_messages ], 
    1915         ["region", "pref_title_source", "want_paytv_channels", "sysid", "last_successful_run", "last_successful_run_data", "last_successful_runs", 'sources', "components", "components_pending_install", "pending_messages" ]); 
     1965        [$region,  $pref_title_source,  $want_paytv_channels,  $sysid,  $last_successful_run, $last_successful_run_data, $last_successful_runs, $last_successful_refresh, $sources, $components,  $components_pending_install,  $pending_messages ], 
     1966        ["region", "pref_title_source", "want_paytv_channels", "sysid", "last_successful_run", "last_successful_run_data", "last_successful_runs", 'last_successful_refresh', 'sources', "components", "components_pending_install", "pending_messages" ]); 
    19161967} 
    19171968 
     
    20072058                        reoutput 
    20082059                        reoutput-mythtv 
     2060                        noautorefresh 
    20092061                     )); 
    20102062  $debug = $opt->{debug}; 
     
    27522804                            $last_successful_run_data; 
    27532805        } 
    2754         &log("\n$str.\n"); 
     2806        $str .= ".\n"; 
     2807        if ($last_successful_refresh and $last_successful_refresh != $last_successful_run) 
     2808        { 
     2809            $str .= sprintf "Shepherd last autorefreshed %s ago.\n",  
     2810                            &pretty_duration(time - $last_successful_refresh); 
     2811        } 
     2812        &log($str); 
    27552813    } 
    27562814    &log("\nPreferred titles from grabber '$pref_title_source'\n") if ($pref_title_source); 
     
    27712829                 scalar(keys %$last_successful_runs), 
    27722830                 int((time - $all_runs[0]) / 86400)); 
     2831    if ($last_successful_refresh and $last_successful_refresh != $last_successful_run) 
     2832    { 
     2833        &log(sprintf "Shepherd last successfully autorefreshed %s ago (%s).\n\n", 
     2834                &pretty_duration(time - $last_successful_refresh), 
     2835                &pretty_date($last_successful_refresh)); 
     2836    } 
     2837 
    27732838    my $str; 
    27742839    foreach my $when (sort {$b <=> $a} keys (%{$last_successful_runs}))  
     
    28102875{ 
    28112876    print q{Info options: 
    2812     --help                Display this message 
     2877    --help                Hello! 
    28132878    --dev-help            Display advanced options 
    28142879    --version             Display version 
    2815     --status              Display status of various components 
    2816     --desc                Display detailed status of components 
     2880    --status              Display status 
     2881    --desc                Display detailed status 
    28172882    --history             Display usage history 
    2818     --check               Display check of all components 
     2883    --check               Verify current installation 
    28192884 
    28202885    --show-config         Show setup details 
     
    28252890 
    28262891Session options: 
    2827     --output <s>          Create file <s> (default: ~/.shepherd/output.xmltv) 
    2828     --days <n>            Retrieve <n> days of guide data 
     2892    --output <file>       Specify an output file (default: ~/.shepherd/output.xmltv) 
     2893    --days <n>            Retrieve <n> days of data 
    28292894    --offset <n>          Skip first <n> days 
    28302895 
     
    28352900 
    28362901    --noupdate            Don't update Shepherd; just grab data 
    2837     --update              Don't grab data; just update Shepherd 
    2838     --skipupdate          Skip update of Shepherd 
    2839     --skippost            Skip postprocessing of data 
     2902    --update              Update Shepherd but don't grab data 
     2903    --skipupdate          Don't update Shepherd or verify components; just grab data 
     2904    --skippost            Don't run any postprocessors on data 
     2905    --noautorefresh       Don't switch to autorefresh mode (i.e. "--days 1") 
    28402906 
    28412907    --mode <s>            Quality (default), Efficiency or Speed 
    2842     --grabwith <s>        Grab with grabber <s> before trying other grabbers 
     2908    --grabwith <s>        Run grabber(s) <s> before any others 
    28432909                          (e.g. --grabwith sbsweb,abc_website) 
    28442910 
    28452911    --debug               Print debugging messages 
    28462912    --quiet               Don't print anything except errors 
    2847     --notquiet            Don't be --quiet 
     2913    --notquiet            Override --quiet 
    28482914    --nolog               Don't write a logfile 
    28492915    --nonotify            Don't report anonymous usage statistics 
     
    29443010        my $iteration = query_iteration($grabber); 
    29453011 
    2946         my $output = sprintf "%s/grabbers/%s/output-%d.xmltv",  
    2947                              $CWD, $grabber, $iteration; 
     3012        my $output = sprintf "%s/grabbers/%s/%s-%d.xmltv",  
     3013                             $CWD, $grabber,  
     3014                             ($opt->{'autorefresh'} ? 'refresh' : 'output'), 
     3015                             $iteration; 
    29483016 
    29493017        my $comm = "$CWD/grabbers/$grabber/$grabber " . 
     
    48404908    &log("\nSHEPHERD: Using $data_processor_type: $data_processor_name\n"); 
    48414909 
    4842     my $output = sprintf "%s/%ss/%s/output.xmltv",$CWD,$data_processor_type,$data_processor_name; 
     4910    my $out = ($opt->{'autorefresh'} ? 'refresh' : 'output'); 
     4911    my $output = sprintf "%s/%ss/%s/%s.xmltv",$CWD,$data_processor_type,$data_processor_name, $out; 
    48434912    my $comm = sprintf "%s/%ss/%s/%s",$CWD,$data_processor_type,$data_processor_name,$data_processor_name; 
    48444913    $comm .= " --region $region" . 
     
    49345003    $reuse_cached_output = 0 if (!defined $reuse_cached_output); 
    49355004     
    4936     my $output_cache_copy = "$CWD/output.xmltv"; 
     5005    my $output_cache_copy = $output_filename; 
    49375006 
    49385007    if ($reuse_cached_output) { 
     
    49625031        &log("Final output stored in $output_filename.\n"); 
    49635032 
    4964         # copy final output to our cache copy as well 
    4965         if ($output_filename ne $output_cache_copy) { 
    4966             unlink($output_cache_copy); 
    4967             open(F1,"<$output_filename"); 
    4968             open(F2,">$output_cache_copy"); 
    4969             while (<F1>) { 
    4970                 print F2 $_; 
    4971             } 
    4972             close(F1); 
    4973             close(F2); 
    4974         } 
    4975         &log("Cached output stored in $output_cache_copy.\n"); 
    4976     } 
    4977  
    4978     if (!$opt->{'output'} and !$opt->{'nooutput'}) { 
     5033        unless ($opt->{'autorefresh'}) 
     5034        { 
     5035            # copy final output to our cache copy as well 
     5036            if ($output_filename ne $output_cache_copy) { 
     5037                unlink($output_cache_copy); 
     5038                open(F1,"<$output_filename"); 
     5039                open(F2,">$output_cache_copy"); 
     5040                while (<F1>) { 
     5041                    print F2 $_; 
     5042                } 
     5043                close(F1); 
     5044                close(F2); 
     5045            } 
     5046            &log("Cached output stored in $output_cache_copy.\n"); 
     5047        } 
     5048    } 
     5049 
     5050    if (!$opt->{'nooutput'} and ($reuse_cached_output or !$opt->{'output'})) { 
    49795051        &log("\nPrinting XMLTV output to STDOUT in 5 seconds...\n"); 
    49805052        sleep 5; 
  • trunk/status

    r1473 r1474  
    1 application     shepherd            1.8.8 
     1application     shepherd            1.9.0 
    22reference       channel_list        107 
    33reference       Shepherd/Common.pm  1.10 
Note: See TracChangeset for help on using the changeset viewer.