From: "Desimone, Ashley E" <ashley.e.desimone@intel.com>
To: devel@edk2.groups.io
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>,
Puja Pandya <puja.pandya@intel.com>
Subject: [edk2-staging/EdkRepo] [PATCH 2/3] EdkRepo: Multiple Command Package Command Factory Update
Date: Mon, 28 Oct 2019 16:22:44 -0700 [thread overview]
Message-ID: <20191028232245.6712-2-ashley.e.desimone@intel.com> (raw)
In-Reply-To: <20191028232245.6712-1-ashley.e.desimone@intel.com>
Add support for iterating through a list of command packages
from the global config file and generate a list of commands
to be included. Improve the the _is_command() function to
succesfully inspect command classes which do not derive
from the edkrepo base command class
Add support to list a command package as preferred.
Signed-off-by: Ashley E Desimone <ashley.e.desimone@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
---
edkrepo/commands/command_factory.py | 51 ++++++++++++++++++++++++++++---------
1 file changed, 39 insertions(+), 12 deletions(-)
diff --git a/edkrepo/commands/command_factory.py b/edkrepo/commands/command_factory.py
index abdfb1a..9f2e923 100644
--- a/edkrepo/commands/command_factory.py
+++ b/edkrepo/commands/command_factory.py
@@ -13,6 +13,7 @@ import os
import sys
from edkrepo.commands.edkrepo_command import EdkrepoCommand
from edkrepo.commands.composite_command import CompositeCommand
+from edkrepo.config.config_factory import GlobalConfig
def _is_command(CommandClass):
if CommandClass == EdkrepoCommand:
@@ -20,12 +21,20 @@ def _is_command(CommandClass):
if CommandClass in EdkrepoCommand.__subclasses__():
return True
#Use reflection to see if the class would work as a command anyway
- funcs = inspect.getmembers(CommandClass, predicate=inspect.ismethod)
+ try:
+ cmd = CommandClass()
+ except:
+ return False
+ funcs = inspect.getmembers(cmd, predicate=inspect.ismethod)
has_get_metadata = False
has_run_command = False
for func in funcs:
if func[0] == 'get_metadata' and len(inspect.getargspec(func[1])[0]) == 1:
- has_get_metadata = True
+ try:
+ cmd.get_metadata()
+ has_get_metadata = True
+ except:
+ has_get_metadata = False
if func[0] == 'run_command':
arg_spec = inspect.getargspec(func[1])
if len(arg_spec[0]) == 3 and arg_spec[0][1] == "args" and arg_spec[0][2] == "config":
@@ -36,16 +45,34 @@ def _is_command(CommandClass):
return False
def get_commands():
- commands = []
- for module in os.listdir(os.path.dirname(__file__)):
- if module == "__init__.py" or os.path.splitext(module)[1] != ".py":
- continue
- mod = importlib.import_module("edkrepo.commands.{}".format(os.path.splitext(module)[0]))
- classes = inspect.getmembers(mod, predicate=inspect.isclass)
- for cls in classes:
- if _is_command(cls[1]):
- commands.append(cls[1])
- return commands
+ cfg_file = GlobalConfig()
+ cmd_pkg_list = cfg_file.command_packages_list
+ pref_cmd_pkg = cfg_file.pref_pkg
+ commands = {}
+ pref_commands = {}
+ final_cmd_list = []
+ 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__)))
+ 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':
+ continue
+ mod = importlib.import_module('{}.{}'.format(cmd_dir[0], os.path.splitext(module)[0]))
+ classes = inspect.getmembers(mod, predicate=inspect.isclass)
+ for cls in classes:
+ if _is_command(cls[1]):
+ if cmd_dir[0] == pref_cmd_pkg:
+ pref_commands.update([(cls[0], cls[1])])
+ else:
+ commands.update([(cls[0], cls[1])])
+ for key in commands.keys():
+ if key not in pref_commands.keys():
+ final_cmd_list.append(commands[key])
+ final_cmd_list.extend(pref_commands.values())
+ return final_cmd_list
def create_composite_command():
commands = get_commands()
--
2.16.2.windows.1
next prev parent reply other threads:[~2019-10-28 23:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-28 23:22 [edk2-staging/EdkRepo][PATCH 1/3] EdkRepo: Multiple Command Package Configuration Support Desimone, Ashley E
2019-10-28 23:22 ` Desimone, Ashley E [this message]
2019-10-28 23:47 ` [edk2-staging/EdkRepo] [PATCH 2/3] EdkRepo: Multiple Command Package Command Factory Update Nate DeSimone
2019-10-28 23:22 ` [edk2-staging/EdkRepo] [PATCH 3/3] EdkRepo: Multiple Command Package Build Script Update Desimone, Ashley E
2019-10-28 23:47 ` [edk2-devel] " Nate DeSimone
2019-10-28 23:47 ` [edk2-devel] [edk2-staging/EdkRepo][PATCH 1/3] EdkRepo: Multiple Command Package Configuration Support Nate DeSimone
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191028232245.6712-2-ashley.e.desimone@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox