mixlib-shellout 1.0.0.rc.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mixlib/shellout/unix.rb +2 -2
- data/lib/mixlib/shellout/version.rb +1 -1
- data/lib/mixlib/shellout/windows.rb +45 -11
- metadata +35 -28
    
        data/lib/mixlib/shellout/unix.rb
    CHANGED
    
    | @@ -185,7 +185,7 @@ module Mixlib | |
| 185 185 | 
             
                    end
         | 
| 186 186 | 
             
                  rescue Errno::EAGAIN
         | 
| 187 187 | 
             
                  rescue EOFError
         | 
| 188 | 
            -
                    open_pipes. | 
| 188 | 
            +
                    open_pipes.delete(child_stdout)
         | 
| 189 189 | 
             
                  end
         | 
| 190 190 |  | 
| 191 191 | 
             
                  def read_stderr_to_buffer
         | 
| @@ -194,7 +194,7 @@ module Mixlib | |
| 194 194 | 
             
                    end
         | 
| 195 195 | 
             
                  rescue Errno::EAGAIN
         | 
| 196 196 | 
             
                  rescue EOFError
         | 
| 197 | 
            -
                    open_pipes. | 
| 197 | 
            +
                    open_pipes.delete(child_stderr)
         | 
| 198 198 | 
             
                  end
         | 
| 199 199 |  | 
| 200 200 | 
             
                  def fork_subprocess
         | 
| @@ -42,6 +42,7 @@ module Mixlib | |
| 42 42 | 
             
                    #
         | 
| 43 43 | 
             
                    stdout_read, stdout_write = IO.pipe
         | 
| 44 44 | 
             
                    stderr_read, stderr_write = IO.pipe
         | 
| 45 | 
            +
                    stdin_read, stdin_write = IO.pipe
         | 
| 45 46 | 
             
                    open_streams = [ stdout_read, stderr_read ]
         | 
| 46 47 |  | 
| 47 48 | 
             
                    begin
         | 
| @@ -55,7 +56,8 @@ module Mixlib | |
| 55 56 | 
             
                        :command_line => command_line,
         | 
| 56 57 | 
             
                        :startup_info => {
         | 
| 57 58 | 
             
                          :stdout => stdout_write,
         | 
| 58 | 
            -
                          :stderr => stderr_write
         | 
| 59 | 
            +
                          :stderr => stderr_write,
         | 
| 60 | 
            +
                          :stdin => stdin_read
         | 
| 59 61 | 
             
                        },
         | 
| 60 62 | 
             
                        :environment => inherit_environment.map { |k,v| "#{k}=#{v}" },
         | 
| 61 63 | 
             
                        :close_handles => false
         | 
| @@ -88,7 +90,7 @@ module Mixlib | |
| 88 90 | 
             
                          when WAIT_TIMEOUT
         | 
| 89 91 | 
             
                            # Kill the process
         | 
| 90 92 | 
             
                            if (Time.now - start_wait) > timeout
         | 
| 91 | 
            -
                              raise Mixlib::ShellOut::CommandTimeout, "command timed out:\n#{format_for_exception}"
         | 
| 93 | 
            +
                              raise Mixlib::ShellOut::Exceptions::CommandTimeout, "command timed out:\n#{format_for_exception}"
         | 
| 92 94 | 
             
                            end
         | 
| 93 95 |  | 
| 94 96 | 
             
                            consume_output(open_streams, stdout_read, stderr_read)
         | 
| @@ -119,6 +121,9 @@ module Mixlib | |
| 119 121 |  | 
| 120 122 | 
             
                  class ThingThatLooksSortOfLikeAProcessStatus
         | 
| 121 123 | 
             
                    attr_accessor :exitstatus
         | 
| 124 | 
            +
                    def success?
         | 
| 125 | 
            +
                      exitstatus == 0
         | 
| 126 | 
            +
                    end
         | 
| 122 127 | 
             
                  end
         | 
| 123 128 |  | 
| 124 129 | 
             
                  def consume_output(open_streams, stdout_read, stderr_read)
         | 
| @@ -149,13 +154,33 @@ module Mixlib | |
| 149 154 | 
             
                    return true
         | 
| 150 155 | 
             
                  end
         | 
| 151 156 |  | 
| 152 | 
            -
                   | 
| 157 | 
            +
                  IS_BATCH_FILE = /\.bat|\.cmd$/i
         | 
| 153 158 |  | 
| 154 159 | 
             
                  def command_to_run
         | 
| 155 | 
            -
                    if command =~  | 
| 160 | 
            +
                    if command =~ /^\s*"(.*)"/
         | 
| 161 | 
            +
                      # If we have quotes, do an exact match
         | 
| 162 | 
            +
                      candidate = $1
         | 
| 163 | 
            +
                    else
         | 
| 164 | 
            +
                      # Otherwise check everything up to the first space
         | 
| 165 | 
            +
                      candidate = command[0,command.index(/\s/) || command.length].strip
         | 
| 166 | 
            +
                    end
         | 
| 167 | 
            +
             | 
| 168 | 
            +
                    # Don't do searching for empty commands.  Let it fail when it runs.
         | 
| 169 | 
            +
                    if candidate.length == 0
         | 
| 170 | 
            +
                      return [ nil, command ]
         | 
| 171 | 
            +
                    end
         | 
| 172 | 
            +
             | 
| 173 | 
            +
                    # Check if the exe exists directly.  Otherwise, search PATH.
         | 
| 174 | 
            +
                    exe = find_exe_at_location(candidate)
         | 
| 175 | 
            +
                    if exe.nil? && exe !~ /[\\\/]/
         | 
| 176 | 
            +
                      exe = which(command[0,command.index(/\s/) || command.length])
         | 
| 177 | 
            +
                    end
         | 
| 178 | 
            +
             | 
| 179 | 
            +
                    if exe.nil? || exe =~ IS_BATCH_FILE
         | 
| 180 | 
            +
                      # Batch files MUST use cmd; and if we couldn't find the command we're looking for, we assume it must be a cmd builtin.
         | 
| 156 181 | 
             
                      [ ENV['COMSPEC'], "cmd /c #{command}" ]
         | 
| 157 182 | 
             
                    else
         | 
| 158 | 
            -
                      [  | 
| 183 | 
            +
                      [ exe, command ]
         | 
| 159 184 | 
             
                    end
         | 
| 160 185 | 
             
                  end
         | 
| 161 186 |  | 
| @@ -175,14 +200,23 @@ module Mixlib | |
| 175 200 | 
             
                    result
         | 
| 176 201 | 
             
                  end
         | 
| 177 202 |  | 
| 203 | 
            +
                  def pathext
         | 
| 204 | 
            +
                    @pathext ||= ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') + [''] : ['']
         | 
| 205 | 
            +
                  end
         | 
| 206 | 
            +
             | 
| 178 207 | 
             
                  def which(cmd)
         | 
| 179 | 
            -
                    return cmd if File.executable? cmd
         | 
| 180 | 
            -
                    exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') + [''] : ['']
         | 
| 181 208 | 
             
                    ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
         | 
| 182 | 
            -
                       | 
| 183 | 
            -
             | 
| 184 | 
            -
             | 
| 185 | 
            -
             | 
| 209 | 
            +
                      exe = find_exe_at_location("#{path}/${cmd}")
         | 
| 210 | 
            +
                      return exe if exe
         | 
| 211 | 
            +
                    end
         | 
| 212 | 
            +
                    return nil
         | 
| 213 | 
            +
                  end
         | 
| 214 | 
            +
             | 
| 215 | 
            +
                  def find_exe_at_location(path)
         | 
| 216 | 
            +
                    return path if File.executable? path
         | 
| 217 | 
            +
                    pathext.each do |ext|
         | 
| 218 | 
            +
                      exe = "#{path}#{ext}"
         | 
| 219 | 
            +
                      return exe if File.executable? exe
         | 
| 186 220 | 
             
                    end
         | 
| 187 221 | 
             
                    return nil
         | 
| 188 222 | 
             
                  end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,35 +1,38 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification
         | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: mixlib-shellout
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
               | 
| 5 | 
            -
               | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              prerelease: 
         | 
| 5 | 
            +
              version: 1.0.0
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 | 
            -
            authors:
         | 
| 7 | 
            +
            authors: 
         | 
| 8 8 | 
             
            - Opscode
         | 
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 12 | 
            +
             | 
| 13 | 
            +
            date: 2012-02-28 00:00:00 Z
         | 
| 14 | 
            +
            dependencies: 
         | 
| 15 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 15 16 | 
             
              name: rspec
         | 
| 16 | 
            -
               | 
| 17 | 
            +
              prerelease: false
         | 
| 18 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 17 19 | 
             
                none: false
         | 
| 18 | 
            -
                requirements:
         | 
| 19 | 
            -
                - -  | 
| 20 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            -
                    version:  | 
| 20 | 
            +
                requirements: 
         | 
| 21 | 
            +
                - - ">="
         | 
| 22 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 23 | 
            +
                    version: "0"
         | 
| 22 24 | 
             
              type: :development
         | 
| 23 | 
            -
               | 
| 24 | 
            -
              version_requirements: *70226438013220
         | 
| 25 | 
            +
              version_requirements: *id001
         | 
| 25 26 | 
             
            description: Run external commands on Unix or Windows
         | 
| 26 27 | 
             
            email: info@opscode.com
         | 
| 27 28 | 
             
            executables: []
         | 
| 29 | 
            +
             | 
| 28 30 | 
             
            extensions: []
         | 
| 29 | 
            -
             | 
| 31 | 
            +
             | 
| 32 | 
            +
            extra_rdoc_files: 
         | 
| 30 33 | 
             
            - README.md
         | 
| 31 34 | 
             
            - LICENSE
         | 
| 32 | 
            -
            files:
         | 
| 35 | 
            +
            files: 
         | 
| 33 36 | 
             
            - LICENSE
         | 
| 34 37 | 
             
            - README.md
         | 
| 35 38 | 
             
            - lib/mixlib/shellout/exceptions.rb
         | 
| @@ -39,26 +42,30 @@ files: | |
| 39 42 | 
             
            - lib/mixlib/shellout.rb
         | 
| 40 43 | 
             
            homepage: http://wiki.opscode.com/
         | 
| 41 44 | 
             
            licenses: []
         | 
| 45 | 
            +
             | 
| 42 46 | 
             
            post_install_message: 
         | 
| 43 47 | 
             
            rdoc_options: []
         | 
| 44 | 
            -
             | 
| 48 | 
            +
             | 
| 49 | 
            +
            require_paths: 
         | 
| 45 50 | 
             
            - lib
         | 
| 46 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 47 52 | 
             
              none: false
         | 
| 48 | 
            -
              requirements:
         | 
| 49 | 
            -
              - -  | 
| 50 | 
            -
                - !ruby/object:Gem::Version
         | 
| 51 | 
            -
                  version:  | 
| 52 | 
            -
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 53 | 
            +
              requirements: 
         | 
| 54 | 
            +
              - - ">="
         | 
| 55 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 56 | 
            +
                  version: "0"
         | 
| 57 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 53 58 | 
             
              none: false
         | 
| 54 | 
            -
              requirements:
         | 
| 55 | 
            -
              - -  | 
| 56 | 
            -
                - !ruby/object:Gem::Version
         | 
| 57 | 
            -
                  version:  | 
| 59 | 
            +
              requirements: 
         | 
| 60 | 
            +
              - - ">="
         | 
| 61 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 62 | 
            +
                  version: "0"
         | 
| 58 63 | 
             
            requirements: []
         | 
| 64 | 
            +
             | 
| 59 65 | 
             
            rubyforge_project: 
         | 
| 60 66 | 
             
            rubygems_version: 1.8.10
         | 
| 61 67 | 
             
            signing_key: 
         | 
| 62 68 | 
             
            specification_version: 3
         | 
| 63 69 | 
             
            summary: Run external commands on Unix or Windows
         | 
| 64 70 | 
             
            test_files: []
         | 
| 71 | 
            +
             |