From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web09.5398.1572306453231279885 for ; Mon, 28 Oct 2019 16:47:33 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: nathaniel.l.desimone@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Oct 2019 16:47:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,241,1569308400"; d="scan'208";a="198209964" Received: from orsmsx102.amr.corp.intel.com ([10.22.225.129]) by fmsmga008.fm.intel.com with ESMTP; 28 Oct 2019 16:47:32 -0700 Received: from orsmsx161.amr.corp.intel.com (10.22.240.84) by ORSMSX102.amr.corp.intel.com (10.22.225.129) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 28 Oct 2019 16:47:31 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.28]) by ORSMSX161.amr.corp.intel.com ([169.254.4.146]) with mapi id 14.03.0439.000; Mon, 28 Oct 2019 16:47:31 -0700 From: "Nate DeSimone" To: "Desimone, Ashley E" , "devel@edk2.groups.io" CC: "Pandya, Puja" Subject: Re: [edk2-staging/EdkRepo] [PATCH 2/3] EdkRepo: Multiple Command Package Command Factory Update Thread-Topic: [edk2-staging/EdkRepo] [PATCH 2/3] EdkRepo: Multiple Command Package Command Factory Update Thread-Index: AQHVjeapvLuTiFbdVEaofM1cH94dsKdwuE7A Date: Mon, 28 Oct 2019 23:47:30 +0000 Message-ID: <02A34F284D1DA44BB705E61F7180EF0AB5B7F906@ORSMSX113.amr.corp.intel.com> References: <20191028232245.6712-1-ashley.e.desimone@intel.com> <20191028232245.6712-2-ashley.e.desimone@intel.com> In-Reply-To: <20191028232245.6712-2-ashley.e.desimone@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMmM1YzFjNmUtMDE4Zi00NzllLWFmZTYtYzVlMjM2OGI3ZTgyIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiTjk0ZUhoVDlzM0lFZ2dMbVVuTXJTWGxxc25TR3c0UFZ2S3dwUHI2ZVYzM1RqTkV0UkJiR0Vkb2dTd0RxZ3JOcSJ9 x-ctpclassification: CTP_NT x-originating-ip: [10.22.254.138] MIME-Version: 1.0 Return-Path: nathaniel.l.desimone@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Nate DeSimone -----Original Message----- From: Desimone, Ashley E =20 Sent: Monday, October 28, 2019 4:23 PM To: devel@edk2.groups.io Cc: Desimone, Nathaniel L ; Pandya, Puja Subject: [edk2-staging/EdkRepo] [PATCH 2/3] EdkRepo: Multiple Command Packa= ge Command Factory Update Add support for iterating through a list of command packages from the globa= l config file and generate a list of commands to be included. Improve the t= he _is_command() function to succesfully inspect command classes which do n= ot derive from the edkrepo base command class Add support to list a command package as preferred. Signed-off-by: Ashley E Desimone Cc: Nate DeSimone Cc: Puja Pandya --- 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 =20 def _is_command(CommandClass): if CommandClass =3D=3D 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 =3D inspect.getmembers(CommandClass, predicate=3Dinspect.ismetho= d) + try: + cmd =3D CommandClass() + except: + return False + funcs =3D inspect.getmembers(cmd, predicate=3Dinspect.ismethod) has_get_metadata =3D False has_run_command =3D False for func in funcs: if func[0] =3D=3D 'get_metadata' and len(inspect.getargspec(func[1= ])[0]) =3D=3D 1: - has_get_metadata =3D True + try: + cmd.get_metadata() + has_get_metadata =3D True + except: + has_get_metadata =3D False if func[0] =3D=3D 'run_command': arg_spec =3D inspect.getargspec(func[1]) if len(arg_spec[0]) =3D=3D 3 and arg_spec[0][1] =3D=3D "args" = and arg_spec[0][2] =3D=3D "config": @@ -36,16 +45,34 @@ def _is_command(CommandClass): return False =20 def get_commands(): - commands =3D [] - for module in os.listdir(os.path.dirname(__file__)): - if module =3D=3D "__init__.py" or os.path.splitext(module)[1] !=3D= ".py": - continue - mod =3D importlib.import_module("edkrepo.commands.{}".format(os.pa= th.splitext(module)[0])) - classes =3D inspect.getmembers(mod, predicate=3Dinspect.isclass) - for cls in classes: - if _is_command(cls[1]): - commands.append(cls[1]) - return commands + cfg_file =3D GlobalConfig() + cmd_pkg_list =3D cfg_file.command_packages_list + pref_cmd_pkg =3D cfg_file.pref_pkg + commands =3D {} + pref_commands =3D {} + final_cmd_list =3D [] + cmd_search_dirs =3D [] + + for cmd_pkg in cmd_pkg_list: + mod =3D 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 =3D=3D '__init__.py' or os.path.splitext(module)[1] = !=3D '.py': + continue + mod =3D importlib.import_module('{}.{}'.format(cmd_dir[0], os.= path.splitext(module)[0])) + classes =3D inspect.getmembers(mod, predicate=3Dinspect.isclas= s) + for cls in classes: + if _is_command(cls[1]): + if cmd_dir[0] =3D=3D 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 =20 def create_composite_command(): commands =3D get_commands() -- 2.16.2.windows.1