laborantin 0.0.6 → 0.0.7

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.6'
6
+ s.version = '0.0.7'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.summary = "A measurement batch facilitator"
9
9
 
data/TODO CHANGED
@@ -1,11 +1,8 @@
1
1
  replay / pause / restart
2
2
 
3
- exploit raw results, wrt to values
4
-
5
3
  => interaction with rubydrill?
6
4
  => or direct stats
7
5
 
8
6
  export results via ftp
9
7
 
10
- app to parse through results
11
-
8
+ creation of a script that doesn't depends on laborantin for export?
data/bin/labor CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
- #require 'rubygems'
5
- require 'laborantin'
6
- #require '../lib/laborantin'
4
+ require 'rubygems'
5
+ #require 'laborantin'
6
+ require '../lib/laborantin'
7
7
  require 'fileutils'
8
8
  require 'find'
9
9
  require 'erb'
10
+ require 'yaml'
11
+ require 'net/ftp'
10
12
 
11
13
  class Command
12
14
  attr_accessor :name, :description, :parser, :block, :options, :args
@@ -57,6 +59,8 @@ class Command
57
59
  end
58
60
  end
59
61
 
62
+ # Create
63
+
60
64
  Command.new('create', 'prepares a dir for laborantin measurements') do |c|
61
65
  c.options[:scenarii] = []
62
66
  c.options[:environments] = []
@@ -73,10 +77,10 @@ Command.new('create', 'prepares a dir for laborantin measurements') do |c|
73
77
  p dir #not for debug
74
78
  unless c.options[:force]
75
79
  begin
76
- FileUtils.mkdir dir
80
+ FileUtils.mkdir dir
77
81
  rescue Errno::EEXIST => err
78
- puts "Directory already exists, use -f/--force to overwrite (will overwrite all generated files, use at your own risk)."
79
- exit
82
+ puts "Directory already exists, use -f/--force to overwrite (will overwrite all generated files, use at your own risk)."
83
+ exit
80
84
  end
81
85
  end
82
86
  %w{environments scenarii results config scripts}.each do |w|
@@ -88,47 +92,49 @@ Command.new('create', 'prepares a dir for laborantin measurements') do |c|
88
92
  res_path = File.join(dir, w)
89
93
  p res_path #not for debug
90
94
  File.open(res_path, 'w') do |f|
91
- tpl = ''
92
- tpl_path = (File.join(File.dirname(__FILE__), 'files', "#{w}.erb"))
93
- File.open(tpl_path) do |tf|
94
- tpl = tf.read
95
- end
96
- erb = ERB.new tpl
97
- erb.filename = res_path
98
- f.puts erb.result(binding)
95
+ tpl = ''
96
+ tpl_path = (File.join(File.dirname(__FILE__), 'files', "#{w}.erb"))
97
+ File.open(tpl_path) do |tf|
98
+ tpl = tf.read
99
+ end
100
+ erb = ERB.new tpl
101
+ erb.filename = res_path
102
+ f.puts erb.result(binding)
99
103
  end
100
104
  end
101
105
  @options[:scenarii].each do |s|
102
106
  res_path = File.join(dir, 'scenarii', "#{s}.rb")
103
107
  p res_path #not for debug
104
108
  File.open(res_path, 'w') do |f|
105
- tpl = ''
106
- tpl_path = (File.join(File.dirname(__FILE__), 'files', 'scenarii', 'scenario.rb.erb'))
107
- File.open(tpl_path) do |tf|
108
- tpl = tf.read
109
- end
110
- erb = ERB.new tpl
111
- erb.filename = res_path
112
- f.puts erb.result(binding)
109
+ tpl = ''
110
+ tpl_path = (File.join(File.dirname(__FILE__), 'files', 'scenarii', 'scenario.rb.erb'))
111
+ File.open(tpl_path) do |tf|
112
+ tpl = tf.read
113
+ end
114
+ erb = ERB.new tpl
115
+ erb.filename = res_path
116
+ f.puts erb.result(binding)
113
117
  end
114
118
  end
115
119
  @options[:environments].each do |e|
116
120
  res_path = File.join(dir, 'environments', "#{e}.rb")
117
121
  p res_path #not for debug
118
122
  File.open(res_path, 'w') do |f|
119
- tpl = ''
120
- tpl_path = (File.join(File.dirname(__FILE__), 'files', 'environments', 'environment.rb.erb'))
121
- File.open(tpl_path) do |tf|
122
- tpl = tf.read
123
- end
124
- erb = ERB.new tpl
125
- erb.filename = res_path
126
- f.puts erb.result(binding)
123
+ tpl = ''
124
+ tpl_path = (File.join(File.dirname(__FILE__), 'files', 'environments', 'environment.rb.erb'))
125
+ File.open(tpl_path) do |tf|
126
+ tpl = tf.read
127
+ end
128
+ erb = ERB.new tpl
129
+ erb.filename = res_path
130
+ f.puts erb.result(binding)
127
131
  end
128
132
  end
129
133
  end
130
134
  end
131
135
 
136
+ # Describe
137
+
132
138
  Command.new('describe', "describes a laborantin's work") do |c|
133
139
  c.opts do |o|
134
140
  o.on_tail('-h', '--help', 'shows this help and exit') {puts o; exit}
@@ -144,8 +150,59 @@ Command.new('describe', "describes a laborantin's work") do |c|
144
150
  end
145
151
  end
146
152
 
153
+ # Scan
154
+
155
+ Command.new('scan', "scan a laborantin's dir for results") do |c|
156
+ c.opts do |o|
157
+ o.on_tail('-h', '--help', 'shows this help and exit') {puts o; exit}
158
+ end
159
+ c.execute do
160
+ FileUtils.cd(args.first || '.')
161
+ Find.find('environments', 'scenarii') do |f|
162
+ require f if File.extname(f) == '.rb'
163
+ end
164
+
165
+ envs = []
166
+ scs = []
147
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
148
193
 
194
+ puts "Laborantin' summary:"
195
+ Laborantin::Environment.all.each do |envklass|
196
+ puts "#{envklass.name.duck_case} => #{envs.count{|e| e.is_a? envklass}}"
197
+ Laborantin::Scenario.all.each do |scklass|
198
+ puts "\t#{scklass.name.duck_case} => #{scs.count{|s| s.is_a? scklass and s.environment.is_a? envklass}}"
199
+ end
200
+ end
201
+
202
+ end
203
+ end
204
+
205
+ # Run
149
206
 
150
207
  Command.new('run', 'actually perform measurements') do |c|
151
208
  c.options[:scenarii] = []
@@ -165,18 +222,18 @@ Command.new('run', 'actually perform measurements') do |c|
165
222
  end
166
223
 
167
224
  envs = if c.options[:environments].empty?
168
- Laborantin::Environment.all
169
- else
170
- c.options[:environments].map!{|e| e.camelize}
171
- Laborantin::Environment.all.select{|e| c.options[:environments].include? e.name}
172
- end
225
+ Laborantin::Environment.all
226
+ else
227
+ c.options[:environments].map!{|e| e.camelize}
228
+ Laborantin::Environment.all.select{|e| c.options[:environments].include? e.name}
229
+ end
173
230
 
174
231
  scii = if c.options[:scenarii].empty?
175
- Laborantin::Scenario.all
176
- else
177
- c.options[:scenarii].map!{|e| e.camelize}
178
- Laborantin::Scenario.all.select{|e| c.options[:scenarii].include? e.name}
179
- end
232
+ Laborantin::Scenario.all
233
+ else
234
+ c.options[:scenarii].map!{|e| e.camelize}
235
+ Laborantin::Scenario.all.select{|e| c.options[:scenarii].include? e.name}
236
+ end
180
237
 
181
238
  params = eval @options[:filter] unless @options[:filter].empty?
182
239
  params.each_key{|k| params[k] = [params[k]].flatten} if params
@@ -184,28 +241,64 @@ Command.new('run', 'actually perform measurements') do |c|
184
241
  envs.each do |eklass|
185
242
  env = eklass.new
186
243
  unless eklass.verifications.find{|v| not env.send(v)} #TODO: pass into class, rescue errors
187
- env.prepare!
188
- env.log "Running matching scenarii", :info #TODO: pass the logging+running in the env
189
- scii.each do |sklass|
190
- sklass.parameters.merge! params if params
191
- env.log sklass.parameters.inspect
192
- sklass.parameters.each_config do |cfg|
193
- sc = sklass.new(env, cfg)
194
- sc.prepare!
195
- sc.perform!
196
- sc.analyze!
197
- end
198
- end
199
- env.log "Scenarii performed", :info
200
- env.analyze!
244
+ env.prepare!
245
+ env.log "Running matching scenarii", :info #TODO: pass the logging+running in the env
246
+ scii.each do |sklass|
247
+ sklass.parameters.merge! params if params
248
+ env.log sklass.parameters.inspect
249
+ sklass.parameters.each_config do |cfg|
250
+ sc = sklass.new(env, cfg)
251
+ sc.prepare!
252
+ sc.perform!
253
+ sc.analyze!
254
+ end
255
+ end
256
+ env.log "Scenarii performed", :info
257
+ env.analyze!
201
258
  end
202
259
  end
203
260
  end
204
261
  end
205
262
 
206
- =begin
207
- TODO: replay, scan, push, pull
208
- =end
263
+ # FTP
264
+
265
+ Command.new('ftp-up', 'upload results via FTP') do |c|
266
+ c.opts do |o|
267
+ o.on_tail('-h', '--help', 'shows this help and exit') {puts o; exit}
268
+ end
269
+ c.execute do
270
+ dir = args.first || '.'
271
+ FileUtils.cd(dir)
272
+ cfg_file = File.join('config', 'ftp.yaml')
273
+ puts "Reading config file from #{cfg_file}"
274
+ cfg = YAML.load_file cfg_file
275
+ if cfg[:enable]
276
+ #TODO: port
277
+ # optimize that
278
+ ftp = Net::FTP.open(cfg[:host], cfg[:nick], cfg[:pass]) do |ftp|
279
+ Find.find('results') do |f|
280
+ if File.directory? f
281
+ ftp.chdir '/'
282
+ begin
283
+ ftp.mkdir f
284
+ rescue Net::FTPPermError
285
+ end
286
+ ftp.chdir f
287
+ elsif File.file? f
288
+ begin
289
+ ftp.putbinaryfile f
290
+ rescue Net::FTPPermError
291
+ end
292
+ end
293
+ end
294
+ end #ftp
295
+ else
296
+ p "Disabled, please edit #{cfg_file}"
297
+ end
298
+ end
299
+ end
300
+
301
+ # Actually run the commands
209
302
 
210
303
  cmd = Command.for_name ARGV.first
211
304
 
@@ -217,10 +310,12 @@ else
217
310
  puts %{#{$0} v.#{Laborantin::VERSION}: No command given
218
311
 
219
312
  Usage: #{$0} <command> [options ...]
220
- <command> among: #{Command.all.map{|c| c.name}.join(', ')}
221
313
 
222
- use #{$0} <command> --help for help on a specific command}
314
+ <command> among: #{Command.all.map{|c| c.name}.join(", ")}
315
+
316
+ use #{$0} <command> --help for help on a specific command
317
+ }
223
318
  else
224
- print "unknown command #{ARGV.first}"
319
+ puts "Unknown command #{ARGV.first}. \nKnown commands: #{Command.all.map{|c| c.name}.join(', ')} "
225
320
  end
226
321
  end
data/lib/laborantin.rb CHANGED
@@ -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.4'
31
+ VERSION = '0.0.7'
32
32
  AUTHORS = ['Lucas Di Cioccio']
33
33
  WEBSITE = 'http://dicioccio.fr'
34
34
  LICENSE = 'GNU GPL version 3'
@@ -72,6 +72,7 @@ module Laborantin
72
72
 
73
73
  end
74
74
 
75
+ #XXX: rundir is the easier way to override the rundir (instead of parsing a date)
75
76
  attr_accessor :rundir, :date, :loggers
76
77
 
77
78
  def initialize(dir='.')
@@ -79,7 +79,7 @@ module Laborantin
79
79
  end
80
80
  end # class <<
81
81
 
82
- attr_reader :params, :environment, :date, :rundir
82
+ attr_accessor :params, :environment, :date, :rundir
83
83
 
84
84
  def initialize(env, params={})
85
85
  @environment = env
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.6
4
+ version: 0.0.7
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-20 00:00:00 +02:00
12
+ date: 2009-07-22 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15