1 #!/usr/bin/perl -0777 -nl
6 Second implementations with a state machine. Much shorter and even
9 It's always an ugly step when going from text processing with console
10 escapes to XML processing
17 use Encode
qw(decode);
18 use Encode
::Detect
();
19 use File
::Path
qw(mkpath);
20 use List
::MoreUtils
qw(uniq);
21 use Time
::HiRes
qw(sleep time);
27 our $p = XML
::LibXML
->new;
30 our($perl_path) = m
|(/home\S+/installed
-perls
/(?
:.*?
)/p
.*?
/perl
-5.*?@
(?
:\d
+))|;
32 warn "Converting '$outdir'\n";
33 $outdir =~ s/.out$/.d/ or die;
35 my $perl = "$perl_path/bin/perl";
38 my($shortdistro,$log,$ok,$seq) = @_;
39 my $outfile = $shortdistro;
40 $outfile =~ s!\.(tar.gz|tgz|tar.bz2|tbz|zip)?$!.xml!;
41 $outfile =~ s
|$|.xml
| unless $outfile =~ /\.xml$/;
43 $outfile =~ s
|^|$outdir/|;
44 my($time) = $outdir =~ /(\d{8}T\d{4})/;
45 open my $fh, ">:utf8", $outfile or die;
46 for ($time,$perl_path,$shortdistro,$ok) {
52 my $ulog = decode
("Detect",$log);
53 my $dumper = Dumpvalue
->new(unctrl
=> "unctrl");
54 $ulog =~ s/([\x00-\x09\x0b\x0c\x0e-\x1f])/ $dumper->stringify($1,1) /ge;
55 $ulog =~ s
|^</span
>||;
56 $ulog .= q
|</span>| if $ulog =~ /<span
[^<>]+>[^<]+$/;
57 $ulog = qq{<distro
time="$time" perl
="$perl_path" distro
="$shortdistro" ok
="$ok" seq
="$seq">$ulog</distro
>\n};
60 die "cannot parse '$shortdistro': [$ulog]" unless eval { $p->parse_string($ulog); 1 };
68 warn sprintf "[%s] since last measure[%.4f]\n", shift, time - $start;
73 # the first part is a duplication of colorterm-to-html.pl which I
74 # wrote for my Munich talk:
76 my%h=("&"=>"&",q
!"!=>""
;","<"=>"<",">"=>">");
79 s!\e\[1;3[45](?:;\d+)?m(.*?)\e\[0m!<span style="color: blue">$1</span>!sg;
81 s!\e\[1;31(?:;\d+)?m(.*?)\e\[0m!<span style="color: red">$1</span>!sg;
87 our $HTMLSPANSTUFF = qr/(?:<[^<>]+>)*/;
89 my @lines = split /\n/, $_;
91 my %seq; # $seq{$shortdistro} = [];
95 LINE: while (defined($_ = shift @lines)) {
98 \Q>Running install for module '\E
99 |>\S+\Q is up to date \E\(
102 } elsif (m!<span[^<>]+>Running (?:make|Build) for (.+)!) {
106 push @longdistro, $d;
107 $d =~ s|^[A-Z]/[A-Z][A-Z]/||;
108 push @shortdistro, $d;
109 $seq{$shortdistro[-1]} ||= [];
110 } elsif (m|[ ]{2}\Q$shortdistro[-1]\E|) {
111 push @{$seq{$shortdistro[-1]}}, $_;
114 if ($lines[0] =~ /[ ]{2}.+[ ]install[ ].*?--\s+((?:NOT\s)?OK|NA)/) {
116 push @{$seq{$shortdistro[-1]}}, shift @lines;
118 } elsif ($lines[0] =~ /[ ]{2}.+\s+--\s+((?:NOT\s)?OK|NA)/) {
120 push @{$seq{$shortdistro[-1]}}, shift @lines;
121 if ($lines[0] =~ /\bPrepending\b.*\bPERL5LIB\b/) {
122 push @{$seq{$shortdistro[-1]}}, shift @lines;
124 if ($lines[0] =~ />Running.*test/
125 && $lines[1] =~ />[ ]{2}/) {
126 push @{$seq{$shortdistro[-1]}}, shift @lines;
127 push @{$seq{$shortdistro[-1]}}, shift @lines;
130 if ($lines[0] =~ />Running.*install/
131 && $lines[1] =~ />[ ]{2}/) {
132 push @{$seq{$shortdistro[-1]}}, shift @lines;
133 push @{$seq{$shortdistro[-1]}}, shift @lines;
136 if ($lines[0] =~ />\/\/hint\/\//) {
137 push @{$seq{$shortdistro[-1]}}, shift @lines;
138 push @{$seq{$shortdistro[-1]}}, shift @lines while $lines[0] =~ /^\s/;
147 my $log = join "", map { "$_\n" } @{$seq{$shortdistro[-1]}};
148 mystore($shortdistro[-1],$log,$ok,$i);
149 delete $seq{$shortdistro[-1]};
155 push @{$seq{$shortdistro[-1]}}, $_;
157 open my $rfh, ">", "$outdir/residuum
.yml
" or die;
158 print $rfh YAML::Syck::Dump(\%seq);
163 open my $fh, ">", "$outdir/perl-V.txt" or die "Could not open >$outdir/perl
-V
.txt
: $!";
164 open my $pfh, "-|", $perl, "-V
" or die "cannot
fork: $!";
168 close $pfh or die "perl died during
-V
";
169 close $fh or die "could
not write '$outdir/perl-V.txt': $!";