Class: Rubble::Executor::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/rubble/executor/local.rb

Defined Under Namespace

Classes: Line, Output, StreamInfo

Instance Method Summary collapse

Methods inherited from Base

#convert_options, #exec, #initialize, #redirect, #rsync, #rsync_includes, #rsync_remote_prefix

Constructor Details

This class inherits a constructor from Rubble::Executor::Base

Instance Method Details

#file_exists?(file) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rubble/executor/local.rb', line 56

def file_exists?(file)
    Pathname(file).exists?
end

#mkdir(directory_name) ⇒ Object



48
49
50
# File 'lib/rubble/executor/local.rb', line 48

def mkdir(directory_name)
    Pathname(directory_name).mkpath
end

#run(*command) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rubble/executor/local.rb', line 60

def run(*command)
    command_str = Shellwords.join(command)
    @log.debug(command_str)

    status = nil
    output = Output.new(@log)

    Open3.popen3(command_str) do |stdin, stdout, stderr, thread|
        streams = {stdout => StreamInfo.new(:info, false), stderr => StreamInfo.new(:error, false)}

        until streams.empty? do
            selected, = IO::select(streams.keys, nil, nil, 0.1)

            if not selected.nil? then
                selected.each do |stream|
                    info = streams[stream]

                    if stream.eof? then
                        streams.delete(stream)

                        if not info.data.empty? then
                            output << Line.new(info.level, info.data)
                        end
                    else
                        data = info.data + stream.readpartial(1024)

                        data.each_line do |line|
                            if line.end_with?("\n") then
                                output << Line.new(info.level, line)
                            else
                                info.data = line
                            end
                        end
                    end

                    if info.autoflush then
                        output.flush
                    end
                end
            end
        end

        status = thread.value
    end

    if status.exitstatus != 0 then
        output.flush
        raise "Command failed with exit status #{status.exitstatus}."
    end
end


52
53
54
# File 'lib/rubble/executor/local.rb', line 52

def symlink(source, target)
    Pathname(target).make_symlink(Pathname(source))
end