Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a script to run edkrepo_cli.py without edkrepo installed to host. #242

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
edkrepo_dev_local_data/*/
edkrepo_dev_local_data/*.*
__pycache__/

12 changes: 10 additions & 2 deletions edkrepo/commands/command_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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':
Expand Down
11 changes: 11 additions & 0 deletions edkrepo/commands/humble/command_factory_humble.py
Original file line number Diff line number Diff line change
@@ -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.'
4 changes: 4 additions & 0 deletions edkrepo/config/config_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
54 changes: 54 additions & 0 deletions edkrepo_dev.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions edkrepo_dev_local_data/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
For edkrepo_dev.py use, this folder has the least priority to be selected as the edkrepo global data directory.

5 changes: 5 additions & 0 deletions edkrepo_dev_requirements_windows.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
colorama>=0.4.4
gitdb>=4.0.7
GitPython>=3.1.14
smmap>=4.0.0