laborantin 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/TODO +1 -4
- data/bin/labor +155 -60
- data/lib/laborantin.rb +1 -1
- data/lib/laborantin/core/environment.rb +1 -0
- data/lib/laborantin/core/scenario.rb +1 -1
- metadata +2 -2
data/Rakefile
CHANGED
data/TODO
CHANGED
data/bin/labor
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
-
|
5
|
-
require 'laborantin'
|
6
|
-
|
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
|
-
|
80
|
+
FileUtils.mkdir dir
|
77
81
|
rescue Errno::EEXIST => err
|
78
|
-
|
79
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
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
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
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
|
-
|
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.
|
31
|
+
VERSION = '0.0.7'
|
32
32
|
AUTHORS = ['Lucas Di Cioccio']
|
33
33
|
WEBSITE = 'http://dicioccio.fr'
|
34
34
|
LICENSE = 'GNU GPL version 3'
|
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.
|
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-
|
12
|
+
date: 2009-07-22 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|