<commit_before>class Runner
  include MessageLogger
  @@silent = false

  def self.execute! options
    @@silent = options[:silent]
    @@verbose = options[:verbose]
    task = options[:task]

    if (task.__servers.nil? or task.__servers == [] or task.__servers.compact == []) and task.__built_commands.any? {|c| c[:type] == :remote or c[:type] == :scp }
      raise Screwcap::ConfigurationError, "The task #{task.name} includes remote commands, however no servers were defined for this task."
    end

    if options[:servers] and task.__servers
      begin
        servers = options[:servers].select {|s| task.__servers.include? s.__name }
        connections = servers.map {|server| server.connect! }.flatten
      rescue Net::SSH::AuthenticationFailed => e
        raise Net::SSH::AuthenticationFailed, "Authentication failed for server named #{server.name}.  Please check your authentication credentials."
      end
    end

    _log "\nExecuting task #{task.name}\n", :color => :blue

    task.__built_commands.each do |command|
      ret = case command[:type]
      when :remote
        threads = []
        connections.each do |connection|
          threads << Thread.new(connection) do |conn|
            run_remote_command(command, conn, options)
          end
        end
        threads.each {|t| t.join }
      when :local
        ret = `#{command[:command]}`
        command[:stdout] = ret
        if $?.to_i == 0
          if options[:verbose]
            _log "    O: #{ret}\n", :color => :green
          else
            _log(".", :color => :green)
          end
        else
          _errorlog("    E: (local): #{command[:command]} return exit code: #{$?}\n", :color => :red) if $? != 0
        end
        ret
      when :scp
        threads = []
        servers.each do |server|
          threads << Thread.new(server) { |_server| _server._upload! command[:local], command[:remote] }
        end
        threads.each {|t| t.join }
        return 0
      when :block
        command[:block].call
      end
    end
    _log "Complete\n", :color => :blue
    task.__built_commands # for tests
  end

  private

  def self.run_remote_command(command, ssh, options)
    stdout, stderr, exit_code, exit_signal = ssh_exec! ssh, command[:command]<commit_msg>gah, another typo in a hard-to-test area.  this should do it.<commit_after>class Runner
  include MessageLogger
  @@silent = false

  def self.execute! options
    @@silent = options[:silent]
    @@verbose = options[:verbose]
    task = options[:task]

    if (task.__servers.nil? or task.__servers == [] or task.__servers.compact == []) and task.__built_commands.any? {|c| c[:type] == :remote or c[:type] == :scp }
      raise Screwcap::ConfigurationError, "The task #{task.name} includes remote commands, however no servers were defined for this task."
    end

    if options[:servers] and task.__servers
      begin
        servers = options[:servers].select {|s| task.__servers.include? s.__name }
        connections = servers.map {|server| server.connect! }.flatten
      rescue Net::SSH::AuthenticationFailed => e
        raise Net::SSH::AuthenticationFailed, "Authentication failed for server named #{server.name}.  Please check your authentication credentials."
      end
    end

    _log "\nExecuting task #{task.name}\n", :color => :blue

    task.__built_commands.each do |command|
      ret = case command[:type]
      when :remote
        threads = []
        connections.each do |connection|
          threads << Thread.new(connection) do |conn|
            run_remote_command(command, conn, options)
          end
        end
        threads.each {|t| t.join }
      when :local
        ret = `#{command[:command]}`
        command[:stdout] = ret
        if $?.to_i == 0
          if options[:verbose]
            _log "    O: #{ret}\n", :color => :green
          else
            _log(".", :color => :green)
          end
        else
          _errorlog("    E: (local): #{command[:command]} return exit code: #{$?}\n", :color => :red) if $? != 0
        end
        ret
      when :scp
        threads = []
        servers.each do |server|
          threads << Thread.new(server) { |_server| _server.upload! command[:local], command[:remote] }
        end
        threads.each {|t| t.join }
        return 0
      when :block
        command[:block].call
      end
    end
    _log "Complete\n", :color => :blue
    task.__built_commands # for tests
  end

  private

  def self.run_remote_command(command, ssh, options)
    stdout, stderr, exit_code, exit_signal = ssh_exec! ssh, command[:command]
{'fraction_non_alphanumeric': 0.12910951447855432, 'fraction_numerical': 0.0013063357282821686, 'mean_word_length': 2.413075780089153, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '883565', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1326, 'n_words': 385}