<commit_before>module Sprinkle
  module Installers
    # The Binary installer will download a binary archive and then extract
    # it in the directory specified by the prefix option.
    # 
    # == Example Usage
    #
    #  binary "http://some.url.com/archive.tar.gz" do
    #    prefix   "/home/user/local"
    #    archives "/home/user/sources"
    #  end 
    # 
    # This example will download archive.tar.gz to /home/user/sources and then
    # extract it into /home/user/local.
    class Binary < Installer
      
      api do
        def binary(source, options = {}, &block)
          install Binary.new(self, source, options, &block)
        end
      end
      
      def initialize(parent, binary_archive, options = {}, &block) #:nodoc:
        @binary_archive = binary_archive
        super parent, options, &block
      end

      def prepare_commands #:nodoc:
        raise 'No installation area defined' unless @options[:prefix]
        raise 'No archive download area defined' unless @options[:archives]

        [ "mkdir -p #{@options[:prefix]}",
          "mkdir -p #{@options[:archives]}" ]
      end

      def install_commands #:nodoc:
        commands = [ "bash -c 'wget -cq --directory-prefix=#{@options[:archives]} #{@binary_archive}'" ]
        commands << "bash -c \"cd #{@options[:prefix]} && #{extract_command} '#{@options[:archives]}/#{archive_name}'\""
      end

      def archive_name #:nodoc:
        @archive_name ||= @binary_archive.split("/").last.gsub('%20', ' ')
      end

      def extract_command #:nodoc:
        case archive_name
        when /(tar.gz)|(tgz)$/
          'tar xzf'
        when /(tar.bz2)|(tb2)$/
          'tar xjf'
        when /tar$/
          'tar xf'
        when /zip$/
          'unzip -o'
        else
          raise "Unknown binary archive format: #{archive_name}"
        end
      end
    end
  end
end
<commit_msg>sudo the extraction operation (binary install) when asked to<commit_after>module Sprinkle
  module Installers
    # The Binary installer will download a binary archive and then extract
    # it in the directory specified by the prefix option.
    # 
    # == Example Usage
    #
    #  binary "http://some.url.com/archive.tar.gz" do
    #    prefix   "/home/user/local"
    #    archives "/home/user/sources"
    #  end 
    # 
    # This example will download archive.tar.gz to /home/user/sources and then
    # extract it into /home/user/local.
    class Binary < Installer

      api do
        def binary(source, options = {}, &block)
          install Binary.new(self, source, options, &block)
        end
      end

      def initialize(parent, binary_archive, options = {}, &block) #:nodoc:
        @binary_archive = binary_archive
        super parent, options, &block
      end

      def prepare_commands #:nodoc:
        raise 'No installation area defined' unless @options[:prefix]
        raise 'No archive download area defined' unless @options[:archives]

        [ "mkdir -p #{@options[:prefix]}",
          "mkdir -p #{@options[:archives]}" ]
      end

      def install_commands #:nodoc:
        commands = [ "bash -c 'wget -cq --directory-prefix=#{@options[:archives]} #{@binary_archive}'" ]
        commands << "bash -c \"cd #{@options[:prefix]} && #{sudo_cmd} #{extract_command} '#{@options[:archives]}/#{archive_name}'\""
      end

      def archive_name #:nodoc:
        @archive_name ||= @binary_archive.split("/").last.gsub('%20', ' ')
      end

      def extract_command #:nodoc:
        case archive_name
        when /(tar.gz)|(tgz)$/
          'tar xzf'
        when /(tar.bz2)|(tb2)$/
          'tar xjf'
        when /tar$/
          'tar xf'
        when /zip$/
          'unzip -o'
        else
          raise "Unknown binary archive format: #{archive_name}"
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.12941176470588237, 'fraction_numerical': 0.0020915032679738564, 'mean_word_length': 2.1567656765676566, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5504858', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1133, 'n_words': 325}