Module: Teapot::Commands

Defined in:
lib/teapot/commands.rb

Defined Under Namespace

Modules: Helpers Classes: CommandError, Pool

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.make(*args) ⇒ Object



81
82
83
# File 'lib/teapot/commands.rb', line 81

def self.make(*args)
  run("make", *args, "-j", processor_count)
end

.make_installObject



85
86
87
# File 'lib/teapot/commands.rb', line 85

def self.make_install
  make("install")
end

.pipeline(parallel = false) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/teapot/commands.rb', line 131

def self.pipeline(parallel = false)
  if parallel == false
    # Non-parallel execution pipeline
    Commands
  else
    # Pool based parallel execution pipeline
    Pool.new(parallel == true ? {} : parallel)
  end
end

.processor_countObject



39
40
41
42
43
44
45
# File 'lib/teapot/commands.rb', line 39

def self.processor_count
  # Get the number of virtual/physical processors
  count = Facter.processorcount.to_i rescue 1
  
  # Make sure we always return at least 1:
  count < 1 ? 1 : count
end

.run(*args, &block) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/teapot/commands.rb', line 54

def self.run(*args, &block)
  options = Hash === args.last ? args.pop : {}
  options[:passthrough] ||= :all
  
  args = args.flatten.collect &:to_s
  
  puts args.join(' ').color(:blue) + " in #{options[:chdir] || Dir.getwd}"
  
  task = RExec::Task.open(args, options, &block)
  
  if task.wait == 0
    true
  else
    raise CommandError.new("Non-zero exit status: #{args.join(' ')}!")
  end
end

.run!(*args, &block) ⇒ Object



71
72
73
74
75
# File 'lib/teapot/commands.rb', line 71

def self.run!(*args, &block)
  run(*args, &block)
rescue CommandError
  false
end

.split(arg) ⇒ Object



50
51
52
# File 'lib/teapot/commands.rb', line 50

def self.split(arg)
  Shellwords.split(arg || "")
end

Instance Method Details

#waitObject



77
78
79
# File 'lib/teapot/commands.rb', line 77

def wait
  # No parallel execution supported by default.
end