<commit_before>require 'yaml'

def get_env_value(string)
  string.split("=")[1].gsub("\"", "")
end


unless ARGV.length == 1
  puts "Incorrect number of arguments."
  exit
end

yml_file = ARGV[0]

unless yml_file.end_with? ".yml"
  puts "This script expects a YML file."
  exit
end

config = YAML.load_file(yml_file)

output = Hash.new

if config.has_key?("baseline")
  output["baseline"] = config["baseline"]
end

field_prefix = "smalltalk_"
allowed_fields = ["baseline", "baseline_group", "packages", "force_update",
          "run_script", "exclude_categories", "exclude_classes",
          "builderci", "tests"]

# TODO: Implement specification https://github.com/hpi-swa/smalltalkCI/issues/20
# allowed_fields.each { |field|
#   field_name = "#{field_prefix}#{field}"
#   if config.has_key?(field_name)
#     output[field] = config[field_name]
#   end
# }

if config.has_key?("env") and config["env"].has_key?("global")
  config["env"]["global"].each { |value|
    allowed_fields.each { |field|
      next if output.include? field
      if value.start_with?("#{field.upcase}=")
        output[field] = get_env_value(value)
      end
    }
  }
end

# Use first smalltalk value if $SMALLTALK is not set
if config.has_key?("smalltalk")
  puts "[[ -z \"'${config_smalltalk}'\" ]] && "\
       "config_smalltalk=(\"#{config["smalltalk"].first}\")"
end

# Print output
output.each { |key, value|
  puts "config_#{key}=(\"#{value}\")"
}<commit_msg>Apply different compatibility hotfix<commit_after>require 'yaml'

def get_env_value(string)
  string.split("=")[1].gsub("\"", "")
end


unless ARGV.length == 1
  puts "Incorrect number of arguments."
  exit
end

yml_file = ARGV[0]

unless yml_file.end_with? ".yml"
  puts "This script expects a YML file."
  exit
end

config = YAML.load_file(yml_file)

output = Hash.new

if config.has_key?("baseline")
  output["baseline"] = config["baseline"]
end

field_prefix = "smalltalk_"
allowed_fields = ["baseline", "baseline_group", "packages", "force_update",
          "run_script", "exclude_categories", "exclude_classes",
          "builderci", "tests"]

# TODO: Implement specification https://github.com/hpi-swa/smalltalkCI/issues/20
# allowed_fields.each { |field|
#   field_name = "#{field_prefix}#{field}"
#   if config.has_key?(field_name)
#     output[field] = config[field_name]
#   end
# }

if config.has_key?("env") and config["env"].has_key?("global")
  config["env"]["global"].each { |value|
    allowed_fields.each { |field|
      next if output.include? field
      if value.start_with?("#{field.upcase}=")
        output[field] = get_env_value(value)
      end
    }
  }
end

# Use first smalltalk value if $SMALLTALK is not set
if !ENV.has_key?("SMALLTALK") and config.has_key?("smalltalk")
  puts "config_smalltalk=(\"#{config["smalltalk"].first}\")"
end

# Print output
output.each { |key, value|
  puts "config_#{key}=(\"#{value}\")"
}
{'fraction_non_alphanumeric': 0.17052122885743873, 'fraction_numerical': 0.0034518467380048328, 'mean_word_length': 4.288321167883212, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3547905', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1030, 'n_words': 213}