From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web11.7343.1585949604394351027 for ; Fri, 03 Apr 2020 14:33:24 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=QIcBHBS7; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: ashley.e.desimone@intel.com) IronPort-SDR: dj81KqFVXGn3ql+ipwHaQ2dgtarAcUXZ3NbTLATIQPhTWXhOHW4gK30ZwavOQlsu536/QtVqpe VUqr12VLNciQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2020 14:33:23 -0700 IronPort-SDR: cMKgxBsE4xqs0T6/HKDgG81YoxafOPhPN4CW3s2lS10pd2Q92nCw7ZpqKxNRMDiFGcwb0OsFc6 ACk89pDGegCw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,341,1580803200"; d="scan'208";a="329284898" Received: from orsmsx102.amr.corp.intel.com ([10.22.225.129]) by orsmga001.jf.intel.com with ESMTP; 03 Apr 2020 14:33:23 -0700 Received: from orsmsx112.amr.corp.intel.com (10.22.240.13) by ORSMSX102.amr.corp.intel.com (10.22.225.129) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 3 Apr 2020 14:33:23 -0700 Received: from ORSEDG002.ED.cps.intel.com (10.7.248.5) by ORSMSX112.amr.corp.intel.com (10.22.240.13) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 3 Apr 2020 14:33:23 -0700 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (104.47.46.53) by edgegateway.intel.com (134.134.137.101) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 3 Apr 2020 14:33:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wzl6N8F4Dmr5eObwRL3SIeqVBEhpOKpKmXJZZg8zQwhRsbSlWDOaXaTxBl0nSRp8z3y1PJkwZgmKD4a0cbW9mwTW+sz0GLELUOwpzzCYIiq4Dv5KTlg23wl2tWWqC6xq0Jj2dWvQMs7s+E1MOVl6ic95xJAYHHLBWT7IKjqGaEsdZgGOvIWDjXOMsT2+aRRiBJ2cNmDXJ5D15mv6kyCwgkh7np4Qa9jkTEdTRUlrAHFHvdGtWApCJzIZ6iRWVHRvF5oblm44lCTbc2VhchVcbqx/wQ0XNOFTgn7+ybkwLD6aH7fcvzynS3S5X7egDEoF0jwjPFqO9h4IT3kgPpMVbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IQKc3YZyMD/2L9wQfHv+N26bt6uv0j9TvY3l/krqM7A=; b=CV6FzNIXdrKjPFQ1JjcxbyuH2Bc0LiFA4e5wk+JlxbeBTKFrSWQghOOnn8bWN9IOgsIDzmL1my79pq8vpqvJuZT5IijkBvtwY7W4C7wie0R2gOR9ipnuzFZk/5dMfXCGV7sWDr8dnZ7z3F4M3hMy78D4PC+t0YofiQ61zUgJd70THNDq5awgjTcj3bhekuLbRp4NAYD6U2M9A2m09n8JwI8TOgzD/Q95yTFVih1IWqwFqx7GRjX7cIwcUPp4Td9hhu6/URA1MmPEP0yO/8Hm1WtABAdwynvVXzvryuNAqzSkNPTxJmgGDKmMZ6331LwRBwgz8xJ08pVrhLnE8OZPfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IQKc3YZyMD/2L9wQfHv+N26bt6uv0j9TvY3l/krqM7A=; b=QIcBHBS7OaclWT+6yMz1JGLZhf/4x8+bZyo1lwHOOEYpuTdlU5SIWL85Lp+LQ6ut50ElZPP4SLi6EYRthzzoxBTeUW7BubP1uvuNKB2pieKUUuHMnCVgSdvREuTF5ZgnNEr77mYHh+Ml1CNzJtPPuXwe8xmPrfRZembw0noMeZc= Received: from DM6PR11MB3628.namprd11.prod.outlook.com (2603:10b6:5:144::25) by DM6PR11MB3452.namprd11.prod.outlook.com (2603:10b6:5:9::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.19; Fri, 3 Apr 2020 21:33:21 +0000 Received: from DM6PR11MB3628.namprd11.prod.outlook.com ([fe80::5904:e7d9:f64d:9a7e]) by DM6PR11MB3628.namprd11.prod.outlook.com ([fe80::5904:e7d9:f64d:9a7e%3]) with mapi id 15.20.2878.014; Fri, 3 Apr 2020 21:33:20 +0000 From: "Ashley E Desimone" To: "Desimone, Nathaniel L" , "devel@edk2.groups.io" CC: "Pandya, Puja" , "Bjorge, Erik C" , "Agyeman, Prince" , "Bret Barkelew" , Philippe Mathieu-Daude Subject: Re: [edk2-staging/EdkRepo] [PATCH V1 1/3] EdkRepo: Generate command completion scripts Thread-Topic: [edk2-staging/EdkRepo] [PATCH V1 1/3] EdkRepo: Generate command completion scripts Thread-Index: AQHWCHXc94VmguQqREGU1NwYOx9wgahn7aCw Date: Fri, 3 Apr 2020 21:33:20 +0000 Message-ID: References: <20200401223452.4805-1-nathaniel.l.desimone@intel.com> <20200401223452.4805-2-nathaniel.l.desimone@intel.com> In-Reply-To: <20200401223452.4805-2-nathaniel.l.desimone@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.2.0.6 dlp-reaction: no-action dlp-product: dlpe-windows authentication-results: spf=none (sender IP is ) smtp.mailfrom=ashley.e.desimone@intel.com; x-originating-ip: [134.134.136.213] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f43519b4-1c31-448b-f814-08d7d816a180 x-ms-traffictypediagnostic: DM6PR11MB3452: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 0362BF9FDB x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB3628.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10019020)(396003)(136003)(346002)(366004)(376002)(39860400002)(81166006)(53546011)(66946007)(54906003)(8676002)(316002)(55016002)(8936002)(81156014)(66556008)(64756008)(9686003)(66476007)(5660300002)(86362001)(52536014)(76116006)(66446008)(110136005)(2906002)(7696005)(4326008)(6506007)(26005)(71200400001)(478600001)(186003)(33656002)(460985005);DIR:OUT;SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RC4CfEVDD/OBpu4YtuNG2JALmGNJlf1zfOOiUsnvMwTgV2xUnS4A38CII96z6M2xo2nuuKOQgpxN+9Bq0tSdkQuUzbV++Ld/fC+XZHkIJoja1XPM+NHW/0XdyIGCETy5feL76ArxDZjSvmpf+nZ2hTm7l+HQ0kKbjwEtF46FBsenLGQvynlD+5x4fFUcOwt6FBIU9Lrm4b/8dBo9AJ6d/ncZpMYvq6HUMl8fjKkJKOo1Q0a65FzOgUOOICLTLxjNVchWBDOHigyj4ARQwAIvm3+uk9t2Lm/3nxpF2owXNaNQlZh+VkV/eSLy29JunHRf1/iCCIYZkcgasXe4mujEcHzBFlu33NvmleuTWU+t9n68wjleYllagd1t0wkusP1Wf+82+cB//C9JqDNbf43DWBbuu3WSdrhlKrmP+8FL6kjFPHP5W6duHX5YTWSthi6xJvGCsC5sx3SCrF///9qUZ8ykGwm0rkz82PfKNPavdeNqrFGUkijVARyKs0oGxb7J x-ms-exchange-antispam-messagedata: 8RQjJairc/zPJQZeGSoogLFoKIsJmlDXiCnHmrzaX/eeinMClN2xadR/tdLmKs4X4zjl0b4DwMlnfuRoLuc0wwmiBbsZRGqpRcs2JhexsLyWQcvFKQ/Nx5WXIBZfZfVwThB+SZ24W6HiI4r7kQP0zA== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: f43519b4-1c31-448b-f814-08d7d816a180 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Apr 2020 21:33:20.5089 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: zPKsAp2DSepDog/l4ZqyUJik3uyYFLuyekTe8T5OQAuJ5SvS0u367YLmvfkXl+yn5N89yOF+M102769nbqlhBq6w4JFY3Zue/2XzcU+fsNo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB3452 Return-Path: ashley.e.desimone@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable The following section will need to be updated to take into account Erik's r= ecent addition of support for archived combinations.=20 +def checkout(parsed_args, config): + manifest =3D get_workspace_manifest() + print(' '.join([c.name for c in manifest.combinations])) Thanks, Ashley=20 -----Original Message----- From: Desimone, Nathaniel L =20 Sent: Wednesday, April 1, 2020 3:35 PM To: devel@edk2.groups.io Cc: Desimone, Ashley E ; Pandya, Puja ; Bjorge, Erik C ; Agyeman, Prince = ; Bret Barkelew ; Ph= ilippe Mathieu-Daude Subject: [edk2-staging/EdkRepo] [PATCH V1 1/3] EdkRepo: Generate command co= mpletion scripts Adds code to edkrepo_cli.py to generate a bash/zsh compatible command compl= etion script. Add a new command_completion_edkrepo.py script which is callable by the she= ll when needed for dynamic completion data. For example, providing completi= on for "edkrepo checkout" requires the shell to know the list of possible b= ranch combinations, this requires parsing the manifest XML. command_complet= ion_edkrepo.py provides a means for the shell to get that type of data. Cc: Ashley DeSimone Cc: Puja Pandya Cc: Erik Bjorge Cc: Prince Agyeman Cc: Bret Barkelew Cc: Philippe Mathieu-Daude Signed-off-by: Nate DeSimone --- edkrepo/command_completion_edkrepo.py | 86 +++++++++++++++++++++++++++ edkrepo/edkrepo_cli.py | 61 ++++++++++++++++++- setup.py | 8 +-- 3 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 edk= repo/command_completion_edkrepo.py diff --git a/edkrepo/command_completion_edkrepo.py b/edkrepo/command_comple= tion_edkrepo.py new file mode 100644 index 0000000..05de9ca --- /dev/null +++ b/edkrepo/command_completion_edkrepo.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +# +## @file +# command_completion_edkrepo.py +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
#=20 +SPDX-License-Identifier: BSD-2-Clause-Patent # + +import argparse +import io +import os +import sys +import traceback + +from edkrepo_manifest_parser.edk_manifest import ManifestXml from=20 +edkrepo.config import config_factory from edkrepo.config.config_factory=20 +import get_workspace_manifest + +def checkout(parsed_args, config): + manifest =3D get_workspace_manifest() + print(' '.join([c.name for c in manifest.combinations])) + +def current_combo(parsed_args, config): + manifest =3D get_workspace_manifest() + print(" [{}]".format(manifest.general_config.current_combo)) + +def checkout_pin(parsed_args, config): + pins =3D [] + manifest_directory =3D config['cfg_file'].manifest_repo_abs_local_path + manifest =3D get_workspace_manifest() + pin_folder =3D os.path.normpath(os.path.join(manifest_directory, manif= est.general_config.pin_path)) + for dirpath, _, filenames in os.walk(pin_folder): + for file in filenames: + pin_file =3D os.path.join(dirpath, file) + # Capture error output from manifest parser stdout so it is hi= dden unless verbose is enabled + stdout =3D sys.stdout + sys.stdout =3D io.StringIO() + pin =3D ManifestXml(pin_file) + parse_output =3D sys.stdout.getvalue() + sys.stdout =3D stdout + if parsed_args.verbose and parse_output.strip() !=3D '': + print('Pin {} Parsing Errors: {}\n'.format(file, parse_out= put.strip())) + if pin.project_info.codename =3D=3D manifest.project_info.code= name: + pins.append(file) + print(' '.join(pins)) + +# To add command completions for a new command, add an entry to this dicti= onary. +command_completions =3D { + 'current-combo': current_combo, + 'checkout': checkout, + 'checkout-pin': checkout_pin, + 'chp': checkout_pin +} + +def main(): + parser =3D argparse.ArgumentParser() + parser.add_argument("-v", "--verbose", action=3D"store_true", help=3D'= Increases command verbosity') + subparsers =3D parser.add_subparsers(dest=3D'subparser_name') + for command_completion in command_completions: + subparsers.add_parser(command_completion, formatter_class=3Dargpar= se.RawTextHelpFormatter) + if len(sys.argv) <=3D 1: + return 0 + parsed_args =3D parser.parse_args() + try: + command_name =3D parsed_args.subparser_name + config =3D {} + config["cfg_file"] =3D config_factory.GlobalConfig() + config["user_cfg_file"] =3D config_factory.GlobalUserConfig() + if command_name not in command_completions: + return 1 + command_completions[command_name](parsed_args, config) + return 0 + except Exception as e: + if parsed_args.verbose: + traceback.print_exc() + print("Error: {}".format(str(e))) + return 1 + return 0 + +if __name__ =3D=3D "__main__": + try: + sys.exit(main()) + except Exception as e: + traceback.print_exc() + sys.exit(1) diff --git a/edkrepo/edkrepo_cli.py b/edkrepo/edkrepo_cli.py index 0b69860.= .03061c9 100644 --- a/edkrepo/edkrepo_cli.py +++ b/edkrepo/edkrepo_cli.py @@ -3,7 +3,7 @@ ## @file # edkrepo_cli.py # -# Copyright (c) 2017- 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2020, Intel Corporation. All rights=20 +reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # =20 @@ -29,6 +29,7 @@ from edkrepo.common.edkrepo_exception import EdkrepoExcep= tion, EdkrepoGlobalConf from edkrepo.common.edkrepo_exception import Edkre= poWarningException from edkrepo.common.edkrepo_exception import EdkrepoCon= figFileInvalidException from edkrepo.common.humble import KEYBOARD_INTERRU= PT, GIT_CMD_ERROR +from edkrepo.common.pathfix import get_actual_path =20 def generate_command_line(command): parser =3D argparse.ArgumentParser() @@ -100,6 +101,61 @@ def generate_command_line(command): subparser_name.add_argument(('--' + arg.get('name')), acti= on=3Darg_action, help=3Darg.get('help-text')) return parser =20 +command_completion_script_header=3D'''#!/usr/bin/env bash # ## @file=20 +edkrepo_completions.sh # # Automatically generated please DO NOT modify=20 +!!! +# + +''' +def generate_command_completion_script(script_filename, parser): + import edkrepo.command_completion_edkrepo as completion + commands =3D [] + for action in parser._positionals._group_actions: + if action.choices is not None: + commands =3D [c for c in action.choices] + break + commands =3D sorted(commands) + commands_with_3rd_param_completion =3D [c for c in completion.command_= completions if c in commands] + commands_with_3rd_param_completion =3D sorted(commands_with_3rd_param_= completion) + with open(script_filename, 'w') as f: + f.write(command_completion_script_header) + if sys.platform =3D=3D "win32": + command_completion_path =3D os.path.dirname(sys.executable) + command_completion_path =3D os.path.join(command_completion_pa= th, 'Scripts', "command_completion_edkrepo.exe") + if not os.path.isfile(command_completion_path): + print('command_completion_edkrepo.exe not found') + return + command_completion_path =3D get_actual_path(command_completion= _path) + (drive, path) =3D os.path.splitdrive(command_completion_path) + command_completion_path =3D '/{}{}'.format(drive.replace(':','= ').lower(), path.replace('\\','/')) + f.write("export command_completion_edkrepo_file=3D'{}'\n".form= at(command_completion_path)) + f.write('alias command_completion_edkrepo=3D"$command_completi= on_edkrepo_file"\n') + f.write('_edkrepo_completions() {\n if [ "${#COMP_WORDS[@]}" -e= q "2" ]; then\n') + f.write(' COMPREPLY=3D($(compgen -W "{}" -- "${{COMP_WORDS[= 1]}}"))\n'.format(' '.join(commands))) + if len(commands_with_3rd_param_completion) > 0: + f.write(' elif [ "${#COMP_WORDS[@]}" -eq "3" ]; then\n') + first_loop =3D True + for command in commands_with_3rd_param_completion: + if first_loop: + f.write(' if [ "${{COMP_WORDS[1]}}" =3D=3D "{}" ]; = then\n'.format(command)) + first_loop =3D False + else: + f.write(' elif [ "${{COMP_WORDS[1]}}" =3D=3D "{}" ]= ; then\n'.format(command)) + f.write(' COMPREPLY=3D($(compgen -W "$(command_comp= letion_edkrepo ${COMP_WORDS[1]})" -- "${COMP_WORDS[2]}"))\n') + if len(commands_with_3rd_param_completion) > 0: + f.write(' fi\n') + f.write(' fi\n}\n\n') + if len(commands_with_3rd_param_completion) > 0: + if sys.platform =3D=3D "win32": + f.write('if [ -x "$(command -v edkrepo)" ] && [ -x "$(comm= and -v $command_completion_edkrepo_file)" ]; then\n') + else: + f.write('if [ -x "$(command -v edkrepo)" ] && [ -x "$(comm= and -v command_completion_edkrepo)" ]; then\n') + else: + f.write('if [ -x "$(command -v edkrepo)" ]; then\n') + f.write(' complete -F _edkrepo_completions edkrepo\nfi\n') + def main(): command =3D command_factory.create_composite_command() config =3D {} @@ -117,6 +173,9 @@ def main(): if len(sys.argv) <=3D 1: parser.print_help() return 1 + if sys.argv[1] =3D=3D 'generate-command-completion-script' and len(sys= .argv) >=3D 3: + generate_command_completion_script(sys.argv[2], parser) + return 0 parsed_args =3D parser.parse_args() command_name =3D parsed_args.subparser_name try: diff --git a/setup.py b/setup.py index e14aed1..e7e6ce8 100755 --- a/setup.py +++ b/setup.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 # -## @file -# setup.py +## @file setup.py # -# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2020, Intel Corporation. All rights=20 +reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # =20 @@ -20,7 +19,8 @@ setup(name=3D'edkrepo', include_package_data=3DTrue, entry_points=3D{ 'console_scripts': [ - 'edkrepo =3D edkrepo.edkrepo_entry_point:main' + 'edkrepo =3D edkrepo.edkrepo_entry_point:main', + 'command_completion_edkrepo =3D edkrepo.command_completion_e= dkrepo:main' ] } ) -- 2.24.0.windows.2