<commit_before>require 'thread'
require 'open3'
require 'yaml'
require 'peach'
require 'bundler'

STDOUT.sync = true
STDERR.sync = true

module Cast
  VERSION = '0.1.7'
  DEFAULTGROUPS = '~/.cast.yml'

  @@mux = Mutex.new
  @@pids = []
  @@groups = nil

  def self.log msg, source = 'cast', stream = $stdout
    @@mux.synchronize do
      prefix = "[#{source}] " unless source == nil
      stream.puts "#{prefix}#{msg}"
    end
  end

  def self.load_groups groupfile
    file = File.expand_path groupfile
    exists = File.exists? file
    @@groups ||= {}

    if !exists
      raise "could not find #{groupfile}" if groupfile != DEFAULTGROUPS
      log "no group file found at #{groupfile}"
    else
      log "loading groups from #{groupfile}"
      @@groups = YAML.load_file file
    end

    return @@groups
  end

  def self.expand_groups cmdgroups, groups = @@groups
    hosts = []
    cmdgroups.each do |group|
      if groups.include? group
        hosts += groups[group]
      else
        hosts << group
      end
    end

    return hosts.uniq
  end

  def self.run hosts, cmd, serial = false, delay = nil, ssh = 'ssh', strict = false
    success = true
    if serial or delay
      hosts.each_with_index do |host, i|
        exitCode = remote host, cmd, ssh
        if strict
          success &= (exitCode == 0)
        end
        if delay and i < hosts.size - 1
          log "delay for #{delay} seconds"<commit_msg>Changed from bitwise to logical and<commit_after>require 'thread'
require 'open3'
require 'yaml'
require 'peach'
require 'bundler'

STDOUT.sync = true
STDERR.sync = true

module Cast
  VERSION = '0.1.7'
  DEFAULTGROUPS = '~/.cast.yml'

  @@mux = Mutex.new
  @@pids = []
  @@groups = nil

  def self.log msg, source = 'cast', stream = $stdout
    @@mux.synchronize do
      prefix = "[#{source}] " unless source == nil
      stream.puts "#{prefix}#{msg}"
    end
  end

  def self.load_groups groupfile
    file = File.expand_path groupfile
    exists = File.exists? file
    @@groups ||= {}

    if !exists
      raise "could not find #{groupfile}" if groupfile != DEFAULTGROUPS
      log "no group file found at #{groupfile}"
    else
      log "loading groups from #{groupfile}"
      @@groups = YAML.load_file file
    end

    return @@groups
  end

  def self.expand_groups cmdgroups, groups = @@groups
    hosts = []
    cmdgroups.each do |group|
      if groups.include? group
        hosts += groups[group]
      else
        hosts << group
      end
    end

    return hosts.uniq
  end

  def self.run hosts, cmd, serial = false, delay = nil, ssh = 'ssh', strict = false
    success = true
    if serial or delay
      hosts.each_with_index do |host, i|
        exitCode = remote host, cmd, ssh
        if strict
          success &&= (exitCode == 0)
        end
        if delay and i < hosts.size - 1
          log "delay for #{delay} seconds"
{'fraction_non_alphanumeric': 0.11257360581918947, 'fraction_numerical': 0.004156563907170073, 'mean_word_length': 2.358139534883721, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6361674', 'n_tokens_mistral': 942, 'n_tokens_neox': 897, 'n_words': 302}