<commit_before>#!/usr/bin/python3
#
# Copyright (C) 2017 Dell, Inc.
# Copyright (C) 2020 Intel, Inc.
#
# SPDX-License-Identifier: LGPL-2.1+
#
import os
import sys
import argparse
import xml.etree.ElementTree as etree


def parse_dependencies(OS, SUBOS, requested_type):
    deps = []
    dep = ""
    directory = os.path.dirname(sys.argv[0])
    tree = etree.parse(os.path.join(directory, "dependencies.xml"))
    root = tree.getroot()
    for child in root:
        if "type" not in child.attrib or "id" not in child.attrib:
            continue
        for distro in child:
            if "id" not in distro.attrib:
                continue
            if distro.attrib["id"] != OS:
                continue
            packages = distro.findall("package")
            for package in packages:
                if SUBOS:
                    if "variant" not in package.attrib:
                        continue
                    if package.attrib["variant"] != SUBOS:
                        continue
                if package.text:
                    dep = package.text
                else:
                    dep = child.attrib["id"]
                if child.attrib["type"] == requested_type and dep:
                    deps.append(dep)
    return deps


if __name__ == "__main__":

    try:
        import distro

        target = distro.linux_distribution()[0]
    except ModuleNotFoundError:
        target = None

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-o",
        "--os",
        default=target,
        choices=["fedora", "centos", "flatpak", "debian", "ubuntu", "arch"],
        help="dependencies for OS",
    )
    args = parser.parse_args()<commit_msg>trivial: generate_dependencies: use distro.id() to better find defaults<commit_after>#!/usr/bin/python3
#
# Copyright (C) 2017 Dell, Inc.
# Copyright (C) 2020 Intel, Inc.
#
# SPDX-License-Identifier: LGPL-2.1+
#
import os
import sys
import argparse
import xml.etree.ElementTree as etree


def parse_dependencies(OS, SUBOS, requested_type):
    deps = []
    dep = ""
    directory = os.path.dirname(sys.argv[0])
    tree = etree.parse(os.path.join(directory, "dependencies.xml"))
    root = tree.getroot()
    for child in root:
        if "type" not in child.attrib or "id" not in child.attrib:
            continue
        for distro in child:
            if "id" not in distro.attrib:
                continue
            if distro.attrib["id"] != OS:
                continue
            packages = distro.findall("package")
            for package in packages:
                if SUBOS:
                    if "variant" not in package.attrib:
                        continue
                    if package.attrib["variant"] != SUBOS:
                        continue
                if package.text:
                    dep = package.text
                else:
                    dep = child.attrib["id"]
                if child.attrib["type"] == requested_type and dep:
                    deps.append(dep)
    return deps


if __name__ == "__main__":

    try:
        import distro

        target = distro.id()
    except ModuleNotFoundError:
        target = None

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-o",
        "--os",
        default=target,
        choices=["fedora", "centos", "flatpak", "debian", "ubuntu", "arch"],
        help="dependencies for OS",
    )
    args = parser.parse_args()
{'fraction_non_alphanumeric': 0.11040278180237613, 'fraction_numerical': 0.007244277021153289, 'mean_word_length': 1.711704634721131, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6796801', 'n_tokens_mistral': 1033, 'n_tokens_neox': 965, 'n_words': 260}