1
# $Id: text.rb,v 1.39 2004/01/27 15:20:01 sdalu Exp $
4
# CONTACT : zonecheck@nic.fr
5
# AUTHOR : Stephane D'Alu <sdalu@nic.fr>
7
# CREATED : 2002/08/02 13:58:17
8
# REVISION : $Revision: 1.39 $
9
# DATE : $Date: 2004/01/27 15:20:01 $
11
# CONTRIBUTORS: (see also CREDITS file)
14
# LICENSE : GPL v2 (or MIT/X11-like after agreement)
15
# COPYRIGHT : AFNIC (c) 2003
17
# This file is part of ZoneCheck.
19
# ZoneCheck is free software; you can redistribute it and/or modify it
20
# under the terms of the GNU General Public License as published by
21
# the Free Software Foundation; either version 2 of the License, or
22
# (at your option) any later version.
24
# ZoneCheck is distributed in the hope that it will be useful, but
25
# WITHOUT ANY WARRANTY; without even the implied warranty of
26
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
# General Public License for more details.
29
# You should have received a copy of the GNU General Public License
30
# along with ZoneCheck; if not, write to the Free Software Foundation,
31
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47
## Rendering of XML chunks
56
def apply(xmlnode, var={})
58
when MyXML::Node::Element
60
when MsgCat::NAME, MsgCat::FAILURE, MsgCat::SUCCESS
62
when MsgCat::EXPLANATION # not displayed in tagonly
63
text = xmlnode.to_a('src').collect { |xmlsrc|
64
type = $mc.get("tag_#{xmlsrc['type']}")
65
title = do_text(xmlsrc.child('title'))
67
type + ': ' + title + "\n" +
68
xmlsrc.to_a('para').collect { |xmlpara|
69
fmt_para(do_text(xmlpara, var)) }.join
71
::Text::Formater.lbox(text, [ ' |', ' `', '-', ' ' ])
72
when MsgCat::DETAILS # not displayed in tagonly
73
text = xmlnode.to_a('para').collect { |xmlpara|
74
fmt_para(do_text(xmlpara, var)) }.join("\n")
75
::Text::Formater.lbox(text, [ ' :', ' `', '.', ' ' ])
79
when MyXML::Node::Text
86
#-- [private] -----------------------------------------------
88
def fmt_para(text, width=MaxLineLength-7, tag=' ')
89
::Text::Formater.paragraph(text, width, tag)
92
def do_text(xmlnode, var={})
94
when MyXML::Node::Element
96
when 'zcvar', 'zcconst'
97
display = xmlnode['display']
98
data = case xmlnode.name
100
when 'zcconst' then @const
102
name = xmlnode['name']
103
value = data.fetch(name)
106
Publisher.to_bind_duration(value.to_i)
111
xmlnode.to_a(:child).collect { |xmlchild|
112
do_text(xmlchild, var) }.join
114
when MyXML::Node::Text
125
## Display progression information about the tests being performed.
129
## Progession bar implementation
134
def initialize(output, precision)
136
@precision = precision
139
@l10n_unit = $mc.get('pgr_speed_unit')
144
@starttime = @lasttime = Time.now
149
@output.write $console.ctl['vi']
152
@updater = Thread::new {
159
@totaltime = if @lasttime == @starttime
161
else nowtime - @starttime
165
if @processed != last_processed
167
last_processed = @processed
172
@output.write $console.ctl['ce']
180
@mutex.synchronize { @processed += size }
184
@mutex.synchronize { @updater.kill }
185
@output.write "\r" + $console.ctl['ce']
190
@output.write $console.ctl['ve']
195
speed = if @totaltime == 0.0
197
else @processed / @totaltime
199
speed_s = if speed < 0.0
200
then "--.--%s" % [ @l10n_unit ]
201
else "%7.2f%s" % [ speed, @l10n_unit ]
205
pct = 100 * @processed / @length
208
else ((@length-@processed) / speed).to_i
210
pct_s = "%2d%%" % pct
211
eta_s = "ETA " + sec_to_timestr(eta)
212
bar_s = '=' * (BarSize * pct / 100) + '>'
214
"%-4s[%-#{BarSize}.#{BarSize}s] %-11s %10s %12s" % [
215
pct_s, bar_s, @processed, speed_s, eta_s ]
217
ind = @tick % (BarSize * 2 - 6)
218
pos = if ind < BarSize - 2
220
else BarSize - (ind - BarSize + 5)
222
bar_s = " " * BarSize
223
bar_s[pos-1,3] = '<=>'
225
" [%s] %-11s %10s" % [ bar_s, @processed, speed_s ]
230
def sec_to_timestr(sec)
231
return "--:--" if sec < 0
233
hrs = sec / 3600; sec %= 3600;
234
min = sec / 60; sec %= 60;
237
then sprintf "%2d:%02d:%02d", hrs, min, sec
238
else sprintf "%2d:%02d", min, sec
245
def initialize(publisher)
246
@publisher = publisher
247
@o = publisher.output
248
@counter = if @publisher.rflag.counter && @o.tty?
249
then PBar::new(@o, 1)
252
@l10n_testing = $mc.get('word:testing').capitalize
257
@counter.start(count) if @counter
260
# Finished on success
262
@counter.done if @counter
265
# Finished on failure
267
@counter.done if @counter
270
# Finish (finalize) output
272
@counter.finish if @counter
276
def process(checkname, ns, ip)
279
@counter.processed(1)
283
if @publisher.rflag.testdesc
284
xtra = if ip then " (IP=#{ip})"
285
elsif ns then " (NS=#{ns})"
288
if @publisher.rflag.tagonly
289
@o.puts "Testing: #{checkname}#{xtra}"
291
desc = @publisher.xmltrans.apply($mc.get(checkname,
292
MsgCat::CHECK, MsgCat::NAME))
293
@o.puts "#{@l10n_testing}: #{desc}#{xtra}"
299
#------------------------------------------------------------
301
def initialize(rflag, option, ostream=$stdout)
302
super(rflag, option, ostream)
303
@progress = Progress::new(self)
304
@xmltrans = XMLTransform::new
308
#------------------------------------------------------------
310
def testdesc(testname, subtype)
311
l10n = @xmltrans.apply($mc.get(testname, MsgCat::CHECK, subtype))
313
when MsgCat::NAME, MsgCat::FAILURE, MsgCat::SUCCESS
316
@o.puts testname + ':'
322
@o.print ::Text::Formater.paragraph(text, MaxLineLength,
323
$mc.get('word:error').upcase+': ')
328
return unless @rflag.intro
330
l10n_zone = $mc.get('ns_zone').upcase
331
l10n_ns = $mc.get('ns_ns' ).upcase
332
sz = [ l10n_zone.length, l10n_ns.length+3 ].max
334
@o.printf "%-*s : %s\n", sz, l10n_zone, domain.name
335
domain.ns.each_index { |i|
337
@o.printf "%-*s : %s [%s]\n",
338
sz, i == 0 ? "#{l10n_ns} <=" : "#{l10n_ns} ",
339
n[0].to_s, n[1].join(', ')
347
def diag_section(title)
348
@o.print ::Text::Formater.title(title, MaxLineLength)
351
def diagnostic1(domainname,
352
i_count, i_unexp, w_count, w_unexp, f_count, f_unexp,
355
i_tag, w_tag, f_tag =
356
severity_description(i_unexp, w_unexp, f_unexp)
358
summary = "%1s%03d %1s%03d %1s%03d" % [
363
@o.printf "%-*s %s\n",
364
MaxLineLength - 4 - summary.length, domainname, summary
368
@o.puts " #{res.testname}"
369
@o.puts " #{severity}: #{res.source || 'generic'}"
371
status = Config.severity2tag(severity)
372
l10n_status = $mc.get("word:#{status}").capitalize
373
source = res.source || $mc.get('word:generic')
374
msg = status_message(res.testname, res.desc, severity)
376
@o.puts " #{l10n_status}: #{source}"
383
def diagnostic(severity, testname, desc, lst)
385
if desc.check && @rflag.testname && !@rflag.tagonly
386
l10n_name = @xmltrans.apply($mc.get(testname,
387
MsgCat::CHECK, MsgCat::NAME))
388
@o.puts "[> #{l10n_name}"
392
status_tag = Config.severity2tag(severity)
395
status_shorttag = severity || Config::Ok
396
status = desc.error ? "[Unexpected] #{testname}" : testname
398
status_shorttag = $mc.get("word:#{status_tag}_id")
399
status = status_message(testname, desc, severity)
401
@o.puts "#{status_shorttag}> #{status}"
403
# Explanation & Details
404
# => only in case of failure (ie: not for Ok or Error)
405
# not when in 'tag only' mode
406
if desc.check && !severity.nil? &&
407
desc.error.nil? && !@rflag.tagonly
410
explanation = $mc.get(testname,
411
MsgCat::CHECK, MsgCat::EXPLANATION)
412
@o.print @xmltrans.apply(explanation) if explanation
416
if @rflag.details && desc.details
417
details = $mc.get(testname, MsgCat::CHECK, MsgCat::DETAILS)
418
@o.print @xmltrans.apply(details, desc.details) if details
424
elt ||= (@rflag.tagonly ? 'generic' : $mc.get('word:generic'))
425
@o.print ::Text::Formater.item(elt)
433
def status(domainname, i_count, w_count, f_count)
434
@o.puts "==> " + super(domainname, i_count, w_count, f_count)