<commit_before>require 'fileutils'
require_relative 'config'

CONFIG_DIRECTORIES = [
  'logfile_directory',
  'pidfile_directory',
  'moneta_directory',
  'job_directory',
  'workspace_directory'
]

# config = configatron.to_h
#   config = config.each do |key, value|
#     config[key] = File.expand_path value if key.to_s.match /_directory/
#   end

def set_dir_permissions(on_directory:)
  user = configatron.user
  group = configatron.has_key?(:group) ? configatron.group : 'nogroup'
  begin
    FileUtils.chown_R user, group, on_directory unless user.nil?
  rescue ArgumentError
    puts "Could not set permissions for '#{on_directory}'"
  end
end

CONFIG_DIRECTORIES.each do |directory|
  directory = File.expand_path configatron[directory]
  begin
    FileUtils.mkdir_p directory
  rescue Errno::EACCES
    puts "Permission denied to create '#{directory}'"
  end
  set_dir_permissions on_directory: directory if configatron.has_key? :user
end
<commit_msg>Staying with convention of using '_directory' to find config dirs<commit_after>require 'fileutils'
require_relative 'config'

def set_dir_permissions(for_path:)
  user = configatron.user
  group = configatron.has_key?(:group) ? configatron.group : 'nogroup'
  begin
    FileUtils.chown_R user, group, for_path unless user.nil?
  rescue ArgumentError
    puts "Could not set permissions for '#{for_path}'"
  end
end

def create_path(path)
  begin
    FileUtils.mkdir_p path
  rescue Errno::EACCES
    puts "Permission denied to create '#{path}'"
  end
end

config = configatron.to_h
config.each do |key, value|
  if key.to_s.match /_directory/
    path = File.expand_path value
    create_path path
    set_dir_permissions for_path: path if configatron.has_key? :user
  end
end

{'fraction_non_alphanumeric': 0.0903337169159954, 'fraction_numerical': 0.0, 'mean_word_length': 4.573717948717949, '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': '3005772', 'n_tokens_mistral': 584, 'n_tokens_neox': 588, 'n_words': 151}