<commit_before>require 'json'
require 'tempfile'

::Capistrano::Configuration.instance(:must_exist).load do

  namespace :roundsman do

    def run_list(*recipes)
      if recipes.any?
        set :run_list, recipes
        install_ruby if fetch(:run_roundsman_checks, true) && install_ruby?
        run_chef
      else
        Array(fetch(:run_list))
      end
    end

    def set_default(name, *args, &block)
      @_defaults ||= []
      @_overridden_defaults ||= []
      @_defaults << name
      if exists?(name)
        @_overridden_defaults << name
      else
        set(name, *args, &block)
      end
    end

    def roundsman_working_dir(*path)
      ensure_roundsman_working_dir
      File.join(fetch(:roundsman_working_dir), *path)
    end

    def sudo(command, *args)
      run "#{top.sudo} #{command}", *args
    end

    def run(*args)
      if fetch(:stream_roundsman_output)
        top.stream *args
      else
        top.run *args
      end
    end

    set_default :roundsman_working_dir, "/tmp/roundsman"
    set_default :stream_roundsman_output, true
    set_default(:roundsman_user) { fetch(:user) { capture('whoami').strip } }
    set_default :debug_chef, false
    set_default :package_manager, 'apt-get'
    set_default :run_roundsman_checks, true

    desc "Lists configuration"
    task :configuration do
      @_defaults.sort_by {|sym| sym.to_s}.each do |name|
        display_name = ":#{name},".ljust(30)
        if variables[name].is_a?(Proc)
          value = "<block>"
        else
          value = fetch(name).inspect
          value = "#{value[0..40]}... (truncated)" if value.length > 40
        end
        overridden = @_overridden_defaults.include?(name) ? "(overridden)" : ""
        puts "set #{display_name} #{value} #{overridden}"
      end
    end

    desc "Prepares the server for chef"
    task :install_ruby do
      install.default
    end

    desc "Runs chef"
    task :run_chef do
      chef.default
    end

    def ensure_roundsman_working_dir
      run "mkdir -p #{fetch(:roundsman_working_dir)}"
      run "mkdir -p #{fetch(:roundsman_working_dir)}/cache"
      sudo "chown -R #{fetch(:roundsman_user)} #{fetch(:roundsman_working_dir)}"
    end

    def install_ruby?
      installed_version = capture("ruby --version || true").strip
      if installed_version.include?("not found")
        logger.info "No version of Ruby could be found."
        return true
      end
      required_version = fetch(:ruby_version).gsub("-", "")
      if installed_version.include?(required_version)
        if fetch(:care_about_ruby_version)
          logger.info "Ruby #{installed_version} matches the required version: #{required_version}."
          return false
        else
          logger.info "Already installed Ruby #{installed_version}, not #{required_version}. Set :care_about_ruby_version if you want to fix this."
          return false
        end
      else
        logger.info "Ruby version mismatch. Installed version: #{installed_version}, required is #{required_version}"
        return true
      end
    end

<commit_msg>change how care_about_ruby version works, fixes issue #19<commit_after>require 'json'
require 'tempfile'

::Capistrano::Configuration.instance(:must_exist).load do

  namespace :roundsman do

    def run_list(*recipes)
      if recipes.any?
        set :run_list, recipes
        install_ruby if fetch(:run_roundsman_checks, true) && install_ruby?
        run_chef
      else
        Array(fetch(:run_list))
      end
    end

    def set_default(name, *args, &block)
      @_defaults ||= []
      @_overridden_defaults ||= []
      @_defaults << name
      if exists?(name)
        @_overridden_defaults << name
      else
        set(name, *args, &block)
      end
    end

    def roundsman_working_dir(*path)
      ensure_roundsman_working_dir
      File.join(fetch(:roundsman_working_dir), *path)
    end

    def sudo(command, *args)
      run "#{top.sudo} #{command}", *args
    end

    def run(*args)
      if fetch(:stream_roundsman_output)
        top.stream *args
      else
        top.run *args
      end
    end

    set_default :roundsman_working_dir, "/tmp/roundsman"
    set_default :stream_roundsman_output, true
    set_default(:roundsman_user) { fetch(:user) { capture('whoami').strip } }
    set_default :debug_chef, false
    set_default :package_manager, 'apt-get'
    set_default :run_roundsman_checks, true

    desc "Lists configuration"
    task :configuration do
      @_defaults.sort_by {|sym| sym.to_s}.each do |name|
        display_name = ":#{name},".ljust(30)
        if variables[name].is_a?(Proc)
          value = "<block>"
        else
          value = fetch(name).inspect
          value = "#{value[0..40]}... (truncated)" if value.length > 40
        end
        overridden = @_overridden_defaults.include?(name) ? "(overridden)" : ""
        puts "set #{display_name} #{value} #{overridden}"
      end
    end

    desc "Prepares the server for chef"
    task :install_ruby do
      install.default
    end

    desc "Runs chef"
    task :run_chef do
      chef.default
    end

    def ensure_roundsman_working_dir
      run "mkdir -p #{fetch(:roundsman_working_dir)}"
      run "mkdir -p #{fetch(:roundsman_working_dir)}/cache"
      sudo "chown -R #{fetch(:roundsman_user)} #{fetch(:roundsman_working_dir)}"
    end

    def install_ruby?
      installed_version = capture("ruby --version || true").strip
      if installed_version.include?("not found")
        logger.info "No version of Ruby could be found."
        return true
      end
      required_version = fetch(:ruby_version).gsub("-", "")
      if fetch(:care_about_ruby_version)
        if installed_version.include?(required_version)
          logger.info "Ruby #{installed_version} matches the required version: #{required_version}."
          return false
        else
          logger.info "Ruby version mismatch. Installed version: #{installed_version}, required is #{required_version}"
          return true
        end
      else
        logger.info "Already installed Ruby #{installed_version}, not #{required_version}. Set :care_about_ruby_version if you want to fix this."
        return false
      end
    end


{'fraction_non_alphanumeric': 0.10871662914120296, 'fraction_numerical': 0.002573174654229656, 'mean_word_length': 2.6711924439197166, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 7, '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': '939897', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1856, 'n_words': 465}