|
1 #!perl |
|
2 |
|
3 # CProgressLog |
|
4 |
|
5 # Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 # All rights reserved. |
|
7 # This component and the accompanying materials are made available |
|
8 # under the terms of "Eclipse Public License v1.0" |
|
9 # which accompanies this distribution, and is available |
|
10 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
11 # |
|
12 # Initial Contributors: |
|
13 # Nokia Corporation - initial contribution. |
|
14 # |
|
15 # Contributors: |
|
16 # |
|
17 # Description: |
|
18 # |
|
19 |
|
20 package CProgressLog; |
|
21 |
|
22 # Constructor |
|
23 # |
|
24 # Parameters: Verbosity - 0 for batch operation (no progress reports) |
|
25 # - 1 for interactive operation (no missing lists by default) |
|
26 # - 2 for fully verbose operation (including detailed progress) |
|
27 sub New($) |
|
28 { |
|
29 my $class = shift; |
|
30 my $self = {}; |
|
31 |
|
32 bless $self, $class; |
|
33 |
|
34 $self->{VERBOSITY}=shift; |
|
35 $self->{ERRORCODE}=0; |
|
36 $self->{PROGRESSING}=0; |
|
37 |
|
38 return $self; |
|
39 } |
|
40 |
|
41 # isBatch |
|
42 # |
|
43 # Tests verbosity setting |
|
44 sub isBatch() |
|
45 { |
|
46 my $self = shift; |
|
47 |
|
48 return ($self->getVerbosity() == 0); |
|
49 } |
|
50 |
|
51 # isVerbose |
|
52 # |
|
53 # Tests verbosity setting |
|
54 sub isVerbose() |
|
55 { |
|
56 my $self = shift; |
|
57 |
|
58 return ($self->getVerbosity() == 2); |
|
59 } |
|
60 |
|
61 # getVerbosity |
|
62 # |
|
63 # Verbosity getter |
|
64 sub getVerbosity() |
|
65 { |
|
66 my $self = shift; |
|
67 |
|
68 return $self->{VERBOSITY}; |
|
69 } |
|
70 |
|
71 # getErrorCode |
|
72 # |
|
73 # ErrorCode getter. For use in determining exit value when terminating script. |
|
74 sub getErrorCode() |
|
75 { |
|
76 my $self = shift; |
|
77 |
|
78 return $self->{ERRORCODE}; |
|
79 } |
|
80 |
|
81 # Warn |
|
82 # |
|
83 # Print warning |
|
84 sub Warn($) |
|
85 { |
|
86 my $self = shift; |
|
87 my ($warning) = @_; |
|
88 |
|
89 $self->_NewMessage(); |
|
90 |
|
91 print "$warning\n"; |
|
92 } |
|
93 |
|
94 # Error |
|
95 # |
|
96 # Print fatal error |
|
97 sub Error($) |
|
98 { |
|
99 my $self = shift; |
|
100 my ($error) = @_; |
|
101 |
|
102 $self->_NewMessage(); |
|
103 |
|
104 print "$error\n"; |
|
105 $self->{ERRORCODE}=1; |
|
106 } |
|
107 |
|
108 # Progress |
|
109 # |
|
110 # Display progress report |
|
111 sub Progress($) |
|
112 { |
|
113 my $self = shift; |
|
114 my ($report) = @_; |
|
115 |
|
116 if (!($self->isBatch())) |
|
117 { |
|
118 if ($self->isVerbose()) |
|
119 { |
|
120 if ($report ne "") |
|
121 { |
|
122 $self->_NewMessage(); |
|
123 |
|
124 print STDOUT "$report\n"; |
|
125 } |
|
126 } |
|
127 else |
|
128 { |
|
129 print STDOUT "."; |
|
130 |
|
131 $self->{PROGRESSING}=1; |
|
132 } |
|
133 } |
|
134 } |
|
135 |
|
136 # ListMissing |
|
137 # |
|
138 # Display a list of files expected but missing |
|
139 sub ListMissing(@) |
|
140 { |
|
141 my $self = shift; |
|
142 my @files = @_; |
|
143 |
|
144 if (($self->isVerbose()) || ($self->isBatch())) |
|
145 { |
|
146 $self->_NewMessage(); |
|
147 print STDOUT "The following files were not found:\n"; |
|
148 |
|
149 foreach my $file (@files) |
|
150 { |
|
151 print STDOUT "$file\n"; |
|
152 } |
|
153 } |
|
154 } |
|
155 |
|
156 # New message |
|
157 # |
|
158 # Prepare a new line if the previous output was progress dots |
|
159 sub _NewMessage() |
|
160 { |
|
161 my $self = shift; |
|
162 |
|
163 if ($self->{PROGRESSING}) |
|
164 { |
|
165 print STDOUT "\n"; |
|
166 $self->{PROGRESSING}=0; |
|
167 } |
|
168 } |
|
169 |
|
170 return 1; |