From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web09.5143.1572305106020676777 for ; Mon, 28 Oct 2019 16:25:06 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: ashley.e.desimone@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Oct 2019 16:25:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,241,1569308400"; d="scan'208";a="283072629" Received: from aedesimo-desk.amr.corp.intel.com ([10.7.159.171]) by orsmga001.jf.intel.com with ESMTP; 28 Oct 2019 16:25:05 -0700 From: "Desimone, Ashley E" To: devel@edk2.groups.io Cc: Nate DeSimone , Puja Pandya Subject: [edk2-staging/EdkRepo] [PATCH] EdkRepo: Preferred Entry Point Support Date: Mon, 28 Oct 2019 16:25:00 -0700 Message-Id: <20191028232500.9212-1-ashley.e.desimone@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 Add support for defining and selecting a preferred entry point. Signed-off-by: Ashley E Desimone Cc: Nate DeSimone Cc: Puja Pandya --- edkrepo/__main__.py | 4 +- edkrepo/config/config_factory.py | 7 ++- edkrepo/edkrepo_cli.py | 55 ------------------- edkrepo/edkrepo_entry_point.py | 103 +++++++++++++++++++++++++++++++++++ edkrepo_installer/Vendor/edkrepo.cfg | 7 ++- setup.py | 2 +- 6 files changed, 117 insertions(+), 61 deletions(-) create mode 100644 edkrepo/edkrepo_entry_point.py diff --git a/edkrepo/__main__.py b/edkrepo/__main__.py index 9bf3e50..115a779 100644 --- a/edkrepo/__main__.py +++ b/edkrepo/__main__.py @@ -24,11 +24,11 @@ for directory in sitepackages: break else: imp.reload(edkrepo) -import edkrepo.edkrepo_cli +import edkrepo.edkrepo_entry_point if __name__ == '__main__': try: - sys.exit(edkrepo.edkrepo_cli.main()) + sys.exit(edkrepo.edkrepo_entry_point.main()) except Exception as e: traceback.print_exc() sys.exit(1) diff --git a/edkrepo/config/config_factory.py b/edkrepo/config/config_factory.py index 38844d7..e3a437f 100644 --- a/edkrepo/config/config_factory.py +++ b/edkrepo/config/config_factory.py @@ -125,11 +125,16 @@ class GlobalConfig(BaseConfig): CfgProp('git-ver', 'minimum', 'minimum_req_git_ver', None, True), CfgProp('git-ver', 'recommended', 'rec_git_ver', None, True), CfgProp('command-packages', 'packages', 'command_packages', None, True), - CfgProp('preferred-command-package', 'preferred-package', 'pref_pkg', None, True)] + CfgProp('preferred-command-package', 'preferred-package', 'pref_pkg', None, True), + CfgProp('preferred-entry-point', 'entry-point', 'pref_entry_point', None, True)] if not os.path.isfile(self.filename): raise EdkrepoGlobalConfigNotFoundException("edkrepo global config file {} does not exist".format(self.filename)) super().__init__(self.filename, True) + @property + def preferred_entry(self): + return (self.pref_entry_point.split(':')[0], self.pref_entry_point.split(':')[1]) + @property def command_packages_list(self): initial_list = self.command_packages.split('|') diff --git a/edkrepo/edkrepo_cli.py b/edkrepo/edkrepo_cli.py index 8a74581..0b69860 100644 --- a/edkrepo/edkrepo_cli.py +++ b/edkrepo/edkrepo_cli.py @@ -23,61 +23,6 @@ import importlib.util from git.exc import GitCommandError -#Prefer the site-packages version of edkrepo -sitepackages = site.getsitepackages() -sys.path = sitepackages + sys.path -import edkrepo -edkrepo_site_dir = None -edkrepo_package_path = os.path.dirname(os.path.dirname(edkrepo.__file__)) -for directory in sitepackages: - if edkrepo_package_path == directory: - edkrepo_site_dir = edkrepo_package_path - break -else: - imp.reload(edkrepo) - edkrepo_package_path = os.path.dirname(os.path.dirname(edkrepo.__file__)) - for directory in sitepackages: - if edkrepo_package_path == directory: - edkrepo_site_dir = edkrepo_package_path - break -if edkrepo_site_dir is None: - print('Running EdkRepo from local source') - -#Determine if this module is being imported by the launcher script -run_via_launcher_script = False -importer = "" -importer_file = "" -f = inspect.currentframe().f_back -while f is not None: - if f.f_globals.get('__name__').find('importlib') == -1: - importer = f.f_globals.get('__name__') - importer_file = f.f_globals.get('__file__') - if importer_file is None: - importer_file = "" - break - f = f.f_back -if importer == "__main__": - if os.path.basename(importer_file).lower() == "__main__.py": - if os.path.basename(os.path.dirname(importer_file)).lower().find('edkrepo') != -1: - run_via_launcher_script = True - elif os.path.basename(importer_file).lower().find('edkrepo') != -1: - run_via_launcher_script = True - -if __name__ == "__main__" or run_via_launcher_script: - #If this module is the entrypoint, we need to make - #sure that the site-packages version is being executed - if edkrepo_site_dir is not None and os.path.commonprefix([edkrepo_site_dir, __file__]) != edkrepo_site_dir: - edkrepo_cli_file_name = os.path.join(edkrepo_site_dir, 'edkrepo', 'edkrepo_cli.py') - if os.path.isfile(edkrepo_cli_file_name): - spec = importlib.util.spec_from_file_location('edkrepo.edkrepo_cli', edkrepo_cli_file_name) - edkrepo_cli = importlib.util.module_from_spec(spec) - spec.loader.exec_module(edkrepo_cli) - try: - sys.exit(edkrepo_cli.main()) - except Exception as e: - traceback.print_exc() - sys.exit(1) - from edkrepo.commands import command_factory from edkrepo.config import config_factory from edkrepo.common.edkrepo_exception import EdkrepoException, EdkrepoGlobalConfigNotFoundException diff --git a/edkrepo/edkrepo_entry_point.py b/edkrepo/edkrepo_entry_point.py new file mode 100644 index 0000000..1f74d1b --- /dev/null +++ b/edkrepo/edkrepo_entry_point.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# +## @file +# edkrepo_entry_point.py +# +# Copyright (c) 2017- 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import argparse +import imp +import importlib.util +import inspect +import json +import os +import pkg_resources +import site +import subprocess +import sys +import time +import traceback +from operator import itemgetter + +from git.exc import GitCommandError + +import edkrepo + +#Prefer the site-packages version of edkrepo +sitepackages = site.getsitepackages() +sys.path = sitepackages + sys.path +edkrepo_site_dir = None +edkrepo_package_path = os.path.dirname(os.path.dirname(edkrepo.__file__)) +for directory in sitepackages: + if edkrepo_package_path == directory: + edkrepo_site_dir = edkrepo_package_path + break +else: + imp.reload(edkrepo) + edkrepo_package_path = os.path.dirname(os.path.dirname(edkrepo.__file__)) + for directory in sitepackages: + if edkrepo_package_path == directory: + edkrepo_site_dir = edkrepo_package_path + break +if edkrepo_site_dir is None: + print('Running EdkRepo from local source') + +#Determine if this module is being imported by the launcher script +run_via_launcher_script = False +importer = "" +importer_file = "" +f = inspect.currentframe().f_back +while f is not None: + if f.f_globals.get('__name__').find('importlib') == -1: + importer = f.f_globals.get('__name__') + importer_file = f.f_globals.get('__file__') + if importer_file is None: + importer_file = "" + break + f = f.f_back +if importer == "__main__": + if os.path.basename(importer_file).lower() == "__main__.py": + if os.path.basename(os.path.dirname(importer_file)).lower().find('edkrepo') != -1: + run_via_launcher_script = True + elif os.path.basename(importer_file).lower().find('edkrepo') != -1: + run_via_launcher_script = True + +if __name__ == "__main__" or run_via_launcher_script: + #If this module is the entrypoint, we need to make + #sure that the site-packages version is being executed + if edkrepo_site_dir is not None and os.path.commonprefix([edkrepo_site_dir, __file__]) != edkrepo_site_dir: + edkrepo_cli_file_name = os.path.join(edkrepo_site_dir, 'edkrepo', 'edkrepo_entry_point.py') + if os.path.isfile(edkrepo_cli_file_name): + spec = importlib.util.spec_from_file_location('edkrepo.edkrepo_entry_point.py', edkrepo_cli_file_name) + edkrepo_entry_point = importlib.util.module_from_spec(spec) + spec.loader.exec_module(edkrepo_entry_point) + try: + sys.exit(edkrepo_entry_point.main()) + except Exception as e: + traceback.print_exc() + sys.exit(1) + +from edkrepo.config.config_factory import GlobalConfig + +def main(): + cfg_file = GlobalConfig() + pref_entry = (cfg_file.preferred_entry[0]).replace('.py', '') + pref_entry_func = cfg_file.preferred_entry[1] + + try: + mod = importlib.import_module(pref_entry) + func = getattr(mod, pref_entry_func) + func() + except: + print('Unable to launch preferred entry point. Launching default entry point edkrepo.edkrepo_cli.py') + import edkrepo.edkrepo_cli + edkrepo.edkrepo_cli.main() + +if __name__ == "__main__": + try: + sys.exit(main()) + except Exception as e: + traceback.print_exc() + sys.exit(1) \ No newline at end of file diff --git a/edkrepo_installer/Vendor/edkrepo.cfg b/edkrepo_installer/Vendor/edkrepo.cfg index 0312c74..7dcaf20 100644 --- a/edkrepo_installer/Vendor/edkrepo.cfg +++ b/edkrepo_installer/Vendor/edkrepo.cfg @@ -13,9 +13,12 @@ packages = edkrepo.commands [preferred-command-package] preferred-package = edkrepo.commands +[preferred-entry-point] +entry-point = edkrepo.edkrepo_cli:main + [sparsecheckout] always_include = BaseTools|Conf|*.* -always_exclude = +always_exclude = [f2f-cherry-pick] -ignored_folder_substrings = +ignored_folder_substrings = diff --git a/setup.py b/setup.py index 51f65d3..ed07594 100755 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup(name='edkrepo', include_package_data=True, entry_points={ 'console_scripts': [ - 'edkrepo = edkrepo.edkrepo_cli:main' + 'edkrepo = edkrepo.edkrepo_entry_point:main' ] } ) -- 2.16.2.windows.1