diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c70844 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +edkrepo_dev_local_data/*/ +edkrepo_dev_local_data/*.* +__pycache__/ + diff --git a/edkrepo/commands/command_factory.py b/edkrepo/commands/command_factory.py index 76211fe..5fea8ba 100644 --- a/edkrepo/commands/command_factory.py +++ b/edkrepo/commands/command_factory.py @@ -14,6 +14,8 @@ from edkrepo.commands.edkrepo_command import EdkrepoCommand from edkrepo.commands.composite_command import CompositeCommand from edkrepo.config.config_factory import GlobalConfig +import edkrepo.common.ui_functions as ui_functions +import edkrepo.commands.humble.command_factory_humble as humble def _is_command(CommandClass): if CommandClass == EdkrepoCommand: @@ -54,8 +56,14 @@ def get_commands(): cmd_search_dirs = [] for cmd_pkg in cmd_pkg_list: - mod = importlib.import_module(cmd_pkg) - cmd_search_dirs.append((cmd_pkg, os.path.dirname(mod.__file__))) + try: + mod = importlib.import_module(cmd_pkg) + cmd_search_dirs.append((cmd_pkg, os.path.dirname(mod.__file__))) + except ImportError: + ui_functions.print_info_msg(humble.COMMAND_PACKAGE_NOT_FOUND.format(cmd_pkg), header=False) + if cmd_search_dirs == []: + ui_functions.print_info_msg(humble.COMMAND_PACKAGES_NOT_FOUND, header=False) + raise ImportError (cmd_pkg_list) for cmd_dir in cmd_search_dirs: for module in os.listdir(cmd_dir[1]): if module == '__init__.py' or os.path.splitext(module)[1] != '.py': diff --git a/edkrepo/commands/humble/command_factory_humble.py b/edkrepo/commands/humble/command_factory_humble.py new file mode 100644 index 0000000..9a94797 --- /dev/null +++ b/edkrepo/commands/humble/command_factory_humble.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 +# +## @file +# command_factory_humble.py +# +# Copyright (c) 2024, Intel Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +COMMAND_PACKAGE_NOT_FOUND = 'command-package {} defined in the cfg file was not found.' +COMMAND_PACKAGES_NOT_FOUND = 'No command-packages defined in the cfg file were found.' diff --git a/edkrepo/config/config_factory.py b/edkrepo/config/config_factory.py index 7808704..9945b6d 100644 --- a/edkrepo/config/config_factory.py +++ b/edkrepo/config/config_factory.py @@ -26,6 +26,7 @@ def get_edkrepo_global_data_directory(): global_data_dir = None + local_data_dir = None if sys.platform == "win32": shell32 = oledll.shell32 SHGetFolderPath = shell32.SHGetFolderPathW @@ -36,11 +37,14 @@ def get_edkrepo_global_data_directory(): common_appdata = create_unicode_buffer(MAX_PATH) SHGetFolderPath(None, CSIDL_COMMON_APPDATA, None, SHGFP_TYPE_CURRENT, common_appdata) global_data_dir = os.path.join(common_appdata.value, "edkrepo") + local_data_dir = os.path.join(os.path.dirname(sys.argv[0]), "edkrepo_dev_local_data") elif sys.platform == "darwin" or sys.platform.startswith("linux") or os.name == "posix": global_data_dir = expanduser("~/.edkrepo") if not os.path.isdir(global_data_dir): if not os.path.exists(os.path.dirname(global_data_dir)): raise EdkrepoGlobalDataDirectoryNotFoundException(humble.GLOBAL_DATA_DIR_NOT_FOUND.format(os.path.dirname(global_data_dir))) + if sys.platform == "win32" and os.path.isdir(local_data_dir): + return local_data_dir os.mkdir(global_data_dir) return global_data_dir diff --git a/edkrepo_dev.py b/edkrepo_dev.py new file mode 100644 index 0000000..0277709 --- /dev/null +++ b/edkrepo_dev.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# +## @file +# edkrepo_dev.py +# +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import sys +import traceback +if sys.version_info >= (3, 8): + from importlib.metadata import version +else: + import pkg_resources +from edkrepo.config.config_factory import GlobalConfig +from edkrepo.common.edkrepo_exception import EdkrepoGlobalConfigNotFoundException +from edkrepo import edkrepo_cli + +if __name__ == '__main__': + # Run the edkrepo command line interface without building and running the edkrepo installer. + # Minimum Python version and Git version in README.md + # Additional Python requirements in edkrepo_dev_requirements_windows.txt + # EdkRepo 'git bash' features support require the installer to use. + try: + # If a global config file was not installed, do not continue further. + GlobalConfig() + except EdkrepoGlobalConfigNotFoundException as e: + traceback.print_exc() + print() + print("Create a global edkrepo.cfg file before running edkrepo_dev.py.") + print("example global config file: edk2-edkrepo/edkrepo_installer/Vendor/edkrepo.cfg") + sys.exit(102) + except Exception as e: + traceback.print_exc() + sys.exit(1) + + try: + # If system has edkrepo installed, exit + if sys.version_info >= (3, 8): + edkrepo_version = version("edkrepo") + else: + edkrepo_version = pkg_resources.get_distribution("edkrepo").version + print("Edkrepo is found installed on the system. Edkrepo version: ", edkrepo_version) + print("Run the edkrepo uninstaller before using 'edkrepo_dev.py'.") + sys.exit(1) + except: + print("edkrepo running from development source.") + + try: + sys.exit(edkrepo_cli.main()) + except Exception as e: + traceback.print_exc() + sys.exit(1) diff --git a/edkrepo_dev_local_data/README b/edkrepo_dev_local_data/README new file mode 100644 index 0000000..505cdfe --- /dev/null +++ b/edkrepo_dev_local_data/README @@ -0,0 +1,2 @@ +For edkrepo_dev.py use, this folder has the least priority to be selected as the edkrepo global data directory. + diff --git a/edkrepo_dev_requirements_windows.txt b/edkrepo_dev_requirements_windows.txt new file mode 100644 index 0000000..25c18e4 --- /dev/null +++ b/edkrepo_dev_requirements_windows.txt @@ -0,0 +1,5 @@ +colorama>=0.4.4 +gitdb>=4.0.7 +GitPython>=3.1.14 +smmap>=4.0.0 +