#!/usr/bin/python3
#
# Copyright (c) 2017-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited
#

import sys
import os


def rename_cython_files(path):
    for root, subdir, files in os.walk(path):
        for f in files:
            if f.endswith('.so'):
                if len(f.split('.')) == 2:
                    os.remove(os.path.join(root, f))
                else:
                    name, ext = os.path.splitext(os.path.basename(f))
                    os.rename(os.path.join(root, f), '{}/{}.so'.format(root, name[:name.index('.')]))


if __name__ == '__main__':
    python_version = 'python{}.{}'.format(sys.version_info.major, sys.version_info.minor)
    for path in ['/usr/share/venvs/netq-agent/lib/{}/site-packages/netq_agent'.format(python_version),
                 '/usr/share/venvs/netq-agent/lib/{}/site-packages/netq_lib'.format(python_version)]:
        if os.path.exists(path):
            rename_cython_files(path)
