<commit_before>#TODO: this is in midst of converting from old form to new form
require 'singleton'
module DTK
  class Configuration
    include Singleton
    def set_configuration(config_file_location=nil)
      config_file_location ||= default_config_file_location() 
      set_defaults()
      load_config_file(config_file_location)
      set_combined_vars()
      validate()
      finalize()
    end

    private
    def default_config_file_location()
      user_specific_config = "#{BaseConfigDir}/#{process_user()}/server.conf"
      File.file?(user_specific_config) ? user_specific_config : "#{BaseConfigDir}/server.conf"
    end
    BaseConfigDir = "/etc/dtk"

    def process_user()
      ENV["USER"]||ENV["USERNAME"] #TODO: may instead look at the Process fns
    end

    def set_defaults()
      r8_nested_require('configuration','defaults')
      R8::Config[:dtk_instance_user] = process_user()
    end
    
    def set_combined_vars()
      r8_nested_require('configuration','combined')
    end

    def load_config_file(config_file_location)
      parsed_file = ParsedFile.new(config_file_location)
      parsed_file.each do |key,value|
        update_config_value!(key,value)
      end
    end

    def update_config_value!(config_file_key,value)
      internal_key = (Mappings[config_file_key]||config_file_key).split(".")
      update_config_value_aux!(R8::Config,internal_key,value)
    end

    Mappings = {
      "remote_repo.host" => "repo.remote.host",
      "local_repo.host" => "repo.git.dns",
      "db.host" => "database.hostname",<commit_msg>using process info to get userid<commit_after>#TODO: this is in midst of converting from old form to new form
require 'singleton'
require 'etc'
module DTK
  class Configuration
    include Singleton
    def set_configuration(config_file_location=nil)
      config_file_location ||= default_config_file_location() 
      set_defaults()
      load_config_file(config_file_location)
      set_combined_vars()
      validate()
      finalize()
    end

    private
    def default_config_file_location()
      user_specific_config = "#{BaseConfigDir}/#{process_user()}/server.conf"
      File.file?(user_specific_config) ? user_specific_config : "#{BaseConfigDir}/server.conf"
    end
    BaseConfigDir = "/etc/dtk"

    def process_user()
      Etc.getpwuid(Process.uid).name
    end

    def set_defaults()
      r8_nested_require('configuration','defaults')
      R8::Config[:dtk_instance_user] = process_user()
    end
    
    def set_combined_vars()
      r8_nested_require('configuration','combined')
    end

    def load_config_file(config_file_location)
      parsed_file = ParsedFile.new(config_file_location)
      parsed_file.each do |key,value|
        update_config_value!(key,value)
      end
    end

    def update_config_value!(config_file_key,value)
      internal_key = (Mappings[config_file_key]||config_file_key).split(".")
      update_config_value_aux!(R8::Config,internal_key,value)
    end

    Mappings = {
      "remote_repo.host" => "repo.remote.host",
      "local_repo.host" => "repo.git.dns",
      "db.host" => "database.hostname",
{'fraction_non_alphanumeric': 0.10575079872204472, 'fraction_numerical': 0.0025559105431309905, 'mean_word_length': 3.680119581464873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1533481', 'n_tokens_mistral': 995, 'n_tokens_neox': 987, 'n_words': 172}