Class: Metabuild::LogText

Inherits:
Log
  • Object
show all
Defined in:
lib/metabuild.rb

Overview

Simple log that just prints out text (for console builds)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Log

#env_spawn, #env_system, #parallel_wait, #script

Constructor Details

#initialize(name) ⇒ LogText

Returns a new instance of LogText.



227
228
229
230
231
232
# File 'lib/metabuild.rb', line 227

def initialize(name)
  super(name)
  @fail, @success, @skip = [], [], []
  @subscripts = []
  @report_done = false
end

Instance Attribute Details

#failObject (readonly)

Returns the value of attribute fail.



225
226
227
# File 'lib/metabuild.rb', line 225

def fail
  @fail
end

#nameObject (readonly)

Returns the value of attribute name.



225
226
227
# File 'lib/metabuild.rb', line 225

def name
  @name
end

#skipObject (readonly)

Returns the value of attribute skip.



225
226
227
# File 'lib/metabuild.rb', line 225

def skip
  @skip
end

#successObject (readonly)

Returns the value of attribute success.



225
226
227
# File 'lib/metabuild.rb', line 225

def success
  @success
end

Instance Method Details

#add_fail(msg) ⇒ Object



234
235
236
# File 'lib/metabuild.rb', line 234

def add_fail(msg)
  @fail.push msg
end

#add_skip(msg) ⇒ Object



242
243
244
# File 'lib/metabuild.rb', line 242

def add_skip(msg)
  @skip.push "SKIPPED : #{msg}"
end

#add_success(msg) ⇒ Object



238
239
240
# File 'lib/metabuild.rb', line 238

def add_success(msg)
  @success.push msg
end

#failure(msg) ⇒ Object

Stop script, adding a message to the log



318
319
320
321
# File 'lib/metabuild.rb', line 318

def failure(msg)
  add_fail msg
  stop
end

#finishObject



329
330
331
332
# File 'lib/metabuild.rb', line 329

def finish
  report
  exit status
end

#integrate(log) ⇒ Object



310
311
312
313
314
315
# File 'lib/metabuild.rb', line 310

def integrate log
  @subscripts.push log.name
  log.success.each {|s| @success.push("[#{log.name}] " + s)}
  log.fail.each {|f| @fail.push("[#{log.name}] " + f)}
  log.skip.each {|f| @skip.push("[#{log.name}] " + f)}
end

#outputObject



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/metabuild.rb', line 256

def output
  puts "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
  puts @name
  puts "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
  puts "Ran the following subscripts :"
  @subscripts.each {|s| puts s}
  puts "----------------------------------------------"
  puts "Sucess : "
  @success.each {|s| puts s}
  puts "----------------------------------------------"
  puts "Fail : "
  @fail.each {|s| puts s}
  puts "----------------------------------------------"
  puts "Skipped : "
  @skip.each {|s| puts s}
  puts "----------------------------------------------"
end

#reportObject



246
247
248
249
250
251
252
253
254
# File 'lib/metabuild.rb', line 246

def report
  return if @report_done # prevent reporting several times
  if @subscript
    $subscript_log = self
  else
    output
  end
  @report_done = true
end

#run(command, env, fail_msg, skip) ⇒ Object

Run a shell command, log



279
280
281
282
283
284
285
286
287
288
289
# File 'lib/metabuild.rb', line 279

def run(command, env, fail_msg, skip)
  if skip
    add_skip command
  else
    if env_system(command, env)
      add_success "[#{@name}] #{command} SUCCESS"
    else
      failure fail_msg
    end
  end
end

#silent(command, env) ⇒ Object

Run a shell command, no logging



292
293
294
# File 'lib/metabuild.rb', line 292

def silent(command, env)
  stop unless env_system(command, env)
end

#statusObject



274
275
276
# File 'lib/metabuild.rb', line 274

def status
  @fail.empty?
end

#stopObject

Output log and exit with error exit status



324
325
326
327
# File 'lib/metabuild.rb', line 324

def stop
  report
  exit false
end

#valid(command, env, fail_msg, success_msg, skip) ⇒ Object

Run a shell command. Log success and failure



297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/metabuild.rb', line 297

def valid(command, env, fail_msg, success_msg, skip)
  if skip
    add_skip command
  else
    if env_system(command, env)
      add_success success_msg if success_msg != ""
    else
      failure(fail_msg) if ENV.has_key? "METABUILD_PARALLEL"
      add_fail fail_msg
    end
  end
end