laborantin 0.0.8 → 0.0.9

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/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
 
4
4
  spec = Gem::Specification.new do |s|
5
5
  s.name = 'laborantin'
6
- s.version = '0.0.8'
6
+ s.version = '0.0.9'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.summary = "A measurement batch facilitator"
9
9
 
@@ -3,11 +3,8 @@
3
3
  class <%= e.camelize %> < Laborantin::Environment
4
4
 
5
5
  describe "Place your description here"
6
-
7
- verify :good_platform?
8
-
9
- def good_platform?
10
- RUBY_PLATFORM =~ /linux/
11
- end
6
+ #verify :instance_meth1, ...
7
+ #setup :instance_meth2, ...
8
+ #teardown :instance_meth3, ...
12
9
 
13
10
  end
@@ -2,4 +2,12 @@
2
2
 
3
3
  class <%= s.camelize %> < Laborantin::Scenario
4
4
  describe "put your decription here"
5
+ # parameter(:param_name) do
6
+ # values 1, 2, 3, 4, ...
7
+ # describe "put your parameter description here"
8
+ # end
9
+ #
10
+ # setup :instance_meth1, ...
11
+ # teardown :instance_meth2, ...
12
+ # produces :instance_meth3, ...
5
13
  end
data/bin/labor CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
- #require 'rubygems'
4
+ require 'rubygems'
5
5
  require 'laborantin'
6
6
  #require '../lib/laborantin'
7
7
  require 'fileutils'
@@ -162,34 +162,9 @@ Command.new('scan', "scan a laborantin's dir for results") do |c|
162
162
  require f if File.extname(f) == '.rb'
163
163
  end
164
164
 
165
- envs = []
166
- scs = []
167
-
168
- Dir.entries('results').each do |f|
169
- envklass = Laborantin::Environment.all.find{|e| e.name.duck_case == f} #TODO: pass that in the class
170
- if envklass
171
- Dir.entries(envklass.envdir).each do |e|
172
- if e =~ /\d+-\w+-\d+_\d+-\d+-\d+/
173
- env = envklass.new #XXX: don't prepare! it hence don't overwrite logs
174
- envs << env
175
- env.rundir = File.join(envklass.envdir, e)
176
- Dir.entries(env.rundir).each do |s|
177
- scklass = Laborantin::Scenario.all.find{|t| t.name.duck_case == s}
178
- if scklass
179
- Dir.entries(scklass.scenardir(env)).each do |r|
180
- if r =~ /\d+-\w+-\d+_\d+-\d+-\d+/
181
- scenar = scklass.new(env)
182
- scs << scenar
183
- scenar.rundir = File.join(scklass.scenardir(env), r)
184
- YAML.load_file(File.join(scenar.rundir, 'config.yaml'))
185
- end
186
- end
187
- end
188
- end
189
- end
190
- end
191
- end
192
- end #Dir
165
+ envs = Laborantin::Environment.scan_resdir('results')
166
+
167
+ scs = envs.map{|env| env.populate }.flatten
193
168
 
194
169
  puts "Laborantin' summary:"
195
170
  Laborantin::Environment.all.each do |envklass|
@@ -240,7 +215,7 @@ Command.new('run', 'actually perform measurements') do |c|
240
215
 
241
216
  envs.each do |eklass|
242
217
  env = eklass.new
243
- unless eklass.verifications.find{|v| not env.send(v)} #TODO: pass into class, rescue errors
218
+ if env.valid?
244
219
  env.prepare!
245
220
  env.log "Running matching scenarii", :info #TODO: pass the logging+running in the env
246
221
  scii.each do |sklass|
@@ -253,7 +228,6 @@ Command.new('run', 'actually perform measurements') do |c|
253
228
  sc.analyze!
254
229
  end
255
230
  end
256
- env.analyze!
257
231
  env.teardown!
258
232
  env.log "Scenarii performed", :info
259
233
  end
@@ -28,7 +28,7 @@ require File.join(File.dirname(__FILE__), 'laborantin', 'core', 'environment')
28
28
  require File.join(File.dirname(__FILE__), 'laborantin', 'core', 'monkey_patches')
29
29
 
30
30
  module Laborantin
31
- VERSION = '0.0.8'
31
+ VERSION = '0.0.9'
32
32
  AUTHORS = ['Lucas Di Cioccio']
33
33
  WEBSITE = 'http://dicioccio.fr'
34
34
  LICENSE = 'GNU GPL version 3'
@@ -29,6 +29,24 @@ module Laborantin
29
29
  class Environment
30
30
  @@all = []
31
31
  @@rootdir = '.'
32
+
33
+ def self.scan_resdir(dir)
34
+ ret = []
35
+ Dir.entries(dir).each do |f|
36
+ envklass = Laborantin::Environment.all.find{|e| e.name.duck_case == f}
37
+ if envklass
38
+ Dir.entries(envklass.envdir).each do |e|
39
+ if e =~ /\d+-\w+-\d+_\d+-\d+-\d+/
40
+ env = envklass.new #XXX don't prepare! it hence don't overwrite logs
41
+ env.rundir = File.join(envklass.envdir, e)
42
+ ret << env
43
+ end
44
+ end
45
+ end
46
+ end
47
+ ret
48
+ end
49
+
32
50
  class << self
33
51
  attr_accessor :verifications, :description, :envdir, :hooks
34
52
 
@@ -90,6 +108,10 @@ module Laborantin
90
108
  @loggers = []
91
109
  end
92
110
 
111
+ def valid?
112
+ self.class.verifications.find{|v| not send(v)}.nil?
113
+ end
114
+
93
115
  def prepare!
94
116
  FileUtils.mkdir_p(rundir) #TODO: ensure unicity
95
117
  @loggers << Logger.new(File.join(rundir, 'environment.log'))
@@ -103,14 +125,14 @@ module Laborantin
103
125
  call_hooks :teardown
104
126
  end
105
127
 
106
- def analyze!
107
- #TODO
108
- end
109
-
110
128
  def log(str, lvl=:debug)
111
129
  @loggers.each{|l| l.send(lvl, str)}
112
130
  end
113
131
 
132
+ def populate
133
+ Laborantin::Scenario.scan_env(self)
134
+ end
135
+
114
136
  private
115
137
 
116
138
  def call_hooks(name)
@@ -30,57 +30,76 @@ require 'yaml'
30
30
  module Laborantin
31
31
  class Scenario
32
32
  @@all = []
33
+
34
+ def self.scan_env(env)
35
+ scs = []
36
+ Dir.entries(env.rundir).each do |s|
37
+ scklass = Laborantin::Scenario.all.find{|t| t.name.duck_case == s}
38
+ if scklass
39
+ Dir.entries(scklass.scenardir(env)).each do |r|
40
+ if r =~ /\d+-\w+-\d+_\d+-\d+-\d+/
41
+ scenar = scklass.new(env)
42
+ scs << scenar
43
+ scenar.rundir = File.join(scklass.scenardir(env), r)
44
+ YAML.load_file(File.join(scenar.rundir, 'config.yaml'))
45
+ end
46
+ end
47
+ end
48
+ end
49
+ scs
50
+ end
51
+
33
52
  class << self
34
53
  attr_accessor :description, :parameters, :products, :hooks
35
54
 
36
55
  def inherited(klass)
37
- klass.parameters = ParameterHash.new
38
- klass.description = ''
39
- klass.products = []
40
- klass.hooks = {:setup => [], :teardown => []}
41
- @@all << klass
56
+ klass.parameters = ParameterHash.new
57
+ klass.description = ''
58
+ klass.products = []
59
+ klass.hooks = {:setup => [], :teardown => []}
60
+ @@all << klass
42
61
  end
43
62
 
44
63
  def describe(str)
45
- self.description = str
64
+ self.description = str
46
65
  end
47
66
 
48
67
  def setup(*args)
49
- self.hooks[:setup] = [*args].flatten
68
+ self.hooks[:setup] = [*args].flatten
50
69
  end
51
70
 
52
71
  def teardown(*args)
53
- self.hooks[:teardown] = [*args].flatten
72
+ self.hooks[:teardown] = [*args].flatten
54
73
  end
55
74
 
56
75
 
57
76
  def parameter(name, &blk)
58
- raise ArgumentError.new("Parameter #{name} already exists") if self.parameters[name]
59
- param = ParameterRange.new(name)
60
- param.instance_eval &blk
61
- self.parameters[name] = param
77
+ raise ArgumentError.new("Parameter #{name} already exists") if self.parameters[name]
78
+ param = ParameterRange.new(name)
79
+ param.instance_eval &blk
80
+ self.parameters[name] = param
62
81
  end
63
82
 
64
83
  def produces(*args)
65
- self.products = [*args].flatten
84
+ self.products = [*args].flatten
66
85
  end
67
86
 
68
87
  def to_s
69
- "#{self.name}:\n\t#{self.description}\n#{self.parameters}"
88
+ "#{self.name}:\n\t#{self.description}\n#{self.parameters}"
70
89
  end
71
90
 
72
91
  def all
73
- @@all
92
+ @@all
74
93
  end
75
94
 
76
95
  def scenardir(env=nil)
77
- envdir = env.rundir || '.'
78
- File.join(envdir, self.name.duck_case)
96
+ envdir = env.rundir || '.'
97
+ File.join(envdir, self.name.duck_case)
79
98
  end
80
99
  end # class <<
81
100
 
82
101
  attr_accessor :params, :environment, :date, :rundir
83
-
102
+
84
103
  def initialize(env, params={})
85
104
  @environment = env
86
105
  @params = params
@@ -101,9 +120,9 @@ module Laborantin
101
120
  call_hooks :setup
102
121
  log "Starting measurement"
103
122
  raw_result_file('w') do |f|
104
- run do |l|
105
- f.puts l
106
- end
123
+ run do |l|
124
+ f.puts l
125
+ end
107
126
  end
108
127
  log "Measurement finished"
109
128
  call_hooks :teardown
@@ -111,13 +130,13 @@ module Laborantin
111
130
 
112
131
  def analyze!
113
132
  self.class.products.each do |name|
114
- log "Producing #{name}"
115
- product_file(name.to_s, 'w') do |f|
116
- send name do |l|
117
- f.puts l
118
- end
119
- end
120
- log "Product #{name} done"
133
+ log "Producing #{name}"
134
+ product_file(name.to_s, 'w') do |f|
135
+ send name do |l|
136
+ f.puts l
137
+ end
138
+ end
139
+ log "Product #{name} done"
121
140
  end
122
141
  end
123
142
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: laborantin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Di Cioccio Lucas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-24 00:00:00 +02:00
12
+ date: 2009-07-27 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15