<commit_before>module Guard
  class RemoteSync
    class Command

      attr_accessor :command, :source, :destination

      CLEAR = "\e[0m"
      # The start of an ANSI bold sequence.
      BOLD = "\e[1m"
      # Set the terminal's foreground ANSI color to black.
      BLACK = "\e[30m"
      # Set the terminal's foreground ANSI color to red.
      RED = "\e[31m"
      # Set the terminal's foreground ANSI color to green.
      GREEN = "\e[32m"
      # Set the terminal's foreground ANSI color to yellow.
      YELLOW = "\e[33m"
      # Set the terminal's foreground ANSI color to blue.
      BLUE = "\e[34m"
      # Set the terminal's foreground ANSI color to magenta.
      MAGENTA = "\e[35m"
      # Set the terminal's foreground ANSI color to cyan.
      CYAN = "\e[36m"
      # Set the terminal's foreground ANSI color to white.
      WHITE = "\e[37m"

      def initialize(source, destination, options = {})
        @options = options
        @source = source
        @destination = destination
        @command = build_command
      end

      def sync
        UI.info "Guard::RemoteSync `#{@command}`"
        run_command @command
      end

      def test
        $stderr.puts("\r\e[0m")
        $stderr.puts "#{BOLD}Testing rsync with a dry run and stats. Verifying the results...#{CLEAR}"
        opts = @options
        @options[:dry_run] = true
        @options[:stats] = true
        test_command = build_command
        @options = opts
        result = run_command test_command, {:suppress_output => false}
        $stderr.puts("\r\e[0m")
        result.to_i == 0
      end

      private

      def run_command(cmd, opts = {})
        options = {:color => CYAN, :suppress_output => false}.merge(opts)
        $stderr.puts "\r\e[0m" unless options[:suppress_output]
        exit_value = nil
        Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
          stdout.read.split("\n").each do |line|
            $stderr.puts "\t#{options[:color]}#{line}#{CLEAR}" unless options[:suppress_output]
          end
          stderr.read.split("\n").each do |line|
            $stderr.puts "\t#{BOLD}#{RED}ERROR:#{line}#{CLEAR}"
          end
          exit_value = wait_thr.value.to_s.split.last
        end<commit_msg>changed case sensitive open3 for ubunutu. Open3 works on mac and in travis, but not on Ubuntu<commit_after>module Guard
  class RemoteSync
    class Command

      attr_accessor :command, :source, :destination

      CLEAR = "\e[0m"
      # The start of an ANSI bold sequence.
      BOLD = "\e[1m"
      # Set the terminal's foreground ANSI color to black.
      BLACK = "\e[30m"
      # Set the terminal's foreground ANSI color to red.
      RED = "\e[31m"
      # Set the terminal's foreground ANSI color to green.
      GREEN = "\e[32m"
      # Set the terminal's foreground ANSI color to yellow.
      YELLOW = "\e[33m"
      # Set the terminal's foreground ANSI color to blue.
      BLUE = "\e[34m"
      # Set the terminal's foreground ANSI color to magenta.
      MAGENTA = "\e[35m"
      # Set the terminal's foreground ANSI color to cyan.
      CYAN = "\e[36m"
      # Set the terminal's foreground ANSI color to white.
      WHITE = "\e[37m"

      def initialize(source, destination, options = {})
        @options = options
        @source = source
        @destination = destination
        @command = build_command
      end

      def sync
        UI.info "Guard::RemoteSync `#{@command}`"
        run_command @command
      end

      def test
        $stderr.puts("\r\e[0m")
        $stderr.puts "#{BOLD}Testing rsync with a dry run and stats. Verifying the results...#{CLEAR}"
        opts = @options
        @options[:dry_run] = true
        @options[:stats] = true
        test_command = build_command
        @options = opts
        result = run_command test_command, {:suppress_output => false}
        $stderr.puts("\r\e[0m")
        result.to_i == 0
      end

      private

      def run_command(cmd, opts = {})
        options = {:color => CYAN, :suppress_output => false}.merge(opts)
        $stderr.puts "\r\e[0m" unless options[:suppress_output]
        exit_value = nil
        open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
          stdout.read.split("\n").each do |line|
            $stderr.puts "\t#{options[:color]}#{line}#{CLEAR}" unless options[:suppress_output]
          end
          stderr.read.split("\n").each do |line|
            $stderr.puts "\t#{BOLD}#{RED}ERROR:#{line}#{CLEAR}"
          end
          exit_value = wait_thr.value.to_s.split.last
        end
{'fraction_non_alphanumeric': 0.11868131868131868, 'fraction_numerical': 0.01098901098901099, 'mean_word_length': 2.1692200557103063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3081620', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1412, 'n_words': 403}