<commit_before>require 'open3'
require 'fulmar/ringbuffer'

# This shell is part of the fulmar deployment tools
# it can be used stand-alone, though
module Fulmar
  # Implements simple access to shell commands
  class Shell
    VERSION = '1.8.0'

    attr_accessor :debug, :last_output, :last_error, :quiet, :strict, :interactive
    attr_reader :path

    DEFAULT_BUFFER_SIZE = 1000

    DEFAULT_OPTIONS = {
      login: false,
      escape_bundler: false
    }

    def initialize(path = '.', host = 'localhost')
      @host = host.nil? ? 'no_hostname_set' : host
      @path = (path.nil? || path.empty?) ? '.' : path
      @path = File.expand_path(@path) if local?
      reset_output
      @debug = false
      @quiet = true
      @strict = false
      @interactive = false
      @clean_environment = [] # list of things to clean from environment variables
    end

    def interactive=(interactive)
      @interactive = interactive
      @quiet = false if interactive
    end

    def run(command, options = DEFAULT_OPTIONS)
      reset_output(@last_output.max_size)
      command = [command] if command.class == String

      # is a custom path given?
      if options[:in]
        # is it absolute?
        path = options[:in][0, 1] == '/' ? options[:in] : "#{@path}/#{options[:in]}"
      else
        path = @path
      end

      options[:error_message] ||= 'Last shell command returned an error.'

      command.unshift "cd \"#{path}\""

      # invoke a login shell?
      shell_command = shell_command(options[:login])

      @clean_environment << 'bundler' if options[:escape_bundler]

      if local?
        execute("#{shell_command} '#{escape_for_sh(command.join(' && '))}'", options[:error_message])
      else
        remote_command = escape_for_sh("#{shell_command} '#{escape_for_sh(command.join(' && '))}'")
        execute("ssh #{@host} '#{remote_command}'", options[:error_message])
      end
    end

    def local?<commit_msg>Detect absolute paths via pathname<commit_after>require 'open3'
require 'pathname'
require 'fulmar/ringbuffer'

# This shell is part of the fulmar deployment tools
# it can be used stand-alone, though
module Fulmar
  # Implements simple access to shell commands
  class Shell
    VERSION = '1.8.0'

    attr_accessor :debug, :last_output, :last_error, :quiet, :strict, :interactive
    attr_reader :path

    DEFAULT_BUFFER_SIZE = 1000

    DEFAULT_OPTIONS = {
      login: false,
      escape_bundler: false
    }

    def initialize(path = '.', host = 'localhost')
      @host = host.nil? ? 'no_hostname_set' : host
      @path = (path.nil? || path.empty?) ? '.' : path
      @path = File.expand_path(@path) if local?
      reset_output
      @debug = false
      @quiet = true
      @strict = false
      @interactive = false
      @clean_environment = [] # list of things to clean from environment variables
    end

    def interactive=(interactive)
      @interactive = interactive
      @quiet = false if interactive
    end

    def run(command, options = DEFAULT_OPTIONS)
      reset_output(@last_output.max_size)
      command = [command] if command.class == String

      # is a custom path given?
      if options[:in]
        # is it absolute?
        (Pathname.new options[:in]).absolute? ? options[:in] : "#{@path}/#{options[:in]}"
      else
        path = @path
      end

      options[:error_message] ||= 'Last shell command returned an error.'

      command.unshift "cd \"#{path}\""

      # invoke a login shell?
      shell_command = shell_command(options[:login])

      @clean_environment << 'bundler' if options[:escape_bundler]

      if local?
        execute("#{shell_command} '#{escape_for_sh(command.join(' && '))}'", options[:error_message])
      else
        remote_command = escape_for_sh("#{shell_command} '#{escape_for_sh(command.join(' && '))}'")
        execute("ssh #{@host} '#{remote_command}'", options[:error_message])
      end
    end

    def local?
{'fraction_non_alphanumeric': 0.1267427122940431, 'fraction_numerical': 0.0045627376425855515, 'mean_word_length': 2.891518737672584, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3581611', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1167, 'n_words': 318}