Class: Metabuild::Log

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

Overview

Mother class for reporting. Defines a simple text-based logfile

Direct Known Subclasses

LogHtml, LogText

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Log

Returns a new instance of Log.



142
143
144
145
# File 'lib/metabuild.rb', line 142

def initialize(name)
  @name = name
  @subscript = (defined? $subscript_log and not $subscript_log.nil?) ? true : false
end

Instance Attribute Details

#name ⇒ Object

Returns the value of attribute name.



140
141
142
# File 'lib/metabuild.rb', line 140

def name
  @name
end

Instance Method Details

#env_spawn(cmd, env, fail_msg, success_msg) ⇒ Object

Spawn with env



170
171
172
173
174
175
# File 'lib/metabuild.rb', line 170

def env_spawn(cmd, env, fail_msg, success_msg)
  str = ""
  env.each { |k, v| str += "export #{k}=#{v};"}
  pid = spawn(str + cmd)
  return [pid, fail_msg]
end

#env_system(cmd, env) ⇒ Object

Helper while waiting for Ruby 1.9 and the "env" option in system



148
149
150
151
152
# File 'lib/metabuild.rb', line 148

def env_system(cmd, env)
  str = ""
  env.each { |k, v| str += "export #{k}=#{v};"}
  system(str + cmd)
end

#failure(f) ⇒ Object



204
205
206
# File 'lib/metabuild.rb', line 204

def failure(f)
  exit false
end

#finish ⇒ Object



212
213
214
# File 'lib/metabuild.rb', line 212

def finish
  exit true
end

#integrate(log) ⇒ Object



208
209
210
# File 'lib/metabuild.rb', line 208

def integrate log
  raise "Should be implemented in child class"
end

#parallel_wait(p) ⇒ Object



177
178
179
180
# File 'lib/metabuild.rb', line 177

def parallel_wait(p)
  pid, stat = Process::waitpid2(p[0])
  failure p[1] unless stat.success?
end

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

Run a shell command, log its status (override in child class)



155
156
157
# File 'lib/metabuild.rb', line 155

def run(command, env, fail_msg, skip)
  env_system(command, env) unless skip
end

#script(script, args, options, fail_msg, use_default) ⇒ Object

Run another ruby build script Be careful with global variables !!! By default, the default options values are transmitted to the subscript



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/metabuild.rb', line 185

def script(script, args, options, fail_msg, use_default)
  $subscript_argv = args.split
  options.each {|k,v| $subscript_argv.push "--#{k}=#{v}" if (DEFAULT_OPTIONS.has_key?(k) and not args =~ /--#{k}=/)} if use_default
  $subscript_log = ""
  begin
    load(script, true)
  rescue Exception => exception
    integrate $subscript_log if $subscript_log != ""
    if exception.kind_of? SystemExit 
      failure fail_msg unless exception.success?
    else
      failure(fail_msg + "(#{exception.class}: #{exception.message})\n" + exception.backtrace.join("\n")) 
    end
  end
  integrate $subscript_log
  $subscript_log = nil
  $subscript_argv = nil
end

#silent(command, env) ⇒ Object

Run a shell command, no logging (override in child class)



160
161
162
# File 'lib/metabuild.rb', line 160

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

#status ⇒ Object



216
217
218
# File 'lib/metabuild.rb', line 216

def status
  false
end

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

Run a shell command. Log success and failure (override in child class)



165
166
167
# File 'lib/metabuild.rb', line 165

def valid(command, env, fail_msg, success_msg, skip)
  env_system(command, env) unless skip
end