uttk 0.3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +36 -0
- data/COPYING +18 -0
- data/ChangeLog +7673 -0
- data/GUIDELINES +86 -0
- data/LGPL +504 -0
- data/NEWS +158 -0
- data/NORM +137 -0
- data/README +180 -0
- data/Rakefile +8 -0
- data/SPEC.gemspec +15 -0
- data/SPEC.yml +60 -0
- data/TODO +23 -0
- data/TODO.old +31 -0
- data/VERSION +5 -0
- data/bin/getopts/uttk.rb +390 -0
- data/bin/uttk +188 -0
- data/bin/uttk-unit +125 -0
- data/lib/uttk.rb +288 -0
- data/lib/uttk/dumpers/Basic.rb +23 -0
- data/lib/uttk/dumpers/BasicColor.rb +35 -0
- data/lib/uttk/dumpers/Dumper.rb +77 -0
- data/lib/uttk/dumpers/Html.rb +271 -0
- data/lib/uttk/dumpers/Path.rb +24 -0
- data/lib/uttk/dumpers/Xml.rb +88 -0
- data/lib/uttk/dumpers/Yaml.rb +138 -0
- data/lib/uttk/filters.rb +128 -0
- data/lib/uttk/filters/Buffer.rb +119 -0
- data/lib/uttk/filters/Compact.rb +75 -0
- data/lib/uttk/filters/Default.rb +27 -0
- data/lib/uttk/filters/DefaultColor.rb +27 -0
- data/lib/uttk/filters/Filter.rb +53 -0
- data/lib/uttk/filters/Id.rb +30 -0
- data/lib/uttk/filters/JustStatus.rb +25 -0
- data/lib/uttk/filters/KeepSkipBased.rb +38 -0
- data/lib/uttk/filters/NodeCut.rb +97 -0
- data/lib/uttk/filters/RPathFilter.rb +134 -0
- data/lib/uttk/filters/Saver.rb +53 -0
- data/lib/uttk/filters/TextFilter.rb +69 -0
- data/lib/uttk/generators/dumper_generator.rb +28 -0
- data/lib/uttk/generators/filter_generator.rb +28 -0
- data/lib/uttk/generators/generator.rb +86 -0
- data/lib/uttk/generators/generator_generator.rb +26 -0
- data/lib/uttk/generators/loader_generator.rb +28 -0
- data/lib/uttk/generators/path_filter_generator.rb +28 -0
- data/lib/uttk/generators/strategy_generator.rb +28 -0
- data/lib/uttk/generators/templates/dumper.rb +50 -0
- data/lib/uttk/generators/templates/filter.rb +50 -0
- data/lib/uttk/generators/templates/generator.rb +28 -0
- data/lib/uttk/generators/templates/loader.rb +26 -0
- data/lib/uttk/generators/templates/path_filter.rb +28 -0
- data/lib/uttk/generators/templates/strategy.rb +59 -0
- data/lib/uttk/generators/templates/strategy.yml +28 -0
- data/lib/uttk/generators/templates/unit_test.rb +46 -0
- data/lib/uttk/loaders/Loader.rb +180 -0
- data/lib/uttk/loaders/Ruby.rb +28 -0
- data/lib/uttk/loaders/Yaml.rb +98 -0
- data/lib/uttk/logger.rb +306 -0
- data/lib/uttk/logger/backend.rb +170 -0
- data/lib/uttk/logger/path.rb +202 -0
- data/lib/uttk/logger/section_node.rb +214 -0
- data/lib/uttk/logger/severity.rb +63 -0
- data/lib/uttk/logger/to_uttk_log.rb +127 -0
- data/lib/uttk/logger/verbosity.rb +61 -0
- data/lib/uttk/logger_factory.rb +55 -0
- data/lib/uttk/path_filters/ColorStatus.rb +57 -0
- data/lib/uttk/path_filters/PathFilter.rb +27 -0
- data/lib/uttk/path_filters/RemoveTypes.rb +25 -0
- data/lib/uttk/status.rb +146 -0
- data/lib/uttk/strategies/Abort.rb +24 -0
- data/lib/uttk/strategies/Assert.rb +44 -0
- data/lib/uttk/strategies/Authors.rb +45 -0
- data/lib/uttk/strategies/Block.rb +113 -0
- data/lib/uttk/strategies/Bootstrap.rb +55 -0
- data/lib/uttk/strategies/Checkout.rb +64 -0
- data/lib/uttk/strategies/Clean.rb +29 -0
- data/lib/uttk/strategies/Cmd.rb +60 -0
- data/lib/uttk/strategies/CmdBase.rb +130 -0
- data/lib/uttk/strategies/Collection.rb +158 -0
- data/lib/uttk/strategies/Compile.rb +59 -0
- data/lib/uttk/strategies/Composite.rb +201 -0
- data/lib/uttk/strategies/Composite/contents_eval.rb +40 -0
- data/lib/uttk/strategies/Configure.rb +66 -0
- data/lib/uttk/strategies/Error.rb +23 -0
- data/lib/uttk/strategies/Fail.rb +26 -0
- data/lib/uttk/strategies/IOBased.rb +159 -0
- data/lib/uttk/strategies/Import.rb +60 -0
- data/lib/uttk/strategies/Iterate.rb +139 -0
- data/lib/uttk/strategies/JUnit.rb +205 -0
- data/lib/uttk/strategies/KillAll.rb +62 -0
- data/lib/uttk/strategies/Make.rb +94 -0
- data/lib/uttk/strategies/Package.rb +129 -0
- data/lib/uttk/strategies/PackageCollection.rb +78 -0
- data/lib/uttk/strategies/Pass.rb +24 -0
- data/lib/uttk/strategies/Pool.rb +104 -0
- data/lib/uttk/strategies/ProbabilityThreshold.rb +46 -0
- data/lib/uttk/strategies/Proxy.rb +42 -0
- data/lib/uttk/strategies/RMatch.rb +92 -0
- data/lib/uttk/strategies/RUnit.rb +132 -0
- data/lib/uttk/strategies/SignalCmd.rb +85 -0
- data/lib/uttk/strategies/Sleep.rb +36 -0
- data/lib/uttk/strategies/SqlQuery.rb +120 -0
- data/lib/uttk/strategies/Strategy.rb +683 -0
- data/lib/uttk/strategies/Stub.rb +37 -0
- data/lib/uttk/strategies/SubCmd.rb +77 -0
- data/lib/uttk/strategies/Suite.rb +71 -0
- data/lib/uttk/strategies/Test.rb +89 -0
- data/lib/uttk/streams.rb +69 -0
- data/lib/uttk/streams/Diff.rb +60 -0
- data/lib/uttk/streams/HexaDiff.rb +35 -0
- data/lib/uttk/streams/Stream.rb +76 -0
- data/lib/uttk/weights.rb +17 -0
- data/lib/uttk/weights/WExpr.rb +68 -0
- data/lib/uttk/weights/WFloat.rb +23 -0
- data/lib/uttk/weights/WMin.rb +22 -0
- data/lib/uttk/weights/Weight.rb +105 -0
- data/lib/www/javascripts/uttk.js +185 -0
- data/misc/expandtab.rb +29 -0
- data/misc/header.rb +44 -0
- data/misc/renaming +57 -0
- data/misc/textile_compiler +194 -0
- data/misc/uttk-grep.sh +8 -0
- data/misc/uttk-line-count.rb +143 -0
- data/test/examples-suite.yml +8 -0
- data/test/examples/README +68 -0
- data/test/examples/basic.rb +10 -0
- data/test/examples/basic.yml +9 -0
- data/test/examples/cache/cache_and_fatal.yml +5 -0
- data/test/examples/cache/simple.yml +30 -0
- data/test/examples/sql/basic.yml +24 -0
- data/test/examples/students-suite.yml +9 -0
- data/test/examples/students/ball.yml +11 -0
- data/test/examples/students/glob_stud.yml +20 -0
- data/test/examples/students/mini-lib.yml +61 -0
- data/test/examples/students/pool_stud.yml +31 -0
- data/test/examples/students/stud.yml +21 -0
- data/test/fixtures/ball/20040804-exam_a1-zapngo-tessar_m.tar.gz +0 -0
- data/test/fixtures/ball/Makefile +24 -0
- data/test/fixtures/ball/bar_p-mini-lib.tar.bz2 +0 -0
- data/test/fixtures/ball/bar_p-mini-lib/Makefile +20 -0
- data/test/fixtures/ball/bar_p-mini-lib/my_strlen.c +13 -0
- data/test/fixtures/ball/foo_s-mini-lib.tar.bz2 +0 -0
- data/test/fixtures/ball/foo_s-mini-lib/Makefile +20 -0
- data/test/fixtures/ball/foo_s-mini-lib/configure +2 -0
- data/test/fixtures/ball/foo_s-mini-lib/my_strlen.c +10 -0
- data/test/fixtures/ball/hello.tar.bz2 +0 -0
- data/test/fixtures/ball/hello.tar.gz +0 -0
- data/test/fixtures/ball/hello/Makefile +14 -0
- data/test/fixtures/ball/hello/hello.c +7 -0
- data/test/fixtures/ball/jack-exit.tar.bz2 +0 -0
- data/test/fixtures/ball/jack-exit/Makefile +14 -0
- data/test/fixtures/ball/jack-exit/exit.c +16 -0
- data/test/fixtures/ball/joe-exit.tar.bz2 +0 -0
- data/test/fixtures/ball/joe-exit/Makefile +14 -0
- data/test/fixtures/ball/joe-exit/exit.c +8 -0
- data/test/fixtures/ball/joe_i-mini-lib.tar.bz2 +0 -0
- data/test/fixtures/ball/joe_i-mini-lib/Makefile +20 -0
- data/test/fixtures/ball/joe_i-mini-lib/configure +2 -0
- data/test/fixtures/ball/joe_i-mini-lib/my_strlen.c +10 -0
- data/test/fixtures/ball/john-exit.tar.bz2 +0 -0
- data/test/fixtures/ball/john-exit/Makefile +14 -0
- data/test/fixtures/ball/john-exit/exit.c +6 -0
- data/test/fixtures/ball/qux_j-mini-lib.tar.bz2 +0 -0
- data/test/fixtures/ball/qux_j-mini-lib/Makefile +20 -0
- data/test/fixtures/ball/qux_j-mini-lib/my_strlen.c +12 -0
- data/test/fixtures/binaries/segv +0 -0
- data/test/fixtures/binaries/segv.c +10 -0
- data/test/fixtures/binaries/segv.rb +2 -0
- data/test/fixtures/demo/command-tutorial/steps/1/check.yml +5 -0
- data/test/fixtures/demo/command-tutorial/steps/1/pluralizer.rb +10 -0
- data/test/fixtures/demo/command-tutorial/steps/2/bad_check.yml +7 -0
- data/test/fixtures/demo/command-tutorial/steps/2/check.yml +7 -0
- data/test/fixtures/demo/command-tutorial/steps/2/pluralizer.rb +10 -0
- data/test/fixtures/demo/command-tutorial/steps/3.1/check.yml +12 -0
- data/test/fixtures/demo/command-tutorial/steps/3/check.yml +14 -0
- data/test/fixtures/demo/command-tutorial/steps/4.1/bird.txt +1 -0
- data/test/fixtures/demo/command-tutorial/steps/4.1/check.yml +12 -0
- data/test/fixtures/demo/command-tutorial/steps/4/check.yml +12 -0
- data/test/fixtures/demo/command-tutorial/steps/4/pluralizer.rb +12 -0
- data/test/fixtures/demo/command-tutorial/steps/5.1/bird.txt +1 -0
- data/test/fixtures/demo/command-tutorial/steps/5.1/check.yml +17 -0
- data/test/fixtures/demo/command-tutorial/steps/5.1/pluralizer.rb +17 -0
- data/test/fixtures/demo/command-tutorial/steps/5/bird.txt +1 -0
- data/test/fixtures/demo/command-tutorial/steps/5/check.yml +16 -0
- data/test/fixtures/demo/command-tutorial/steps/5/pluralizer.rb +16 -0
- data/test/fixtures/demo/command-tutorial/steps/6.1/bird.txt +1 -0
- data/test/fixtures/demo/command-tutorial/steps/6.1/check.yml +22 -0
- data/test/fixtures/demo/command-tutorial/steps/6.1/pluralizer.rb +17 -0
- data/test/fixtures/demo/command-tutorial/steps/6/bird.txt +1 -0
- data/test/fixtures/demo/command-tutorial/steps/6/check.yml +21 -0
- data/test/fixtures/demo/command-tutorial/steps/6/pluralizer.rb +17 -0
- data/test/fixtures/demo/command-tutorial/steps/7/bird.txt +1 -0
- data/test/fixtures/demo/command-tutorial/steps/7/check.yml +22 -0
- data/test/fixtures/demo/command-tutorial/steps/7/pluralizer.rb +17 -0
- data/test/fixtures/demo/filter-tutorial/check.yml +20 -0
- data/test/fixtures/demo/filter-tutorial/filters/CutSkip100.rb +19 -0
- data/test/fixtures/demo/filter-tutorial/pluralizer.rb +17 -0
- data/test/fixtures/java/unit/MultiRight/Foo/Foo.java +11 -0
- data/test/fixtures/java/unit/MultiRight/Foo/FooTest.java +15 -0
- data/test/fixtures/java/unit/MultiRight/MultiRight.java +13 -0
- data/test/fixtures/java/unit/MultiRight/MultiRightTest.java +12 -0
- data/test/fixtures/java/unit/MultiRight/bar/Bar.java +11 -0
- data/test/fixtures/java/unit/MultiRight/bar/BarTest.java +21 -0
- data/test/fixtures/java/unit/MultiRight/build.sh +7 -0
- data/test/fixtures/java/unit/SimpleException/SimpleExceptionTest.java +11 -0
- data/test/fixtures/java/unit/SimpleException/build.sh +4 -0
- data/test/fixtures/java/unit/build.sh +9 -0
- data/test/fixtures/java/unit/multibar.yml +6 -0
- data/test/fixtures/java/unit/multifoo.yml +6 -0
- data/test/fixtures/java/unit/multiright.yml +8 -0
- data/test/fixtures/java/unit/simple_exception.yml +6 -0
- data/test/fixtures/mini-lib/Makefile +9 -0
- data/test/fixtures/mini-lib/strlen.c +15 -0
- data/test/fixtures/package/pkg_foo.tar.gz +0 -0
- data/test/fixtures/package/pkg_foo/Makefile +20 -0
- data/test/fixtures/package/pkg_foo/bootstrap +3 -0
- data/test/fixtures/package/pkg_foo/configure +3 -0
- data/test/fixtures/package/pkg_foo/foo.sh +2 -0
- data/test/fixtures/text/1.txt +4 -0
- data/test/fixtures/unit/bad.rb +26 -0
- data/test/fixtures/unit/error.rb +6 -0
- data/test/fixtures/unit/good.rb +26 -0
- data/test/functional-suite.yml +10 -0
- data/test/functional/author.yml +11 -0
- data/test/functional/base.yml +119 -0
- data/test/functional/base_pool.yml +13 -0
- data/test/functional/block.yml +13 -0
- data/test/functional/cat.yml +16 -0
- data/test/functional/cmd.yml +17 -0
- data/test/functional/diff.yml +27 -0
- data/test/functional/env_cmd.yml +53 -0
- data/test/functional/exit.yml +15 -0
- data/test/functional/fatal.yml +23 -0
- data/test/functional/glob.yml +11 -0
- data/test/functional/hexa-diff.yml +25 -0
- data/test/functional/import.yml +41 -0
- data/test/functional/iterate.yml +99 -0
- data/test/functional/killall.yml +31 -0
- data/test/functional/pkg.yml +14 -0
- data/test/functional/probability_threshold.yml +35 -0
- data/test/functional/r_unit.yml +26 -0
- data/test/functional/rmatch.yml +122 -0
- data/test/functional/signal_cmd.yml +22 -0
- data/test/functional/sub.yml +15 -0
- data/test/functional/test.yml +25 -0
- data/test/functional/timeout.yml +20 -0
- data/test/functional/wc.yml +26 -0
- data/test/functional/weight.yml +152 -0
- data/test/pkg-suite.yml +8 -0
- data/test/pkg/cmdline.yml +80 -0
- data/test/pool-suite.yml +8 -0
- data/test/pool/base.yml +12 -0
- data/test/pool/pool.yml +25 -0
- data/test/ruby-suite.rb +10 -0
- data/test/ruby-suite.yml +5 -0
- data/test/ruby/base.rb +119 -0
- data/test/ruby/iterate.rb +21 -0
- data/test/ruby/wc.rb +43 -0
- data/test/unit-suite.yml +10 -0
- data/test/unit/dumpers/path_test.rb +46 -0
- data/test/unit/dumpers/xml_test.rb +65 -0
- data/test/unit/dumpers/yaml_test.rb +65 -0
- data/test/unit/filters/buffer_test.rb +168 -0
- data/test/unit/filters/keep_skip_based_test.rb +46 -0
- data/test/unit/filters/node_cut_test.rb +72 -0
- data/test/unit/filters/rpath_filter_test.rb +191 -0
- data/test/unit/filters/text_filter_test.rb +46 -0
- data/test/unit/filters_test.rb +119 -0
- data/test/unit/logger/section_node_test.rb +120 -0
- data/test/unit/logger/severity_test.rb +37 -0
- data/test/unit/logger/to_uttk_log_test.rb +113 -0
- data/test/unit/logger/verbosity_test.rb +44 -0
- data/test/unit/logger_test.rb +203 -0
- data/test/unit/strategies/suite_test.rb +151 -0
- data/test/uttk-check.yml +8 -0
- data/test/uttk-distcheck.yml +18 -0
- metadata +399 -0
data/lib/uttk/logger.rb
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
|
2
|
+
# Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
|
|
3
|
+
# License:: LGPL
|
|
4
|
+
# $Id: /w/fey/uttk/trunk/lib/uttk/logger.rb 21879 2006-02-19T01:31:34.473073Z pouillar $
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
require 'observer'
|
|
8
|
+
|
|
9
|
+
require 'uttk/logger/severity'
|
|
10
|
+
require 'uttk/logger/to_uttk_log'
|
|
11
|
+
require 'uttk/logger/section_node'
|
|
12
|
+
require 'uttk/logger/path'
|
|
13
|
+
require 'uttk/logger/verbosity'
|
|
14
|
+
require 'uttk/logger/backend'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
module Uttk
|
|
18
|
+
|
|
19
|
+
class Logger
|
|
20
|
+
|
|
21
|
+
include Observable
|
|
22
|
+
|
|
23
|
+
OPTIONS = [ :ordered, :type ]
|
|
24
|
+
|
|
25
|
+
MESSAGES = [ :new_leaf, :close ]
|
|
26
|
+
|
|
27
|
+
class UnsupportedMessage < ArgumentError
|
|
28
|
+
end
|
|
29
|
+
class DuplicatedPath < Exception
|
|
30
|
+
def initialize ( backend_path, path )
|
|
31
|
+
@backend_path = backend_path
|
|
32
|
+
@path = path
|
|
33
|
+
end
|
|
34
|
+
def to_s
|
|
35
|
+
path, bpath = @path.to_s, @backend_path.to_s
|
|
36
|
+
path += ' vs ' + bpath if path != bpath
|
|
37
|
+
"The path notification flow contains two leaves at the same path (#{path})"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def initialize ( *observers )
|
|
42
|
+
@path = Logger::Path.new
|
|
43
|
+
observers.flatten.each { |obs| add_observer(obs) }
|
|
44
|
+
@sections = []
|
|
45
|
+
@section_tree = SectionNode.new('all')
|
|
46
|
+
@severity_level = Severity::DEBUG
|
|
47
|
+
@nb_log_msg = 0
|
|
48
|
+
@verbosity = Verbosity.new
|
|
49
|
+
@verbosity_level = 0
|
|
50
|
+
@closed = false
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def initialize_copy ( o )
|
|
54
|
+
super # FIXME share less information
|
|
55
|
+
@path = o.path
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def chpath ( path )
|
|
59
|
+
@path = path.dup
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
attr_reader :severity_level
|
|
63
|
+
|
|
64
|
+
def severity_level=(severity_level)
|
|
65
|
+
if severity_level.is_a?(String)
|
|
66
|
+
severity_level = Severity.const_get(severity_level.to_s.upcase)
|
|
67
|
+
end
|
|
68
|
+
if Severity.lower <= severity_level and severity_level <= Severity.higher
|
|
69
|
+
@severity_level = severity_level
|
|
70
|
+
else
|
|
71
|
+
raise(ArgumentError, "`#{severity_level}' - invalid severity level")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
attr_accessor :section_tree
|
|
76
|
+
|
|
77
|
+
def active_section(active, *section_names)
|
|
78
|
+
@sections = @section_tree.set_active_section(active, *section_names)
|
|
79
|
+
nil
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def active_section?(section_name)
|
|
83
|
+
@sections.include?(section_name)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
attr_reader :verbosity
|
|
87
|
+
|
|
88
|
+
def verbosity=(verbosity)
|
|
89
|
+
unless verbosity.is_a?(Verbosity)
|
|
90
|
+
raise(ArgumentError,
|
|
91
|
+
"`#{verbosity}' - must inherit from Verbosity")
|
|
92
|
+
end
|
|
93
|
+
@verbosity = verbosity
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
attr_reader :verbosity_level
|
|
97
|
+
|
|
98
|
+
def verbosity_level=(verbosity_level)
|
|
99
|
+
if verbosity_level < 0
|
|
100
|
+
raise(ArgumentError,
|
|
101
|
+
"`#{verbosity_level}' - " +
|
|
102
|
+
'verbosity level must be positive or null')
|
|
103
|
+
end
|
|
104
|
+
@verbosity_level = verbosity_level
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def log(severity_level=nil, *section_names, &block)
|
|
108
|
+
severity_level ||= Severity.higher
|
|
109
|
+
return true if severity_level < @severity_level
|
|
110
|
+
if section_names.empty?
|
|
111
|
+
format_log_message(severity_level, section_names, &block)
|
|
112
|
+
else
|
|
113
|
+
section_names.each do |s|
|
|
114
|
+
if @sections.include?(s)
|
|
115
|
+
format_log_message(severity_level, section_names, &block)
|
|
116
|
+
break
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def format_log_message(severity_level, section_names, &block)
|
|
123
|
+
message = block[]
|
|
124
|
+
return if message.nil?
|
|
125
|
+
name = Severity.label(severity_level)
|
|
126
|
+
name += "_#@nb_log_msg" unless @nb_log_msg.zero?
|
|
127
|
+
new_node(name) do
|
|
128
|
+
if @verbosity_level == 0
|
|
129
|
+
message.to_uttk_log(self)
|
|
130
|
+
else
|
|
131
|
+
for i in 1..@verbosity_level do
|
|
132
|
+
@verbosity.class.level_fields(i).each do |field|
|
|
133
|
+
self[field] = @verbosity.send(field,
|
|
134
|
+
severity_level,
|
|
135
|
+
section_names)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
self['message'] = message
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
@nb_log_msg += 1
|
|
142
|
+
end
|
|
143
|
+
protected :format_log_message
|
|
144
|
+
|
|
145
|
+
class Upper
|
|
146
|
+
def initialize ( &block )
|
|
147
|
+
@called = false
|
|
148
|
+
@block = block
|
|
149
|
+
end
|
|
150
|
+
def up
|
|
151
|
+
return if @called
|
|
152
|
+
@called = true
|
|
153
|
+
@block[]
|
|
154
|
+
end
|
|
155
|
+
alias_method :call, :up
|
|
156
|
+
alias_method :[], :up
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def new_node ( node, options=nil, &block )
|
|
160
|
+
unless options.nil?
|
|
161
|
+
options.each_key do |k|
|
|
162
|
+
unless OPTIONS.include? k
|
|
163
|
+
raise ArgumentError, "bad option: #{k}"
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
unless node.is_a? Symbol or node.is_a? Integer or node == ''
|
|
168
|
+
node = node.to_s.to_sym
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
if block
|
|
172
|
+
up_path = @path.dup
|
|
173
|
+
else
|
|
174
|
+
result = upper
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
begin
|
|
178
|
+
@path << Segment.new(node, options)
|
|
179
|
+
rescue Exception => ex
|
|
180
|
+
if block
|
|
181
|
+
secret_up up_path
|
|
182
|
+
else
|
|
183
|
+
result.up
|
|
184
|
+
end
|
|
185
|
+
raise ex
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
if block
|
|
189
|
+
begin
|
|
190
|
+
block[]
|
|
191
|
+
ensure
|
|
192
|
+
@path = up_path
|
|
193
|
+
end
|
|
194
|
+
else
|
|
195
|
+
result
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def upper
|
|
200
|
+
# The local variable up_path is very important !!!
|
|
201
|
+
up_path = @path.dup
|
|
202
|
+
Upper.new { @path = up_path }
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def new_leaf ( x )
|
|
206
|
+
notif :new_leaf, @path.dup, x
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def []= ( k, v )
|
|
210
|
+
v.to_uttk_log_with_key(k, self)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def << ( v )
|
|
214
|
+
v.to_uttk_log(self)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
class BadMethodFormat < ArgumentError
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def method_missing ( key, *a, &b )
|
|
221
|
+
str = key.to_s
|
|
222
|
+
if str =~ /^(.*)=$/
|
|
223
|
+
self[$1.to_sym] = a[0]
|
|
224
|
+
elsif b
|
|
225
|
+
begin
|
|
226
|
+
args = make_log_arguments(str)
|
|
227
|
+
args += a
|
|
228
|
+
self.log(*args, &b)
|
|
229
|
+
rescue BadMethodFormat
|
|
230
|
+
super
|
|
231
|
+
end
|
|
232
|
+
else
|
|
233
|
+
super
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def make_log_arguments(str)
|
|
238
|
+
if str =~ /^([A-Za-z0-9]+)(.*)$/
|
|
239
|
+
severity, tail = $1, $2
|
|
240
|
+
args = []
|
|
241
|
+
begin
|
|
242
|
+
args << Severity.const_get(severity.upcase)
|
|
243
|
+
rescue NameError
|
|
244
|
+
raise(NameError, "`#{severity}' - unknown severity level")
|
|
245
|
+
end
|
|
246
|
+
while tail =~ /^_([A-Za-z0-9]+)(.*)$/
|
|
247
|
+
args << $1
|
|
248
|
+
tail = $2
|
|
249
|
+
end
|
|
250
|
+
args
|
|
251
|
+
else
|
|
252
|
+
raise(BadMethodFormat, "`#{str}' - bad format")
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def path
|
|
257
|
+
@path.dup
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def path_size
|
|
261
|
+
@path.size
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def to_s
|
|
265
|
+
"#<#{self.class} path=#{path}>"
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
alias :inspect :to_s
|
|
269
|
+
|
|
270
|
+
# r = Logger.new
|
|
271
|
+
# r.new_node(:root)
|
|
272
|
+
# r.update(:new_node, [:another_path], :foo) # it's now correct
|
|
273
|
+
def update ( msg, *args )
|
|
274
|
+
notif(msg, *args) if MESSAGES.include? msg
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def notif ( *args )
|
|
278
|
+
changed
|
|
279
|
+
notify_observers(*args)
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
private :notif, :notify_observers, :changed
|
|
283
|
+
|
|
284
|
+
def close
|
|
285
|
+
return if @closed
|
|
286
|
+
@path = Logger::Path.new unless @path.empty?
|
|
287
|
+
notif :close
|
|
288
|
+
@closed = true
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def self.make_notif ( n )
|
|
292
|
+
if n.size == 3
|
|
293
|
+
n
|
|
294
|
+
else
|
|
295
|
+
[:new_leaf, n[0].to_logger_path, n[1]]
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
def self.make_notifs ( ns )
|
|
300
|
+
ns.map { |n| make_notif(n) }
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
end # class Logger
|
|
304
|
+
|
|
305
|
+
end # module Uttk
|
|
306
|
+
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved.
|
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
|
3
|
+
# License:: LGPL
|
|
4
|
+
# Revision:: $Id: /w/fey/uttk/trunk/lib/uttk/logger/backend.rb 21975 2006-02-19T22:24:11.182512Z pouillar $
|
|
5
|
+
|
|
6
|
+
module Uttk
|
|
7
|
+
|
|
8
|
+
class Logger
|
|
9
|
+
|
|
10
|
+
# A Logger::Backend is a logger observer.
|
|
11
|
+
# It's react to some methods, which can be compared to shell commands:
|
|
12
|
+
#
|
|
13
|
+
# At any time `path' is "equivalent to" the shell command `pwd'.
|
|
14
|
+
# The path argument is a Logger::Path instance.
|
|
15
|
+
#
|
|
16
|
+
# - new_node ( path, node ):
|
|
17
|
+
# - The method new_node is called with the path and a node as arguments.
|
|
18
|
+
# - node is a Logger::Segment it contains 2 fields (segment and options)
|
|
19
|
+
# - new_node is equivalent to `mkdir node && cd node' in shell.
|
|
20
|
+
#
|
|
21
|
+
# - new_leaf ( path, leaf ):
|
|
22
|
+
# - equivalent to `touch leaf'
|
|
23
|
+
#
|
|
24
|
+
# - up ( path ):
|
|
25
|
+
# - equivalent to `cd ..` (path is given but it's allways the parent path)
|
|
26
|
+
# - Change the current path to the parent.
|
|
27
|
+
#
|
|
28
|
+
# - close ():
|
|
29
|
+
# - Close this backend.
|
|
30
|
+
#
|
|
31
|
+
#
|
|
32
|
+
#
|
|
33
|
+
#
|
|
34
|
+
#
|
|
35
|
+
#
|
|
36
|
+
# Thinking about the notification model
|
|
37
|
+
# - either we send complete paths:
|
|
38
|
+
# root
|
|
39
|
+
# root/sub1
|
|
40
|
+
# root/sub1/status
|
|
41
|
+
# root/sub1/status/PASS
|
|
42
|
+
# root/sub2
|
|
43
|
+
# root/sub2/contents[ordered]
|
|
44
|
+
# root/sub2/contents[ordered]/t1
|
|
45
|
+
# root/sub2/contents[ordered]/t1/status
|
|
46
|
+
# root/sub2/contents[ordered]/t1/status/PASS
|
|
47
|
+
# root/sub2/contents[ordered]/t2
|
|
48
|
+
# root/sub2/contents[ordered]/t2/status
|
|
49
|
+
# root/sub2/contents[ordered]/t2/status/FAIL
|
|
50
|
+
# root/sub2/status/FAIL(50%)
|
|
51
|
+
# root/status/FAIL(75%)
|
|
52
|
+
# avantages
|
|
53
|
+
# - no more needs to send new_leaf, new_node, and up
|
|
54
|
+
# - it's more robust against transformations (up quantity...)
|
|
55
|
+
#
|
|
56
|
+
# - but we can compress this flow, we send only path of leaves:
|
|
57
|
+
#
|
|
58
|
+
# root/sub1/status/PASS
|
|
59
|
+
# root/sub2/contents[ordered]/t1/status/PASS
|
|
60
|
+
# root/sub2/contents[ordered]/t2/status/FAIL
|
|
61
|
+
# root/sub2/status/FAIL(50%)
|
|
62
|
+
# root/status/FAIL(75%)
|
|
63
|
+
#
|
|
64
|
+
# - or even better to avoid the leaf encoding (by ourself),
|
|
65
|
+
# we send the path of the leaf and the leaf:
|
|
66
|
+
# ---
|
|
67
|
+
# - !lpath root/sub1/status
|
|
68
|
+
# - PASS
|
|
69
|
+
# ---
|
|
70
|
+
# - !lpath root/sub2/contents[ordered]/t1/status
|
|
71
|
+
# - PASS
|
|
72
|
+
# ---
|
|
73
|
+
# - !lpath root/sub2/contents[ordered]/t2/status
|
|
74
|
+
# - FAIL
|
|
75
|
+
# ---
|
|
76
|
+
# - !lpath root/sub2/status
|
|
77
|
+
# - FAIL(50%)
|
|
78
|
+
# ---
|
|
79
|
+
# - !lpath root/status
|
|
80
|
+
# - FAIL(75%)
|
|
81
|
+
#
|
|
82
|
+
# The last one is kept in this implementation.
|
|
83
|
+
class Backend
|
|
84
|
+
include Abstract
|
|
85
|
+
|
|
86
|
+
def initialize
|
|
87
|
+
@backend_path = Logger::Path.new
|
|
88
|
+
@open = true
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def new_node ( path, node )
|
|
93
|
+
end
|
|
94
|
+
protected :new_node
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def new_leaf ( path, leaf )
|
|
98
|
+
end
|
|
99
|
+
protected :new_leaf
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def up ( path )
|
|
103
|
+
end
|
|
104
|
+
protected :up
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def close
|
|
108
|
+
end
|
|
109
|
+
protected :close
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def complete_up ( size )
|
|
113
|
+
diff = @backend_path.size - size
|
|
114
|
+
diff.times do
|
|
115
|
+
@backend_path.pop
|
|
116
|
+
up(@backend_path.dup)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
private :complete_up
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def spawn_new_node ( node )
|
|
124
|
+
new_node(@backend_path.dup, node)
|
|
125
|
+
@backend_path << node
|
|
126
|
+
end
|
|
127
|
+
private :spawn_new_node
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def update ( msg, path=nil, *args )
|
|
132
|
+
if msg == :close
|
|
133
|
+
if @open
|
|
134
|
+
@open = false
|
|
135
|
+
return close
|
|
136
|
+
else
|
|
137
|
+
return
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
raise UnsupportedMessage, msg if msg != :new_leaf
|
|
141
|
+
path = path.to_logger_path unless path.is_a? Logger::Path
|
|
142
|
+
identical = true
|
|
143
|
+
last_ordered_seg = nil
|
|
144
|
+
path.each_with_index do |x, i|
|
|
145
|
+
y = @backend_path[i]
|
|
146
|
+
last_ordered_seg = i if x.options[:ordered]
|
|
147
|
+
next if x == y
|
|
148
|
+
identical = false
|
|
149
|
+
complete_up i unless y.nil?
|
|
150
|
+
spawn_new_node x
|
|
151
|
+
end
|
|
152
|
+
if msg == :new_leaf and identical and not path.empty? \
|
|
153
|
+
and not last_ordered_seg.nil? # FIXME
|
|
154
|
+
# try to make this assertion more precise to not break some valid tests (sub.yml)
|
|
155
|
+
# raise DuplicatedPath.new(@backend_path, path) if last_ordered_seg.nil?
|
|
156
|
+
last_ordered_seg += 1
|
|
157
|
+
complete_up last_ordered_seg
|
|
158
|
+
path.each_with_index do |x, i|
|
|
159
|
+
next if i < last_ordered_seg
|
|
160
|
+
spawn_new_node x
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
new_leaf(path.dup, *args)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
end # class Backend
|
|
167
|
+
|
|
168
|
+
end # class Logger
|
|
169
|
+
|
|
170
|
+
end # module Uttk
|