Ken,
A short while ago Jamis wrote out something like this...
This is the replay solution roughly..
you said you don't want this..
--------------------------------------------------------
require 'capistrano/configuration'
require 'stringio'
output = StringIO.new
config = Capistrano::Configuration.new
config.logger = Capistrano::Logger.new(:output => output)
config.load "/path/to/Capfile"
config.logger.level = 3
config.deploy
puts output.string
--------------------------------------------------------
#Modify the last line
puts output.string
- to -
puts output.string.match("^[*]{3}.*")
Alternatively you can modify the Capistrano Base source
or extended the class of this module of
capistrano/lib/capistrano/logger.rb
@~line 30
def log(level, message, line_prefix=nil)
if level <= self.level
indent = "%*s" % [MAX_LEVEL, "*" * (MAX_LEVEL - level)]
message.each do |line|
if line_prefix
device.puts "#{indent} [#{line_prefix}] #{line.strip}\n"
else
device.puts "#{indent} #{line.strip}\n"
end
end
end
end
You could add regex pattern match here... on the two device.puts
statements.
Then any output you "puts" should be change to a capistrano logger
statement
(ie if you are breaking up a run call with |channel stream data|).
On Apr 21, 10:23 am, Ken Collins <[EMAIL PROTECTED]> wrote:
> I have a ruby script that issues cap commands in bulk. What I would
> like to do is to filter the output of that script to show only the
> lines returned from the executing cap command that begin with a
> certain number of ** before them. Basically rolling my own verbosity/
> filter for cap in my script. I am admittedly weak in dealing with IO
> in ruby and would love some help. I would like my interface to be
> something like this.
>
> filtered_out do
> system(command)
> end
>
> The command would be the cap command of course and the filtered_out
> method would capture the $stdout in some way and filter it to my
> liking. My difficulty is thinking about how to do this in a way that
> filters $stdout in realtime as it is being captured vs waiting for the
> command to complete and then rewinding $stdout and filtering it
> accordingly. While googling around, I found this neat method in
> ZenTest and put it below to consideration, perhaps I can retool this?
>
> # Captures $stdout and $stderr to StringIO objects and returns them.
> # Restores $stdout and $stderr when done.
> #
> # Usage:
> # def test_puts
> # out, err = capture do
> # puts 'hi'
> # STDERR.puts 'bye!'
> # end
> # assert_equal "hi\n", out.string
> # assert_equal "bye!\n", err.string
> # end
>
> def util_capture
> require 'stringio'
> orig_stdout = $stdout.dup
> orig_stderr = $stderr.dup
> captured_stdout = StringIO.new
> captured_stderr = StringIO.new
> $stdout = captured_stdout
> $stderr = captured_stderr
> yield
> captured_stdout.rewind
> captured_stderr.rewind
> return captured_stdout, captured_stderr
> ensure
> $stdout = orig_stdout
> $stderr = orig_stderr
> end
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---