<commit_before>require "wraith"
require "wraith/helpers/logger"

class Wraith::FolderManager
  include Logging
  attr_reader :wraith

  def initialize(config)
    @wraith = Wraith::Wraith.new(config)
  end

  def dir
    wraith.directory
  end

  def history_dir
    wraith.history_dir
  end

  def paths
    wraith.paths
  end

  def spider_paths
    if !paths
      paths = File.read(wraith.spider_file)
      eval(paths)
    else
      wraith.paths
    end
  end

  def clear_shots_folder
    FileUtils.rm_rf("./#{dir}")
    FileUtils.mkdir_p("#{dir}")
  end

  def copy_old_shots
    if history_dir.nil?
      logger.error "no `history_dir` attribute found in config. Cannot copy files."
    else
      FileUtils.cp_r("#{dir}/.", "#{history_dir}/")
      FileUtils.rm_rf("#{history_dir}/thumbnails") # thumbnails aren't generated until the gallery stage anyway
      FileUtils.rm_rf("#{dir}") # get rid of the live folder
      Dir["#{history_dir}/**/*.png"].each do |filepath|
        new_name = filepath.gsub("latest.png", "base.png")
        File.rename(filepath, new_name)
      end
    end
  end

  def copy_base_images<commit_msg>Update folder.rb<commit_after>require "wraith"
require "wraith/helpers/logger"

class Wraith::FolderManager
  include Logging
  attr_reader :wraith

  def initialize(config)
    @wraith = Wraith::Wraith.new(config)
  end

  def dir
    wraith.directory
  end

  def history_dir
    wraith.history_dir
  end

  def paths
    wraith.paths
  end

  def spider_paths
    if !paths
      paths = File.read(wraith.spider_file)
      eval(paths)
    else
      wraith.paths
    end
  end

  def clear_shots_folder
    FileUtils.rm_rf("./#{dir}")
    FileUtils.mkdir_p("#{dir}")
  end

  def copy_old_shots
    if history_dir.nil?
      logger.error "no `history_dir` attribute found in config. Cannot copy files."
    else
      FileUtils.mkdir_p("#{history_dir}")
      FileUtils.cp_r("#{dir}/.", "#{history_dir}/")
      FileUtils.rm_rf("#{history_dir}/thumbnails") # thumbnails aren't generated until the gallery stage anyway
      FileUtils.rm_rf("#{dir}") # get rid of the live folder
      Dir["#{history_dir}/**/*.png"].each do |filepath|
        new_name = filepath.gsub("latest.png", "base.png")
        File.rename(filepath, new_name)
      end
    end
  end

  def copy_base_images
{'fraction_non_alphanumeric': 0.11397849462365592, 'fraction_numerical': 0.0, 'mean_word_length': 2.9897084048027445, 'pattern_counts': {'":': 0, '<': 3, '<?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': '617763', 'n_tokens_mistral': 823, 'n_tokens_neox': 812, 'n_words': 181}