source: ProjectBuilder/devel/pb-modules/lib/ProjectBuilder/Log.pm@ 1109

Last change on this file since 1109 was 1109, checked in by Bruno Cornec, 13 years ago

r4041@localhost: bruno | 2010-11-17 11:40:41 +0100

  • Adds new configuration parameters (oschkcmd, oschkopt) to externalize package checking command
  • Adds new configuration parameters (pbinstalltype, pbpkg) to start allowing installation of pb in VM/VE with packages or files (this last is only needed by upstream)
  • Remove dependency on Mail::Sendmail to where it's really needed (part of Log, not used yet, and annouce). In particular this removes one non std dep for VE/VM build.
File size: 5.8 KB
Line 
1package ProjectBuilder::Log;
2
3# this class can be used to store and analyze the complete log from pb
4# this includes more than one vm
5
6use strict;
7use ProjectBuilder::Base;
8use ProjectBuilder::Log::Item;
9
10sub new {
11 # contains the object name (here PBLog)
12 my $object = shift;
13 my $self = {};
14
15 # $self should point to an object of type $object
16 bless($self, $object);
17
18 # this array stores our childs
19 $self->{'logitems'} = [];
20
21 return($self);
22}
23
24# returns number of handled ProjectBuilder::Log::Item's
25sub countItems {
26 my $self = shift;
27 return scalar(@{$self->{'logitems'}});
28}
29
30# returns an array of all names of handled ProjectBuilder::Log::Item's
31# the name is the vm name (e.g. ubuntu-10.04-i386 (by default))
32sub itemNames {
33 my $self = shift;
34 my @result = ();
35
36 foreach my $item (@{$self->{'logitems'}}) {
37 push(@result, $item->name());
38 }
39 return @result;
40}
41
42# set's the log for ProjectBuilder::Log::item $vmname
43# if such an item is not present, one is added
44# $log should only contain the log of one machine
45sub setLog {
46 my $self = shift;
47 my $vmname = shift;
48 my $log = shift;
49
50 my $logitem = $self->findItem($vmname);
51 if (!$logitem) {
52 $logitem = new ProjectBuilder::Log::Item($vmname);
53 push(@{$self->{'logitems'}}, $logitem);
54 }
55 $logitem->setLog($log);
56}
57
58# used to analyze the complete log of pb
59sub setCompleteLog {
60 my $self = shift;
61 my $log = shift;
62 my $tmplog = "";
63 my $item = undef;
64
65 foreach my $line (split("\n", $log)) {
66 if ($line =~ m/^Waiting [0-9]+ s for VM/) {
67 # here starts a new machine, so append the tmplog to the last one
68 if (defined($item)) {
69 $item->setLog($tmplog);
70 }
71 if($line =~ m/VM ([^\s]+)/){
72 $item = new ProjectBuilder::Log::Item($1);
73 push(@{$self->{'logitems'}}, $item);
74 $tmplog = 0;
75 }
76 } else {
77 $tmplog .= $line ."\n";
78 }
79 }
80 if (defined($item) && ($tmplog)) {
81 $item->setLog($tmplog);
82 }
83}
84
85# nums the issues (Warnings and Errors from lintian and rpmlint
86# if no name is given, the total of all ProjectBuilder::Log::Item's is returned
87sub numQaIssues {
88 my $self = shift;
89 my $itemname = shift || "";
90 my $result = 0;
91
92 if ($itemname eq "") {
93 # no machine selected, so return combine from all items
94 foreach my $item (@{$self->{'logitems'}}) {
95 $result += scalar($item->qaIssues());
96 }
97 } else {
98 my $item = $self->findItem($itemname);
99 if ($item) {
100 $result = $item->numQaIssues();
101 }
102 }
103 return $result;
104}
105
106# returns the issues itself
107# behaves like numQaIssues
108sub qaIssues {
109 my $self = shift;
110 my $itemname = shift || "";
111 my @result = ();
112
113 if ($itemname eq "") {
114 # no machine selected, so return combine from all items
115 foreach my $item (@{$self->{'logitems'}}) {
116 push(@result, $item->qaIssues());
117 }
118 } else {
119 my $item = $self->findItem($itemname);
120 if ($item) {
121 push(@result, $item->qaIssues());
122 }
123 }
124 return @result;
125}
126
127# same as num qaIssues but for compile errors
128sub numErrors {
129 my $self = shift;
130 my $itemname = shift || "";
131 my $result = 0;
132
133 if ($itemname eq "") {
134 # no machine selected, so return combine from all items
135 foreach my $item (@{$self->{'logitems'}}) {
136 $result += $item->numErrors();
137 }
138 } else {
139 my $item = $self->findItem($itemname);
140 if ($item) {
141 $result = $item->numErrors();
142 }
143 }
144 return $result;
145}
146
147# returns the compile errors itself
148# behaves like numQaIssues
149sub errors {
150 my $self = shift;
151 my $itemname = shift || "";
152 my @result = ();
153
154 if ($itemname eq "") {
155 # no machine selected, so return combine from all items
156 foreach my $item (@{$self->{'logitems'}}) {
157 push(@result, $item->errors());
158 }
159 } else {
160 my $item = $self->findItem($itemname);
161 if ($item) {
162 push(@result, $item->errors());
163 }
164 }
165 return @result;
166}
167
168# same as num qaIssues but for compile warnings
169sub numWarnings {
170 my $self = shift;
171 my $itemname = shift || "";
172 my $result = 0;
173
174 if ($itemname eq "") {
175 # no machine selected, so return combine from all items
176 foreach my $item (@{$self->{'logitems'}}) {
177 $result += $item->numWarnings();
178 }
179 } else {
180 my $item = $self->findItem($itemname);
181 if ($item) {
182 $result = $item->numWarnings();
183 }
184 }
185 return $result;
186}
187
188# returns the compile warnings itself
189# behaves like numQaIssues
190sub warnings {
191 my $self = shift;
192 my $itemname = shift || "";
193 my @result = ();
194
195 if ($itemname eq "") {
196 # no machine selected, so return combine from all items
197 foreach my $item (@{$self->{'logitems'}}) {
198 push(@result, $item->warnings());
199 }
200 } else {
201 my $item = $self->findItem($itemname);
202 if ($item) {
203 push(@result, $item->warnings());
204 }
205 }
206 return @result;
207}
208
209# prints out a summary of the log
210sub summary {
211 my $self = shift;
212 my $summary = "";
213
214 $summary = "Items: ". $self->countItems();
215 $summary .= " (QA Issues: ". $self->numQaIssues();
216 $summary .= ", Warnings: ". $self->numWarnings();
217 $summary .= ", Errors: ". $self->numErrors() .")\n";
218 foreach my $name ($self->itemNames()) {
219 $summary .= $name ." (QA Issues: ". $self->numQaIssues($name);
220 $summary .= ", Warnings: ". $self->numWarnings($name);
221 $summary .= ", Errors: ". $self->numErrors($name) .")\n";
222 }
223 return $summary;
224}
225
226# mails the summary to $to
227sub mailSummary {
228 require Mail::Sendmail;
229 my $self = shift;
230 my $to = shift || "";
231
232 if ($to eq "") {
233 pb_log(0,"Please give a To: address\n");
234 return;
235 }
236 my %mail = (
237 To => $to,
238 From => "pb\@localhost",
239 Message => $self->summary()
240 );
241 if (! sendmail(%mail)) {
242 if (defined $Mail::Sendmail::error) {
243 return $Mail::Sendmail::error;
244 } else {
245 return "Unkown error";
246 }
247 }
248 pb_log(0,"Mail send to ". $to ."\n");
249}
250
251# private part (perl does not no about private, but it is meant so)
252# find's item with name $vmname in handled OB::Log::Item's
253sub findItem {
254 my $self = shift;
255 my $vmname = shift;
256
257 # find existing item or add item if needed
258 foreach my $logitem (@{$self->{'logitems'}}) {
259 if ($logitem->name eq $vmname) {
260 return $logitem;
261 }
262 }
263 return 0;
264}
265
2661;
Note: See TracBrowser for help on using the repository browser.