lilalo

changeset 150:822b36252d7f

Вывод больших фрагментов текста не теряется.

Большие фрагменты текста теперь не вырезаются бесследно.
Там, откуда они вырезаются, вставляются ссылки,
по которым можно посмотреть полную версию вывода.
Испытано на больших фрагментах текста,
содержащих до 5000 строк (фрагменты более 5000 строк по умолчанию
обрезаются административно; допустимые размеры задаются в l3config.pm).
Исправлены ошибки, из-за которых большие фрагменты
обрабатывались некорректно.
author igor@chub.in
date Tue Jun 23 01:15:02 2009 +0300 (2009-06-23)
parents 40d843395547
children 80691b40e6db
files l3-agent l3-cgi-lite l3-frontend l3pre.php
line diff
     1.1 --- a/l3-agent	Fri Mar 06 13:34:59 2009 +0600
     1.2 +++ b/l3-agent	Tue Jun 23 01:15:02 2009 +0300
     1.3 @@ -344,6 +344,7 @@
     1.4          my $tty = $1;
     1.5          my %cl;
     1.6          my $last_output_length=0;
     1.7 +	my $saved_output;
     1.8          while (<FILE>) {
     1.9              $commandlines_processed++;
    1.10  
    1.11 @@ -555,6 +556,7 @@
    1.12  
    1.13                  # Output
    1.14                  if (!$last_cl{"suppress_output"} || $last_cl{"err"}) {
    1.15 +                    $last_cl{"output"}=$saved_output;
    1.16                      for (my $i=0; $i<$Config{"terminal_height"}; $i++) {
    1.17                          my $line= $vt{$local_session_id}->row_plaintext($i);
    1.18                          next if !defined ($line) ; #|| $line =~ /^\s*$/;
    1.19 @@ -568,6 +570,7 @@
    1.20                  }
    1.21  
    1.22                  $vt{$local_session_id}->reset();
    1.23 +		$saved_output="";
    1.24  
    1.25  
    1.26                  # Changing encoding 
    1.27 @@ -588,6 +591,20 @@
    1.28                  next;
    1.29              }
    1.30  
    1.31 +            if (($commandlines_processed%100) == 0) {
    1.32 +# Каждые сто строк обнуляем терминал и переносим вывод из него в кэш
    1.33 +                # Output
    1.34 +	        for (my $i=0; $i<$Config{"terminal_height"}; $i++) {
    1.35 +	   	    my $line= $vt{$local_session_id}->row_plaintext($i);
    1.36 +		    next if !defined ($line) ; #|| $line =~ /^\s*$/;
    1.37 +		    $line =~ s/\s*$//;
    1.38 +		    $line .= "\n" unless $line =~ /^\s*$/;
    1.39 +		    $saved_output .= $line;
    1.40 +	        }
    1.41 +                $vt{$local_session_id}->reset();
    1.42 +                $last_output_length=0;
    1.43 +	    }
    1.44 +
    1.45  # Иначе, это строка вывода
    1.46  
    1.47              $last_output_length+=length($_);
     2.1 --- a/l3-cgi-lite	Fri Mar 06 13:34:59 2009 +0600
     2.2 +++ b/l3-cgi-lite	Tue Jun 23 01:15:02 2009 +0300
     2.3 @@ -6,7 +6,8 @@
     2.4  
     2.5  BEGIN {
     2.6      chdir("/etc/lilalo/");
     2.7 -    require l3config;
     2.8 +    require "/etc/lilalo/l3config.pm"
     2.9 +        or die " Can't open l3config.pm ";
    2.10      l3config::init_config();
    2.11  };
    2.12  
    2.13 @@ -27,10 +28,12 @@
    2.14  my $commands_to_show_at_a_go = $l3config::Config{"commands_to_show_at_a_go"};
    2.15  my $start_from_command = "0";
    2.16  my $this_page_number=0;
    2.17 +my $page_id;
    2.18  if ($path =~ s/:(.*)//) {
    2.19      $this_page_number = $1;
    2.20      $start_from_command = $this_page_number*$commands_to_show_at_a_go;
    2.21  }
    2.22 +$page_id=$this_page_number;
    2.23  
    2.24  my $real_path = $l3config::Config{"backend_datadir"} ;
    2.25  my $cgi_path = $l3config::Config{"cgi_path"} ;
    2.26 @@ -38,6 +41,10 @@
    2.27  my $frontend_css = $l3config::Config{"frontend_css"} ;
    2.28  
    2.29  my $filter=$ENV{QUERY_STRING};
    2.30 +if ($filter =~ s@command_id=([0-9]+)@@){
    2.31 +   $l3config::Config{"command_id"}=$1;
    2.32 +   $page_id=$1;
    2.33 +}
    2.34  if ($filter =~ /page=([^&]*)/ ) {
    2.35      open(PAGE_NAME, "grep $1 $real_path/sessions-index | tail -1 | sed 's^-<.*^^; s^/[^/]*\$^^'| ");
    2.36      my $page_name;
    2.37 @@ -84,11 +91,18 @@
    2.38  
    2.39      unless ( -e "$real_path/$data_file"
    2.40               && -e "$real_path/index.html" 
    2.41 -             && (stat("$real_path/index.html"))[9] > (stat("$real_path/$data_file"))[9] && 0!=0 ) {
    2.42 +             && (stat("$real_path/index$page_id.html"))[9] > (stat("$real_path/$data_file"))[9]) {
    2.43  
    2.44 +        my $fragment_options;
    2.45 +        if ($l3config::Config{"command_id"}) {
    2.46 +            $fragment_options = " --command_id ".$l3config::Config{"command_id"};
    2.47 +        }
    2.48 +        else {
    2.49 +            $fragment_options = " --start_from_command $start_from_command ";
    2.50 +        }
    2.51          my $l3_frontend = "l3-frontend --backend_datafile $real_path/$data_file".
    2.52 -                                     " --output $real_path/index.html".
    2.53 -                                     " --start_from_command $start_from_command ".
    2.54 +                                     $fragment_options.
    2.55 +                                     " --output $real_path/index$page_id.html".
    2.56                                       " --filter '$filter'";
    2.57          system($l3_frontend) == 0
    2.58              or error("Файл журнала найден, но возникла ошибка при его обработке:<br/> $!");
    2.59 @@ -96,7 +110,7 @@
    2.60  
    2.61      {
    2.62          local $/;
    2.63 -        open(HTML, "<:utf8", "$real_path/index.html");
    2.64 +        open(HTML, "<:utf8", "$real_path/index$page_id.html");
    2.65          my $html = <HTML>;
    2.66  
    2.67  # Добавим в начало документа навигационную строку
     3.1 --- a/l3-frontend	Fri Mar 06 13:34:59 2009 +0600
     3.2 +++ b/l3-frontend	Tue Jun 23 01:15:02 2009 +0300
     3.3 @@ -354,7 +354,12 @@
     3.4      $dir=$_[0];
     3.5      for $i (glob("$dir/*.png")) {
     3.6        $i =~ s@.*/(([0-9-]+)_([0-9]+).*)@$1@;
     3.7 -      $Uploads{$2}{$3}=$i;
     3.8 +      if (defined($Uploads{$2}{$3})) {
     3.9 +        $Uploads{$2}{$3} .= " ".$i;
    3.10 +      }
    3.11 +      else {
    3.12 +        $Uploads{$2}{$3}=$i;
    3.13 +      }
    3.14      }
    3.15  }
    3.16  
    3.17 @@ -633,7 +638,7 @@
    3.18  
    3.19          my $cl=$Command_Lines[$Command_Lines_Index[$current_command++]];
    3.20          next unless $cl;
    3.21 -        my $next_cl=$Command_Lines[$Command_Lines_Index[$current_command+1]];
    3.22 +        my $next_cl=$Command_Lines[$Command_Lines_Index[$current_command]];
    3.23  
    3.24          next if $current_command < $Config{"start_from_command"};
    3.25          last if $current_command > $Config{"start_from_command"} + $Config{"commands_to_show_at_a_go"};
    3.26 @@ -834,23 +839,28 @@
    3.27              if ( $Config{"show_diffs"} =~ /^y/i && $cl->{"diff"});
    3.28  # SHOT
    3.29  
    3.30 -        $this_day_result .= join(".", key(%Uploads));
    3.31 -        $this_day_result .= "PRIVET";
    3.32 +        #$this_day_result .= join(".", keys(%Uploads));
    3.33 +        #$this_day_result .= "PRIVET";
    3.34          for $t (sort { $a <=> $b } keys %{ $Uploads{$cl->{"local_session_id"}} }) {
    3.35 -        #    if ($t > $cl->{"time"} && $t < $next_cl->{"time"}) {
    3.36 -            $this_day_result .= "<IMG src='"
    3.37 -                .$Config{l3shot_path}
    3.38 -                .$Uploads{$cl->{"local_session_id"}}
    3.39 -                ."' alt ='screenshot id ".$cl->{"screenshot"}
    3.40 -                ."'/>"
    3.41 +            if (($t >= $cl->{"time"} and $t < $next_cl->{"time"}) or ($t >= $cl->{"time"} and not defined($next_cl))) {
    3.42 +                my @shots=split(/\s+/, $Uploads{$cl->{"local_session_id"}}{$t});
    3.43 +                for my $shot (@shots) {
    3.44 +                    $this_day_result .= "<IMG src='"
    3.45 +                        .$Config{l3shot_path}
    3.46 +                        .$shot
    3.47 +                        ."' alt ='screenshot id ".$shot
    3.48 +                        ."'/><br/>"
    3.49 +                }
    3.50 +            }
    3.51          }
    3.52  
    3.53 -        $this_day_result .= "<img src='"
    3.54 -                .$Config{l3shot_path}
    3.55 -                .$cl->{"screenshot"}
    3.56 -                ."' alt ='screenshot id ".$cl->{"screenshot"}
    3.57 -                ."'/>"
    3.58 -            if ( $Config{"show_screenshots"} =~ /^y/i && $cl->{"screenshot"});
    3.59 +# Временно заблокировано
    3.60 +#        $this_day_result .= "<img src='"
    3.61 +#                .$Config{l3shot_path}
    3.62 +#                .$cl->{"screenshot"}
    3.63 +#                ."' alt ='screenshot id ".$cl->{"screenshot"}
    3.64 +#                ."'/>"
    3.65 +#            if ( $Config{"show_screenshots"} =~ /^y/i && $cl->{"screenshot"});
    3.66  
    3.67  #NOTES
    3.68          if ( $Config{"show_notes"} =~ /^y/i && $cl->{"note"}) {
     4.1 --- a/l3pre.php	Fri Mar 06 13:34:59 2009 +0600
     4.2 +++ b/l3pre.php	Tue Jun 23 01:15:02 2009 +0300
     4.3 @@ -1,14 +1,35 @@
     4.4  <?
     4.5 +$wgHooks['ParserAfterTidy'][] = 'wfLiLaLoParserAfterTidy';
     4.6  $wgExtensionFunctions[] = "wfLiLaLoExtension";
     4.7  
     4.8 +/*
     4.9 +
    4.10 +More on this technic:
    4.11 +http://www.mediawiki.org/wiki/Manual:Tag_extensions#How_can_I_avoid_modification_of_my_extension.27s_HTML_output.3F
    4.12 +
    4.13 +
    4.14 +HTML tooltips from:
    4.15 +http://www.walterzorn.com/tooltip/tooltip_e.htm#download
    4.16 +
    4.17 +Also:
    4.18 +http://sixrevisions.com/tutorials/javascript_tutorial/create_lightweight_javascript_tooltip/
    4.19 +
    4.20 +*/
    4.21 +
    4.22  function wfLiLaLoExtension() {
    4.23      global $wgParser;
    4.24      $wgParser->setHook( "lilalo", "renderLiLaLoPRE" );
    4.25 +    global $wgOut;
    4.26 +    $wgOut->addHTML('<script src="/js/wz_tooltip.js"></script>');
    4.27  }
    4.28  
    4.29 +$markerList = array();
    4.30 +
    4.31  function renderLiLaLoPRE( $input ) {
    4.32 +    global $markerList;
    4.33      preg_match('/[^\n]*l3: local_session_id=([0-9-]*)[^\n]*[\n]/', $input, $matches);
    4.34      $session_id=$matches[1];
    4.35 +    if ($session_id) {
    4.36      preg_match('/([0-9]*)-([0-9]*)/', $session_id, $matches);
    4.37      $session_start_time = intval($matches[2]);
    4.38      $hour=intval(date('G', $session_start_time));
    4.39 @@ -21,7 +42,36 @@
    4.40                               .'">$5</a></b>\'', 
    4.41                            $input);
    4.42  #                             .strval($session_start_time+3600*(intval($2)-$hour)+60*(intval($3)-$min)+(intval($4)-$sec))
    4.43 -    return "<pre>$hour:$min:$sec $input</pre>";
    4.44 +        $time_prefix="$hour:$min:$sec ";
    4.45 +    }
    4.46 +    else 
    4.47 +    {
    4.48 +        $tip_text='<table><tr><td>-n</td><td>show numerical addresses instead of trying to determine symbolic  host  names.<br/>  This  is useful if you are trying to determine why the route to your nameserver has vanished.</td></tr></table>';
    4.49 +        #$tip_text='<dv>1</dv>';
    4.50 +        $tip=" onmouseover=\"Tip('".$tip_text."')\" onmouseout=\"UnTip()\"";
    4.51 +        $input = preg_replace('/(%#.*)/', '<span style="font-weight:bold"'.$tip.'>$1</span>', $input);
    4.52 +    }
    4.53 +    $output = "<pre>$time_prefix$input</pre>";
    4.54 +    $markercount = count($markerList);
    4.55 +    $marker = "xx-lilalo-marker".$markercount."-xx";
    4.56 +    $markerList[$markercount] = $output;
    4.57 +    return $marker;
    4.58 +
    4.59  }
    4.60  
    4.61 +function wfLiLaLoParserAfterTidy(&$parser, &$text) {
    4.62 +    // find markers in $text
    4.63 +    // replace markers with actual output
    4.64 +    global $markerList;
    4.65 +    $keys = array();
    4.66 +    $marker_count = count($markerList);
    4.67 + 
    4.68 +    for ($i = 0; $i < $marker_count; $i++) {
    4.69 +        $keys[$i] = 'xx-lilalo-marker' . $i . '-xx';
    4.70 +    }
    4.71 + 
    4.72 +    $text = str_replace($keys, $markerList, $text);
    4.73 +#$text = $marker_count;
    4.74 +    return true;
    4.75 +}
    4.76  ?>