<commit_before>module Rake
  WHOAMI = `whoami`.strip

  class ProcessStatusLine < Struct.new(:uid, :pid, :ppid, :c, :stime, :tty, :time, :cmd)
    def namespace_equal? namespace
      self.cmd.split.select {|i| i.match(/:/) }[0] == namespace
    end

    def working_dir_equal? working_dir
      !!(`lsof -p #{self.pid} | grep cwd | grep DIR`.split[-1].match(working_dir))
    end
  end

  def self.ensure_only_one_task_is_running name, working_dir
    process_status_lines = `ps -u #{WHOAMI} -ef | grep rake | grep -v '/bash ' | grep -v 'grep rake'`.split("\n").map {|line| ProcessStatusLine.new *line.split(" ", 8) }
    Process.exit! 0 if process_status_lines.select {|process_status_line| process_status_line.namespace_equal?(name) && process_status_line.working_dir_equal?(working_dir) }.size > 1
  end

  module DSL
    private
    def only_one_task(*args, &block)
      task = Rake::Task.define_task(*args, &block)
      task.is_only_one_task = true
      task
    end
  end

  class Task
    attr_accessor :is_only_one_task
    attr_accessor :working_dir

    # Execute the actions associated with this task.
    def execute(args=nil)
      args ||= EMPTY_TASK_ARGS
      if application.options.dryrun<commit_msg>Fix output of `lsof` is nothing<commit_after>module Rake
  WHOAMI = `whoami`.strip

  class ProcessStatusLine < Struct.new(:uid, :pid, :ppid, :c, :stime, :tty, :time, :cmd)
    def namespace_equal? namespace
      self.cmd.split.select {|i| i.match(/:/) }[0] == namespace
    end

    def working_dir_equal? working_dir
      !!(`lsof -p #{self.pid} | grep cwd | grep DIR`.split[-1].to_s.match(working_dir))
    end
  end

  def self.ensure_only_one_task_is_running name, working_dir
    process_status_lines = `ps -u #{WHOAMI} -ef | grep rake | grep -v '/bash ' | grep -v 'grep rake'`.split("\n").map {|line| ProcessStatusLine.new *line.split(" ", 8) }
    Process.exit! 0 if process_status_lines.select {|process_status_line| process_status_line.namespace_equal?(name) && process_status_line.working_dir_equal?(working_dir) }.size > 1
  end

  module DSL
    private
    def only_one_task(*args, &block)
      task = Rake::Task.define_task(*args, &block)
      task.is_only_one_task = true
      task
    end
  end

  class Task
    attr_accessor :is_only_one_task
    attr_accessor :working_dir

    # Execute the actions associated with this task.
    def execute(args=nil)
      args ||= EMPTY_TASK_ARGS
      if application.options.dryrun
{'fraction_non_alphanumeric': 0.12373225152129817, 'fraction_numerical': 0.004056795131845842, 'mean_word_length': 3.5582255083179297, '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': '3058153', 'n_tokens_mistral': 898, 'n_tokens_neox': 861, 'n_words': 204}