<commit_before>#!/usr/bin/env python
#
# Microsoft Azure Linux Agent setup.py
#
# Copyright 2013 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import subprocess
import sys

import setuptools
from setuptools import find_packages
from setuptools.command.install import install as _install

from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.version import AGENT_NAME, AGENT_VERSION, \
    AGENT_DESCRIPTION, \
    DISTRO_NAME, DISTRO_VERSION, DISTRO_FULL_NAME

root_dir = os.path.dirname(os.path.abspath(__file__))  # pylint: disable=invalid-name
os.chdir(root_dir)


def set_files(data_files, dest=None, src=None):
    data_files.append((dest, src))


def set_bin_files(data_files, dest, src=None):
    if src is None:
        src = ["bin/waagent", "bin/waagent2.0"]
    data_files.append((dest, src))


def set_conf_files(data_files, dest="/etc", src=None):
    if src is None:
        src = ["config/waagent.conf"]
    data_files.append((dest, src))


def set_logrotate_files(data_files, dest="/etc/logrotate.d", src=None):
    if src is None:
        src = ["config/waagent.logrotate"]
    data_files.append((dest, src))


def set_sysv_files(data_files, dest="/etc/rc.d/init.d", src=None):
    if src is None:
        src = ["init/waagent"]
    data_files.append((dest, src))


def set_systemd_files(data_files, dest, src=None):
    if src is None:
        src = ["init/waagent.service"]
    data_files.append((dest, src))


def set_freebsd_rc_files(data_files, dest="/etc/rc.d/", src=None):
    if src is None:
        src = ["init/freebsd/waagent"]
    data_files.append((dest, src))


def set_openbsd_rc_files(data_files, dest="/etc/rc.d/", src=None):
    if src is None:
        src = ["init/openbsd/waagent"]
    data_files.append((dest, src))


def set_udev_files(data_files, dest="/etc/udev/rules.d/", src=None):
    if src is None:
        src = ["config/66-azure-storage.rules",
               "config/99-azure-product-uuid.rules"]
    data_files.append((dest, src))


def get_data_files(name, version, fullname):  # pylint: disable=R0912
    """
    Determine data_files according to distro name, version and init system type
    """
    data_files = []
    osutil = get_osutil()
    systemd_dir_path = osutil.get_systemd_unit_file_install_path()
    agent_bin_path = osutil.get_agent_bin_path()

    if name in ('redhat', 'centos', 'almalinux', 'cloudlinux', 'rocky'):
        if version.startswith("8.2"):
            # redhat8+ default to py3
            set_bin_files(data_files, dest=agent_bin_path,
                          src=["bin/py3/waagent", "bin/waagent2.0"])
        else:
            set_bin_files(data_files, dest=agent_bin_path)
        set_conf_files(data_files)
        set_logrotate_files(data_files)
        set_udev_files(data_files)
        if version.startswith("8.2"):
            # redhat 8+ uses systemd and python3
            set_systemd_files(data_files, dest=systemd_dir_path,
                              src=["init/redhat/waagent.service",
                              "init/azure.slice",
                              "init/azure-vmextensions.slice"
                                   ])

        elif version.startswith("6"):
            set_sysv_files(data_files)
        else:
            # redhat7.0+ use systemd
            set_systemd_files(data_files, dest=systemd_dir_path,
                              src=[
                                  "init/redhat/py2/waagent.service",
                                  "init/azure.slice",
                                  "init/azure-vmextensions.slice"
                              ])
            if version.startswith("7.1"):
                # TODO this is a mitigation to systemctl bug on 7.1
                set_sysv_files(data_files)<commit_msg>Update setup.py to cater for all RHEL 8 versions (#2532)<commit_after>#!/usr/bin/env python
#
# Microsoft Azure Linux Agent setup.py
#
# Copyright 2013 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import subprocess
import sys

import setuptools
from setuptools import find_packages
from setuptools.command.install import install as _install

from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.version import AGENT_NAME, AGENT_VERSION, \
    AGENT_DESCRIPTION, \
    DISTRO_NAME, DISTRO_VERSION, DISTRO_FULL_NAME

root_dir = os.path.dirname(os.path.abspath(__file__))  # pylint: disable=invalid-name
os.chdir(root_dir)


def set_files(data_files, dest=None, src=None):
    data_files.append((dest, src))


def set_bin_files(data_files, dest, src=None):
    if src is None:
        src = ["bin/waagent", "bin/waagent2.0"]
    data_files.append((dest, src))


def set_conf_files(data_files, dest="/etc", src=None):
    if src is None:
        src = ["config/waagent.conf"]
    data_files.append((dest, src))


def set_logrotate_files(data_files, dest="/etc/logrotate.d", src=None):
    if src is None:
        src = ["config/waagent.logrotate"]
    data_files.append((dest, src))


def set_sysv_files(data_files, dest="/etc/rc.d/init.d", src=None):
    if src is None:
        src = ["init/waagent"]
    data_files.append((dest, src))


def set_systemd_files(data_files, dest, src=None):
    if src is None:
        src = ["init/waagent.service"]
    data_files.append((dest, src))


def set_freebsd_rc_files(data_files, dest="/etc/rc.d/", src=None):
    if src is None:
        src = ["init/freebsd/waagent"]
    data_files.append((dest, src))


def set_openbsd_rc_files(data_files, dest="/etc/rc.d/", src=None):
    if src is None:
        src = ["init/openbsd/waagent"]
    data_files.append((dest, src))


def set_udev_files(data_files, dest="/etc/udev/rules.d/", src=None):
    if src is None:
        src = ["config/66-azure-storage.rules",
               "config/99-azure-product-uuid.rules"]
    data_files.append((dest, src))


def get_data_files(name, version, fullname):  # pylint: disable=R0912
    """
    Determine data_files according to distro name, version and init system type
    """
    data_files = []
    osutil = get_osutil()
    systemd_dir_path = osutil.get_systemd_unit_file_install_path()
    agent_bin_path = osutil.get_agent_bin_path()

    if name in ('redhat', 'centos', 'almalinux', 'cloudlinux', 'rocky'):
        if version.startswith("8"):
            # redhat8+ default to py3
            set_bin_files(data_files, dest=agent_bin_path,
                          src=["bin/py3/waagent", "bin/waagent2.0"])
        else:
            set_bin_files(data_files, dest=agent_bin_path)
        set_conf_files(data_files)
        set_logrotate_files(data_files)
        set_udev_files(data_files)
        if version.startswith("8"):
            # redhat 8+ uses systemd and python3
            set_systemd_files(data_files, dest=systemd_dir_path,
                              src=["init/redhat/waagent.service",
                              "init/azure.slice",
                              "init/azure-vmextensions.slice"
                                   ])

        elif version.startswith("6"):
            set_sysv_files(data_files)
        else:
            # redhat7.0+ use systemd
            set_systemd_files(data_files, dest=systemd_dir_path,
                              src=[
                                  "init/redhat/py2/waagent.service",
                                  "init/azure.slice",
                                  "init/azure-vmextensions.slice"
                              ])
            if version.startswith("7.1"):
                # TODO this is a mitigation to systemctl bug on 7.1
                set_sysv_files(data_files)
{'fraction_non_alphanumeric': 0.10835734870317003, 'fraction_numerical': 0.008876080691642651, 'mean_word_length': 2.571840263482915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7668479', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2697, 'n_words': 640}