# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#

__all__ = ["validate_extensions_load"]

import omni.kit.app
import omni.kit.test


def validate_extensions_load():
    failures = []
    manager = omni.kit.app.get_app().get_extension_manager()
    for ext in manager.get_extensions():
        ext_id = ext["id"]
        ext_name = ext["name"]
        info = manager.get_extension_dict(ext_id)

        enabled = ext.get("enabled", False)
        if not enabled:
            continue

        failed = info.get("state/failed", False)
        if failed:
            failures.append(ext_name)

    if len(failures) == 0:
        print("\n[success] All extensions loaded successfuly!\n")
    else:
        print("")
        print(f"[error] Found {len(failures)} extensions that could not load:")
        for count, ext in enumerate(failures):
            print(f"  {count+1}: {ext}")
        print("")
    return len(failures)


if __name__ == "__main__":
    result = validate_extensions_load()
    omni.kit.app.get_app().post_quit(result)
