<commit_before>"""
Utility code for supporting earlier Rez data in later Rez releases.
"""
from rez.config import config
from rez.utils.logging_ import print_debug
import re
import os


variant_key_conversions = {
    "name":         "name",
    "version":      "version",
    "index":        "index",
    "ext":          "ext",
    "search_path":  "location"
}


def convert_old_variant_handle(handle_dict):
    """Convert a variant handle from serialize_version < 4.0."""
    old_variables = handle_dict.get("variables", {})
    variables = dict(repository_type="filesystem")

    for old_key, key in variant_key_conversions.iteritems():
        value = old_variables.get(old_key)
        if value is not None:
            variables[key] = value

    key = "filesystem.variant"
    return dict(key=key, variables=variables)


def convert_old_command_expansions(command):
    """Convert expansions from !OLD! style to {new}."""
    command = command.replace("!VERSION!",       "{version}")
    command = command.replace("!MAJOR_VERSION!", "{version.major}")
    command = command.replace("!MINOR_VERSION!", "{version.minor}")
    command = command.replace("!BASE!",          "{base}")
    command = command.replace("!ROOT!",          "{root}")
    command = command.replace("!USER!",          "{system.user}")
    return command


def convert_old_commands(commands, annotate=True):
    """Converts old-style package commands into equivalent Rex code."""
    from rez.config import config<commit_msg>-added backwards compatibility for combined pkg resource variants<commit_after>"""
Utility code for supporting earlier Rez data in later Rez releases.
"""
from rez.config import config
from rez.utils.logging_ import print_debug
import re
import os
import os.path


variant_key_conversions = {
    "name":         "name",
    "version":      "version",
    "index":        "index",
    "ext":          "ext",
    "search_path":  "location"
}


def convert_old_variant_handle(handle_dict):
    """Convert a variant handle from serialize_version < 4.0."""
    old_variables = handle_dict.get("variables", {})
    variables = dict(repository_type="filesystem")

    for old_key, key in variant_key_conversions.iteritems():
        value = old_variables.get(old_key)
        if value is not None:
            variables[key] = value

    path = handle_dict["path"]
    filename = os.path.basename(path)
    if os.path.splitext(filename)[0] == "package":
        key = "filesystem.variant"
    else:
        key = "filesystem.variant.combined"

    return dict(key=key, variables=variables)


def convert_old_command_expansions(command):
    """Convert expansions from !OLD! style to {new}."""
    command = command.replace("!VERSION!",       "{version}")
    command = command.replace("!MAJOR_VERSION!", "{version.major}")
    command = command.replace("!MINOR_VERSION!", "{version.minor}")
    command = command.replace("!BASE!",          "{base}")
    command = command.replace("!ROOT!",          "{root}")
    command = command.replace("!USER!",          "{system.user}")
    return command


def convert_old_commands(commands, annotate=True):
    """Converts old-style package commands into equivalent Rex code."""
    from rez.config import config
{'fraction_non_alphanumeric': 0.13401109057301294, 'fraction_numerical': 0.0015403573629081946, 'mean_word_length': 3.441860465116279, 'pattern_counts': {'":': 11, '<': 5, '<?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': '6409541', 'n_tokens_mistral': 948, 'n_tokens_neox': 945, 'n_words': 240}