Class: EY::Serverside::Shell
- Inherits:
-
Object
show all
- Defined in:
- lib/engineyard-serverside/shell.rb,
lib/engineyard-serverside/shell/helpers.rb,
lib/engineyard-serverside/shell/yieldio.rb,
lib/engineyard-serverside/shell/formatter.rb,
lib/engineyard-serverside/shell/command_result.rb
Defined Under Namespace
Modules: Helpers
Classes: CommandResult, Formatter, YieldIO
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ Shell
Returns a new instance of Shell.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/engineyard-serverside/shell.rb', line 13
def initialize(options)
@start_time = options[:start_time]
@verbose = options[:verbose]
@stdout = options[:stdout] || $stdout
@stderr = options[:stderr] || $stderr
log_pathname = Pathname.new(options[:log_path])
log_pathname.unlink if log_pathname.exist? @logger = Logger.new(log_pathname.to_s)
@logger.level = Logger::DEBUG @logger.formatter = EY::Serverside::Shell::Formatter.new(@stdout, @stderr, start_time, @verbose)
end
|
Instance Attribute Details
Returns the value of attribute logger.
11
12
13
|
# File 'lib/engineyard-serverside/shell.rb', line 11
def logger
@logger
end
|
Instance Method Details
#debug(msg) ⇒ Object
46
|
# File 'lib/engineyard-serverside/shell.rb', line 46
def debug(msg) logger.debug msg end
|
#error(msg) ⇒ Object
42
|
# File 'lib/engineyard-serverside/shell.rb', line 42
def error(msg) logger.error "ERROR: #{msg}" end
|
#fatal(msg) ⇒ Object
41
|
# File 'lib/engineyard-serverside/shell.rb', line 41
def fatal(msg) logger.fatal "FATAL: #{msg}" end
|
#info(msg) ⇒ Object
45
|
# File 'lib/engineyard-serverside/shell.rb', line 45
def info(msg) logger.info msg end
|
#logged_system(cmd) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/engineyard-serverside/shell.rb', line 58
def logged_system(cmd)
show_command(cmd)
output = ""
outio = YieldIO.new { |msg| output << msg; debug msg.gsub(/^/,' ') }
errio = YieldIO.new { |msg| output << msg; unknown msg.gsub(/^/,' ') }
result = spawn_process(cmd, outio, errio)
CommandResult.new(cmd, result.exitstatus, output)
end
|
#notice(msg) ⇒ Object
44
|
# File 'lib/engineyard-serverside/shell.rb', line 44
def notice(msg) logger.warn msg end
|
#show_command(cmd) ⇒ Object
a debug outputter that displays a command being run Formatis like this:
$ cmd blah do \
> something more
> end
54
55
56
|
# File 'lib/engineyard-serverside/shell.rb', line 54
def show_command(cmd)
debug cmd.gsub(/^/, ' > ').sub(/>/, '$')
end
|
#start_time ⇒ Object
28
29
30
|
# File 'lib/engineyard-serverside/shell.rb', line 28
def start_time
@start_time ||= Time.now
end
|
#status(msg) ⇒ Object
a nice info outputter that prepends spermy operators for some reason.
33
34
35
|
# File 'lib/engineyard-serverside/shell.rb', line 33
def status(msg)
info msg.gsub(/^/, '~> ')
end
|
#substatus(msg) ⇒ Object
37
38
39
|
# File 'lib/engineyard-serverside/shell.rb', line 37
def substatus(msg)
debug msg.gsub(/^/, ' ~ ')
end
|
#unknown(msg) ⇒ Object
47
|
# File 'lib/engineyard-serverside/shell.rb', line 47
def unknown(msg) logger.unknown msg end
|
#warning(msg) ⇒ Object
43
|
# File 'lib/engineyard-serverside/shell.rb', line 43
def warning(msg) logger.warn "WARNING: #{msg}" end
|