1 # Copyright (c) 2009 Symbian Foundation Ltd |
|
2 # This component and the accompanying materials are made available |
|
3 # under the terms of the License "Eclipse Public License v1.0" |
|
4 # which accompanies this distribution, and is available |
|
5 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
6 # |
|
7 # Initial Contributors: |
|
8 # Symbian Foundation Ltd - initial contribution. |
|
9 # |
|
10 # Contributors: |
|
11 # |
|
12 # Description: |
|
13 # Extracts output text in <buildlog> context which doesn't belong to <recipe>'s |
|
14 |
|
15 use strict; |
|
16 |
|
17 use XML::SAX; |
|
18 use RaptorSAXHandler; |
|
19 use Getopt::Long; |
|
20 |
|
21 my @logfiles; |
|
22 my $basedir = ''; |
|
23 my $help = 0; |
|
24 GetOptions(( |
|
25 'log:s' => \@logfiles, |
|
26 'basedir:s' => \$basedir, |
|
27 'help!' => \$help |
|
28 )); |
|
29 |
|
30 $help = 1 if (!@logfiles); |
|
31 |
|
32 if ($help) |
|
33 { |
|
34 print "Extracts text which doesn't belong to recipes from a raptor log file\n"; |
|
35 print "Usage: perl unreciped_text.pl --log=FILE1 --log=FILE2 [OPTIONS]\n"; |
|
36 print "where OPTIONS are:\n"; |
|
37 print "\t--basedir=DIR Generate output file under DIR\n"; |
|
38 exit(0); |
|
39 } |
|
40 |
|
41 my $reset_status = {}; |
|
42 my $buildlog_status = {}; |
|
43 my $buildlog_subtag_status = {}; |
|
44 |
|
45 $reset_status->{name} = 'reset_status'; |
|
46 $reset_status->{next_status} = {buildlog=>$buildlog_status}; |
|
47 |
|
48 $buildlog_status->{name} = 'buildlog_status'; |
|
49 $buildlog_status->{next_status} = {'?default?'=>$buildlog_subtag_status}; |
|
50 $buildlog_status->{on_start} = 'main::on_start_buildlog'; |
|
51 $buildlog_status->{on_end} = 'main::on_end_buildlog'; |
|
52 $buildlog_status->{on_chars} = 'main::on_chars_buildlog'; |
|
53 |
|
54 $buildlog_subtag_status->{name} = 'buildlog_subtag_status'; |
|
55 $buildlog_subtag_status->{next_status} = {}; |
|
56 |
|
57 my $characters = ''; |
|
58 |
|
59 if (!$basedir) |
|
60 { |
|
61 $basedir = time; |
|
62 |
|
63 print "Using $basedir as basedir.\n"; |
|
64 } |
|
65 if (-d $basedir) |
|
66 { |
|
67 print "Directory $basedir exists. Quitting.\n"; |
|
68 exit(1); |
|
69 } |
|
70 mkdir($basedir); |
|
71 #print "Created dir $basedir.\n"; |
|
72 |
|
73 my $saxhandler = RaptorSAXHandler->new(); |
|
74 $saxhandler->set_init_status($reset_status); |
|
75 my $parser = XML::SAX::ParserFactory->parser(Handler=>$saxhandler); |
|
76 for (@logfiles) |
|
77 { |
|
78 $parser->parse_uri($_); |
|
79 } |
|
80 |
|
81 |
|
82 sub on_start_buildlog |
|
83 { |
|
84 my $filename = "$basedir/unreciped.txt"; |
|
85 print "Writing unreciped file $filename\n" if (!-f$filename); |
|
86 open(FILE, ">>$filename"); |
|
87 } |
|
88 |
|
89 sub on_chars_buildlog |
|
90 { |
|
91 my ($ch) = @_; |
|
92 |
|
93 my $characters = $ch->{Data}; |
|
94 |
|
95 print FILE $characters if ($characters =~ m,[^\s^\r^\n],); |
|
96 |
|
97 #print "characters is now -->$characters<--\n"; |
|
98 } |
|
99 |
|
100 sub on_end_buildlog |
|
101 { |
|
102 close(FILE); |
|
103 } |
|