This file is indexed.

/usr/share/perl5/AMC/Gui/Commande.pm is in auto-multiple-choice-common 1.2.1-3build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#! /usr/bin/perl -w
#
# Copyright (C) 2008-2012 Alexis Bienvenue <paamc@passoire.fr>
#
# This file is part of Auto-Multiple-Choice
#
# Auto-Multiple-Choice is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# Auto-Multiple-Choice is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Auto-Multiple-Choice.  If not, see
# <http://www.gnu.org/licenses/>.

package AMC::Gui::Commande;

use Gtk2::Helper;
use Encode;

use AMC::Basic;
use AMC::Gui::Avancement;

use AMC::Messages;

@ISA=("AMC::Messages");

sub new {
    my %o=(@_);
    my $self={
	'commande'=>'',
	'log'=>'',
	'avancement'=>'',
	'texte'=>'',
	'progres.id'=>'',
	'progres.pulse'=>'',
	'fin'=>'',
	'finw'=>'',
	'signal'=>9,
	'o'=>{},
	'clear'=>1,

	'messages'=>[],
	'variables'=>{},

	'pid'=>'',
	'avance'=>'',
	'fh'=>'',
	'tag'=>'',
	'pid'=>'',
    };

    for (keys %o) {
	$self->{$_}=$o{$_} if(defined($self->{$_}) || /^niveau/);
    }

    $self->{'commande'}=[$self->{'commande'}] if(!ref($self->{'commande'}));

    bless $self;

    return($self);
}

sub proc_pid {
    my ($self)=(@_);
    return($self->{'pid'});
}

sub erreurs {
    my ($self)=(@_);
    return($self->get_messages('ERR'));
}

sub variables {
    my ($self)=(@_);
    return(%{$self->{'variables'}});
}

sub variable {
    my ($self,$k)=(@_);
    return $self->{'variables'}->{$k};
}

sub quitte {
    my ($self)=(@_);
    my $pid=$self->proc_pid();
    debug "Canceling command [".$self->{'signal'}."->".$pid."].";

    kill $self->{'signal'},$pid if($pid =~ /^[0-9]+$/);
}

sub open {
    my ($self)=@_;

    $self->{'times'}=[times()];
    $self->{'pid'}=open($self->{'fh'},"-|",@{$self->{'commande'}});
    if(defined($self->{'pid'})) {

	$self->{'tag'}=Gtk2::Helper->add_watch( fileno( $self->{'fh'} ),
						in => sub { $self->get_output() }
						);

	debug "Command [".$self->{'pid'}."] : "
	  .join(' ',map { /\s/ || ! $_ ? "\"$_\"" : $_ }
		@{$self->{'commande'}});

	if($self->{'avancement'}) {
	    $self->{'avancement'}->set_text($self->{'texte'});
	    $self->{'avancement'}->set_fraction(0);
	    $self->{'avancement'}->set_pulse_step($self->{'progres.pulse'})
		if($self->{'progres.pulse'});
	}

	$self->{'avance'}=AMC::Gui::Avancement::new
	  (0,'bar'=>$self->{'avancement'});

	$self->{'log'}->get_buffer()->set_text('') if($self->{'clear'});

    } else {
	print STDERR "ERROR execing command\n".join(' ',@{$self->{'commande'}})."\n";
    }
}


sub get_output {
    my ($self)=@_;

    if( eof($self->{'fh'}) ) {
        Gtk2::Helper->remove_watch( $self->{'tag'} );
	  close($self->{'fh'});

	  debug "Command [".$self->{'pid'}."] : OK - ".($self->n_messages('ERR'))." erreur(s)\n";

	  my @tb=times();
	  debug sprintf("Total parent exec times during ".$self->{pid}.": [%7.02f,%7.02f]",$tb[0]+$tb[1]-$self->{'times'}->[0]-$self->{'times'}->[1],$tb[2]+$tb[3]-$self->{'times'}->[2]-$self->{'times'}->[3]);

	  $self->{'pid'}='';
	  $self->{'tag'}='';
	  $self->{'fh'}='';

	  $self->{'avancement'}->set_text('');

	  &{$self->{'finw'}}($self) if($self->{'finw'});
	  &{$self->{'fin'}}($self) if($self->{'fin'});

    } else {
	my $fh=$self->{'fh'};
	my $line = decode("utf8",<$fh>);
	my $r='';

	if($self->{'avancement'}) {
	    if($self->{'progres.pulse'}) {
		$self->{'avancement'}->pulse;
	    } else {
	      $self->{'avance'}->lit($line,
				     {'bar'=>$self->{'avancement'}});
	    }
	}

	if($r eq '') {
	  my $log=$self->{'log'};
	  my $logbuff=$log->get_buffer();

	  $logbuff->insert($logbuff->get_end_iter(),$line);
	  $logbuff->place_cursor($logbuff->get_end_iter());
	  $log->scroll_to_iter($logbuff->get_end_iter(),0,0,0,0);

	  if($line =~ /^(ERR|INFO|WARN)/) {
	    chomp(my $lc=$line);
	    $lc =~ s/^(ERR|INFO|WARN)[:>]\s*//;
	    $self->add_message($1,$lc);
	  }
	  if($line =~ /^VAR:\s*([^=]+)=(.*)/) {
	    $self->{'variables'}->{$1}=$2;
	  }
	  for my $k (qw/OK FAILED/) {
	    if($line =~ /^$k/) {
	      $self->{'variables'}->{$k}++;
	    }
	  }
	}


    }

    return 1;
}

1;