<commit_before>$:.push '/home/ebrodeur/Projects/bin_snippets/lib'

# Some requires, they don't fit elsewhere.
require 'yajl'
require 'sys/proctable'
module ErnieBrodeur

  class Application
    attr_accessor :version
    attr_accessor :banner
    attr_accessor :long_description
    attr_accessor :plugins

    # return the name of the app, for now this is just the cmd ran, later it will be
    # something generated but more unique.
    def name
      $0.split("/").last
    end

    def cache_dir
      "#{Dir.home}/.cache/erniebrodeur/#{App.name}/"
    end

    def config_dir
      "#{Dir.home}/.config/erniebrodeur/#{App.name}/"
    end

    def pids
      a = Sys::ProcTable.ps.select{|x| x.cmdline =~ /.*#{App.name}.*-[dD].*/}.map {|x| x.pid}
      a.delete $$
      return a if a.any?
      nil
    end

    def initialize
      @version = '0.0.0'
      @banner  = 'A bin snippet by <NAME> that does . . . something.'
      @long_description = ''
      @plugins = []
    end

    def daemonize(*params, &block)
      if params[0] && !params[0][:multiple_pids] && pids
        puts "#{App.name} appears to be running (#{pids}), only one allowed, exiting."
        exit
      end
      puts "Forking to background."

      Process.daemon
      block.call
    end

    def kill_daemon
      if !pids
        puts "No pids found, exiting."
        exit
      end

      pids.each do |p|
        puts "Killing #{p}"
        %x[kill -TERM #{p}]
      end
    end
  end

  App = Application.new

  # This will load a helper, if it exists.
  f = "#{$:.last}/helpers/#{App.name}.rb"
  require f if File.exist? f
end<commit_msg>Added App#puts_or_log to decide if it should puts or use Log.level. Updated the few puts left in app.rb<commit_after>$:.push '/home/ebrodeur/Projects/bin_snippets/lib'

# Some requires, they don't fit elsewhere.
require 'yajl'
require 'sys/proctable'
module ErnieBrodeur

  class Application
    attr_accessor :version
    attr_accessor :banner
    attr_accessor :long_description
    attr_accessor :plugins

    # return the name of the app, for now this is just the cmd ran, later it will be
    # something generated but more unique.
    def name
      $0.split("/").last
    end

    def cache_dir
      "#{Dir.home}/.cache/erniebrodeur/#{App.name}/"
    end

    def config_dir
      "#{Dir.home}/.config/erniebrodeur/#{App.name}/"
    end

    def pids
      a = Sys::ProcTable.ps.select{|x| x.cmdline =~ /.*#{App.name}.*-[dD].*/}.map {|x| x.pid}
      a.delete $$
      return a if a.any?
      nil
    end

    def initialize
      @version = '0.0.0'
      @banner  = 'A bin snippet by <NAME> that does . . . something.'
      @long_description = ''
      @plugins = []
    end

    def daemonize(*params, &block)
      if params[0] && !params[0][:multiple_pids] && pids
        puts_or_log :info, "#{App.name} appears to be running (#{pids}), only one allowed, exiting."
        exit
      end
      puts_or_log :info, "Forking to background."

      Process.daemon
      block.call
    end

    def kill_daemon
      if !pids
        puts_or_log :fatal, "No pids found, exiting."
      end

      pids.each do |p|
        puts_or_log :info, "Killing #{p}"
        %x[kill -TERM #{p}]
      end
    end
    private
    def puts_or_log(l, s)
      if App.plugins.include? 'logging'
        Log.send l, s
      else
        puts s
        exit if l.to_sym == :fatal
      end
    end
  end

  App = Application.new

  # This will load a helper, if it exists.
  f = "#{$:.last}/helpers/#{App.name}.rb"
  require f if File.exist? f
end
{'fraction_non_alphanumeric': 0.1250350434538828, 'fraction_numerical': 0.00336417157275021, 'mean_word_length': 2.1857142857142855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2514972', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1228, 'n_words': 354}