lilalo

changeset 80:d28dda8ea18f

1)
Изменён формат имени diff-файлов.
Теперь в имени присутствует только название сессии, время и имя файла.

2)
Можно просмотреть отдельную сессию.
Для этого нужно щёлкнуть по блоку сессии в журнале

3)
Исправлена ошибка с таблицей новых команд в последнем дне.
Раньше она просто не показывалась

4)
Запись lablog-ов теперь ведётся только для интерактивных shell'ов
Неинтерактивные работают как обычно.
author devi
date Mon Feb 20 17:52:40 2006 +0200 (2006-02-20)
parents 44973d76ba4d
children d9a700d48bef
files l3-agent l3-cgi l3-frontend l3bashrc
line diff
     1.1 --- a/l3-agent	Sun Feb 19 16:02:42 2006 +0200
     1.2 +++ b/l3-agent	Mon Feb 20 17:52:40 2006 +0200
     1.3 @@ -58,36 +58,36 @@
     1.4          for my $file (@files) {
     1.5  
     1.6              next if defined($Diffs{$file});
     1.7 -            
     1.8              my %diff;
     1.9 -            
    1.10 -            $diff{"path"}=$path;
    1.11 -            $diff{"uid"}="SET THIS";
    1.12  
    1.13 -# Сейчас UID определяется из названия каталога
    1.14 -# откуда берутся diff-файлы
    1.15 -# Это неправильно
    1.16 -#
    1.17 -# ВАРИАНТ:
    1.18 -# К файлам жураналам должны прилагаться ситемны файлы, 
    1.19 -# мз которых и будет определяться соответствие 
    1.20 -# имён пользователей их uid'ам
    1.21 -#
    1.22 -            $diff{"uid"} = 0 if $path =~ m@/root/@; 
    1.23 -            
    1.24 -            $diff{"bind_to"}="";
    1.25 -            $diff{"time_range"}=-1;
    1.26 -        
    1.27 -            next if not $file=~m@/(D?[0-9][0-9]?[0-9]?)[^/]*?([0-9]*):([0-9]*):?([0-9]*)@;
    1.28 -            $diff{"day"}=$1 || "";
    1.29 -            $diff{"hour"}=$2;
    1.30 -            $diff{"min"}=$3;
    1.31 -            $diff{"sec"}=$4 || 0;
    1.32 -            
    1.33 -            $diff{"index"}=$i;
    1.34 +# Старый формат имени diff-файла
    1.35 +# DEPRECATED
    1.36 +            if ($file=~m@/(D?[0-9][0-9]?[0-9]?)[^/]*?([0-9]*):([0-9]*):?([0-9]*)@) {
    1.37 +                $diff{"day"}=$1 || "";
    1.38 +                $diff{"hour"}=$2;
    1.39 +                $diff{"min"}=$3;
    1.40 +                $diff{"sec"}=$4 || 0;
    1.41 +
    1.42 +                $diff{"uid"} = 0 if $path =~ m@/root/@; 
    1.43  
    1.44              print "diff loaded: $diff{day} $diff{hour}:$diff{min}:$diff{sec}\n";
    1.45 -            
    1.46 +
    1.47 +            }
    1.48 +# Новый формат имени diff-файла
    1.49 +            elsif ($file =~ m@.*/([^_]*)_([0-9]+)(.*)@) {
    1.50 +                $diff{"local_session_id"} = $1;
    1.51 +                $diff{"time"} = $2;
    1.52 +                $diff{"filename"} = $3;
    1.53 +                $diff{"filename"} =~ s@_@/@g;
    1.54 +                $diff{"filename"} =~ s@//@_@g;
    1.55 +
    1.56 +                print "diff loaded: $diff{filename} (time=$diff{time},session=$diff{local_session_id})\n";
    1.57 +            }
    1.58 +            else {
    1.59 +                next;
    1.60 +            }
    1.61 +
    1.62 +# Чтение и изменение кодировки содержимого diff-файла
    1.63              local $/;
    1.64              open (F, "$file")
    1.65                  or return "Can't open file $file ($_[0]) for reading";
    1.66 @@ -98,9 +98,12 @@
    1.67              }
    1.68              close(F);   
    1.69              $diff{"text"}=$text;
    1.70 -            #print "$file loaded ($diff{day})\n";
    1.71  
    1.72 -            #push @Diffs, \%diff;
    1.73 +            $diff{"path"}=$path;
    1.74 +            $diff{"bind_to"}="";
    1.75 +            $diff{"time_range"}=-1;
    1.76 +            $diff{"index"}=$i;
    1.77 +
    1.78              $Diffs{$file} = \%diff;
    1.79              $i++;
    1.80          }
    1.81 @@ -110,11 +113,6 @@
    1.82  
    1.83  sub bind_diff
    1.84  {
    1.85 -#   my $path = shift;
    1.86 -#   my $pid = shift;
    1.87 -#   my $day = shift;
    1.88 -#   my $lab = shift;
    1.89 -
    1.90      print "Trying to bind diff...\n";
    1.91  
    1.92      my $cl = shift;
    1.93 @@ -126,12 +124,24 @@
    1.94  
    1.95      for my $diff_key (keys %Diffs) {
    1.96              my $diff = $Diffs{$diff_key};
    1.97 -            # Check here date, time and user
    1.98 +            next if ($diff->{"local_session_id"} 
    1.99 +                    && $cl->{"local_session_id"} 
   1.100 +                    && ($cl->{"local_session_id"} ne $diff->{"local_session_id"}));
   1.101 +            print "diff of my session found\n";
   1.102 +
   1.103              next if ($diff->{"day"} && $cl->{"day"} && ($cl->{"day"} ne $diff->{"day"}));
   1.104 -            #next if (!$diff->{"uid"} && $cl->{"euid"} != $diff->{"uid"});
   1.105 -            
   1.106 -            my $dt=($diff->{"hour"}-$hour)*3600 +($diff->{"min"}-$min)*60 + ($diff->{"sec"}-$sec);
   1.107 -            if ($dt >0  && $dt < $min_dt && ($diff->{"time_range"} <0 || $dt < $diff->{"time_range"})) {
   1.108 +
   1.109 +            my $dt;
   1.110 +            if ($diff->{"time"} && $cl->{"time"}) {
   1.111 +                $dt = $diff->{"time"} - $cl->{"time"}
   1.112 +            }
   1.113 +            else {
   1.114 +                $dt=($diff->{"hour"}-$hour)*3600 +($diff->{"min"}-$min)*60 + ($diff->{"sec"}-$sec);
   1.115 +            }
   1.116 +            if ($dt >0  
   1.117 +                    && $dt < $min_dt 
   1.118 +                    && ($diff->{"time_range"} <0 
   1.119 +                    || $dt < $diff->{"time_range"})) {
   1.120                  print "Approppriate diff found: dt=$dt\n";
   1.121                  if ($diff->{"bind_to"}) {
   1.122                      undef $diff->{"bind_to"}->{"diff"};
   1.123 @@ -141,7 +151,7 @@
   1.124  
   1.125                  $cl->{"diff"} = $diff_key;
   1.126                  $min_dt = $dt;  
   1.127 -        }
   1.128 +            }
   1.129      }
   1.130  }
   1.131  
   1.132 @@ -281,7 +291,7 @@
   1.133  
   1.134          $file =~ m@.*/(.*?)-.*@;
   1.135  
   1.136 -        print "+- processing file $file\n" if $Config{"verbose"} =~/y/;
   1.137 +        print "\n+- processing file $file\n" if $Config{"verbose"} =~/y/;
   1.138  
   1.139          my $tty = $1;
   1.140          my $first_pass = 1;
     2.1 --- a/l3-cgi	Sun Feb 19 16:02:42 2006 +0200
     2.2 +++ b/l3-cgi	Mon Feb 20 17:52:40 2006 +0200
     2.3 @@ -13,7 +13,7 @@
     2.4  
     2.5  my %filter;
     2.6  
     2.7 -for my $key (qw(login_from)) {
     2.8 +for my $key (qw(login_from local_session_id)) {
     2.9  	$filter{$key} =  param($key) if param($key);
    2.10  	$filter{$key} = $ENV{$key} if defined $ENV{$key};
    2.11  }
     3.1 --- a/l3-frontend	Sun Feb 19 16:02:42 2006 +0200
     3.2 +++ b/l3-frontend	Mon Feb 20 17:52:40 2006 +0200
     3.3 @@ -394,6 +394,7 @@
     3.4      
     3.5      my $cl;
     3.6      my $last_tty="";
     3.7 +    my $last_session="";
     3.8      my $last_day=q();
     3.9      my $last_wday=q();
    3.10      my $in_range=0;
    3.11 @@ -565,11 +566,20 @@
    3.12                  for my $entry_class (sort keys %new_entries_of) {
    3.13                      my $new_commands_section = make_new_entries_table($entry_class=~/[0-9]+\s+(.*)/, \@known_commands);
    3.14  
    3.15 -                    my $table_caption = "Таблица ".$table_number++.". ".$Day_Name[$last_wday].". Новые ".$new_entries_of{$entry_class};
    3.16 +                    my $table_caption = "Таблица "
    3.17 +                                      . $table_number++
    3.18 +                                      . ". "
    3.19 +                                      . $Day_Name[$last_wday]
    3.20 +                                      . ". Новые "
    3.21 +                                      . $new_entries_of{$entry_class};
    3.22                      if ($new_commands_section) {
    3.23                          $result .= "<table class='new_commands_table' width='700' cellspacing='0' cellpadding='0'>"
    3.24 -                                .  "<tr class='new_commands_caption'><td colspan='2' align='right'>$table_caption</td></tr>"
    3.25 -                                .  "<tr class='new_commands_header'><td width=100>Команда</td><td width=600>Описание</td></tr>"
    3.26 +                                .  "<tr class='new_commands_caption'>"
    3.27 +                                .  "<td colspan='2' align='right'>$table_caption</td>"
    3.28 +                                .  "</tr>"
    3.29 +                                .  "<tr class='new_commands_header'>"
    3.30 +                                .  "<td width=100>Команда</td><td width=600>Описание</td>"
    3.31 +                                .  "</tr>"
    3.32                                  .  $new_commands_section 
    3.33                                  .  "</table>"
    3.34                      }
    3.35 @@ -637,6 +647,15 @@
    3.36              $last_tty=$cl->{"tty"};
    3.37          }
    3.38  
    3.39 +# Session change
    3.40 +        if ( $last_session ne $cl->{"local_session_id"}) {
    3.41 +            my $tty = $cl->{"tty"};
    3.42 +            $this_day_result .= "<a href='?local_session_id=".$cl->{"local_session_id"}."'><div class='ttychange'>"
    3.43 +                                . $Sessions{$cl->{"local_session_id"}}->{"tty"}
    3.44 +                                ."</div></a>";
    3.45 +            $last_session=$cl->{"local_session_id"};
    3.46 +        }
    3.47 +
    3.48  # TIME
    3.49          $this_day_result .= "<div class='time'>$hour:$min:$sec</div>" 
    3.50                              if $Config{"show_time"} =~ /^y/i;
    3.51 @@ -725,24 +744,29 @@
    3.52          $result .= "<h3 id='day$last_day'>".$Day_Name[$last_wday]."</h3>";
    3.53  
    3.54          for my $entry_class (keys %new_entries_of) {
    3.55 -            my $new_commands_section = make_new_entries_table("$entry_class", \@known_commands);
    3.56 -            @known_commands = keys %CommandsFDistribution;
    3.57 -
    3.58 -            my $table_caption = "Таблица ".$table_number++.". Новые ".$new_entries_of{$entry_class}. ". ".$Day_Name[$last_wday];
    3.59 +            my $new_commands_section = make_new_entries_table($entry_class=~/[0-9]+\s+(.*)/, \@known_commands);
    3.60 +            my $table_caption = "Таблица "
    3.61 +                                . $table_number++
    3.62 +                                . ". "
    3.63 +                                . $Day_Name[$last_wday]
    3.64 +                                . ". Новые "
    3.65 +                                . $new_entries_of{$entry_class};
    3.66              if ($new_commands_section) {
    3.67 -                $result .= "<table class='new_commands_table'>"
    3.68 -                        .  "<tr class='new_commands_caption'><td colspan='2' align='right'>$table_caption</td></tr>"
    3.69 -                        .  "<tr class='new_commands_header'><td width='200'>Команда</td><td width='600'>Описание</td></tr>"
    3.70 +                $result .= "<table class='new_commands_table' width='700' cellspacing='0' cellpadding='0'>"
    3.71 +                        .  "<tr class='new_commands_caption'>"
    3.72 +                        .  "<td colspan='2' align='right'>$table_caption</td>"
    3.73 +                        .  "</tr>"
    3.74 +                        .  "<tr class='new_commands_header'>"
    3.75 +                        .  "<td width=100>Команда</td><td width=600>Описание</td>"
    3.76 +                        .  "</tr>"
    3.77                          .  $new_commands_section 
    3.78                          .  "</table>"
    3.79 -                        ;
    3.80              }
    3.81  
    3.82          }
    3.83 +        @known_commands = keys %CommandsFDistribution;
    3.84  
    3.85 -        #$result .= "<table width='100%'>\n";
    3.86          $result .= $this_day_result;
    3.87 -        #$result .= "</table>";
    3.88     }
    3.89  
    3.90      return ($result, collapse_list (\@toc));
     4.1 --- a/l3bashrc	Sun Feb 19 16:02:42 2006 +0200
     4.2 +++ b/l3bashrc	Mon Feb 20 17:52:40 2006 +0200
     4.3 @@ -17,6 +17,7 @@
     4.4  
     4.5  _l3_start()
     4.6  {
     4.7 +    echo $- | grep -q i || return 0
     4.8      if _l3_is_running_here
     4.9      then
    4.10          _l3_env
    4.11 @@ -145,12 +146,15 @@
    4.12                  TIME=\"\`date +%s\`\"
    4.13                  DIR=\"\"
    4.14                  [ \"\${1#/}\" = \"\$1\" ] && DIR=\"\$PWD/\"
    4.15 -                DIFFNAME=\"\$PPID_\${TIME}_\`echo \$DIR\$1| /bin/sed s@_@__@ | /bin/sed 's@/@_@g'\`.diff\"
    4.16 +                DIFFNAME=\"\${L3_SESSION_ID}_\${TIME}\`echo \$DIR\$1| sed s@_@__@ | sed 's@/@_@g'\`.diff\"
    4.17                  old_file=\"/tmp/l3-saved-\$\$.\$RANDOM.\$RANDOM\"
    4.18                  /bin/cp -- \"\$1\" \"\$old_file\" 2> /dev/null
    4.19                  $editor_file \"\$@\" || ERR=\$?
    4.20 -                [ -e \"\$old_file\" ] && diff \"\$old_file\" \"\$1\" > \"\$L3_HOME/\$DIFFNAME\" 2> /dev/null \
    4.21 -                                  || diff /dev/null \"\$1\"  > \"\$L3_HOME/\$DIFFNAME\" 2> /dev/null
    4.22 +                [ -e \"\$old_file\" ] && diff \"\$old_file\" \"\$1\" > \"\$L3_HOME/\$DIFFNAME\" 2> /dev/null
    4.23 +                if [ "$?" == 2 ] 
    4.24 +                then 
    4.25 +                    diff /dev/null \"\$1\"  > \"\$L3_HOME/\$DIFFNAME\" 2> /dev/null
    4.26 +                fi
    4.27                  /bin/rm \"\$old_file\" 2> /dev/null
    4.28                  return \$ERR
    4.29              fi