From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.7804.1585950689363065350 for ; Fri, 03 Apr 2020 14:51:29 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=VyxvFbfQ; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: ashley.e.desimone@intel.com) IronPort-SDR: yHxQ5nAUV4PHchWjoLHnRgzDzbU/dmFgf2/6EYNSUijKUt5KszAh+zb22ms10swA3UstnQmPHK IeP3rgUfGJDg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2020 14:51:29 -0700 IronPort-SDR: 25tLE7Jx+0l9I3OpHxuobk5SFXoFdoeEORbWyfneQpIl/G8TOTvsgnge8PkFREYPwRB33ciThe ARPdXyXNb4ww== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,341,1580803200"; d="scan'208";a="242919355" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga008.fm.intel.com with ESMTP; 03 Apr 2020 14:51:28 -0700 Received: from FMSEDG001.ED.cps.intel.com (10.1.192.133) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 3 Apr 2020 14:51:29 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.175) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 3 Apr 2020 14:51:28 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=apzUmO+8u85K2WSfJOCH4ixS/VljOkMZVyTS7gVXQQvkmCpD0pwQH4P6Q4SuIyu1jUSAd40sL6QomDnWgFyfk7VVSsQ9ZN3bNmw8YyzMCUxrZxOyBcBg6LOBGwAK8lsqvCQLh/4vWBtwm/J4+dPN8luC7bs4k9hontOSxBP3MatN5RQyU/pGU+ZKO4pE2iigpoRwwgnmDfQ5UiOkTABUEwdYf18T1nv6a8Et0goXYQywgqwhvowrbwF0n6PIwKr0+iq/Fsy0us6fshobovZeoL4/+GXZWC9coiTdoPbLZYqHa+nD9lPrvJsoIHswkrvHn4cwL/UN11JFxBlnHjsyTA== 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=UAN4Q03WbjJ3lQLbB1W0+cOKWHbDIfaHEDeJN+vYrS0=; b=JLuD1+D0GWPTa9n42qZ5CBVcmXkiVITeE37qe8uV1lTQjaC7kMqmVff4eO/KOICuxbPMRsdtHmtagM8diyJPJEJcEHgHcNARdUHXj3TP/95AwqtGDKoapgs7c+OEOY9k2vPgS2RNjlBOO41LPjeoNdBcPFUhYxQ+MC5es18o0l0oUxFLPgj5ScUihU2ERVa0u9wEkFIEC7Dg868H0KI3bNolWYAbDx4AbdLXj2wnLNcvFkFrWBTATj5vPXEEryVDcuuFd7COKZ7dAyDmlJHaMqha399tYnfrn0IJfWCyjOyIs5Gp+zfoWqKIUxBUrEv4wjxfVUCd5q3HMgKOktjMhw== 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=UAN4Q03WbjJ3lQLbB1W0+cOKWHbDIfaHEDeJN+vYrS0=; b=VyxvFbfQ8R45eDh7MHzh9+PmJIwOpAxJvVycO/8N3iepxTilZg0ouB8+5WcTA2yuFjaOLZXUAaDJv+fUTWJ3R+MFaNxvzeW+rM/wGTbwbz62HM7pmPRFgQweZ/IfgUow1Ys+4dhd6rN4Homlrv1PpLA1xxBHYp/J2bJsNG4D25Y= Received: from DM6PR11MB3628.namprd11.prod.outlook.com (2603:10b6:5:144::25) by DM6PR11MB3035.namprd11.prod.outlook.com (2603:10b6:5:69::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2878.19; Fri, 3 Apr 2020 21:51:26 +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:51:26 +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 2/3] EdkRepo: Add command completion setup to install.py Thread-Topic: [edk2-staging/EdkRepo] [PATCH V1 2/3] EdkRepo: Add command completion setup to install.py Thread-Index: AQHWCHXcv1ryHL/z6ES44Kq0vwogMahn8v6g Date: Fri, 3 Apr 2020 21:51:25 +0000 Message-ID: References: <20200401223452.4805-1-nathaniel.l.desimone@intel.com> <20200401223452.4805-3-nathaniel.l.desimone@intel.com> In-Reply-To: <20200401223452.4805-3-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: 1b97aec9-17e3-486f-8dcc-08d7d819287a x-ms-traffictypediagnostic: DM6PR11MB3035: 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:203; 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)(366004)(346002)(136003)(376002)(39860400002)(5660300002)(81166006)(478600001)(52536014)(66946007)(54906003)(86362001)(6506007)(53546011)(2906002)(7696005)(66476007)(66556008)(64756008)(66446008)(316002)(76116006)(55016002)(26005)(81156014)(4326008)(110136005)(9686003)(186003)(8936002)(8676002)(71200400001)(33656002)(30864003)(11771555001)(473944003)(414714003);DIR:OUT;SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Z2XrkLYs4VzK9ZJVufbA6AatOW7P5F42UqguC+dPrCiQGcuGKtNG5XH2XP7u+WDyau1TT5rOV9Og1i2tIlsTjkupo5/Mx5tUAfy345mMZ9f7im0M/9Xi79ILd0rBh3auJ7rQMTw19OAI5LdlcEpVvqH6HoiR9ri0RlHwL6H415GAjXJSvrHQ3SUY+VVnqXyk9YgnZ9Mbo3TcWGn1rbnISguNeMbTqxlhj5Zk2UfVV6rMdXNOQ9jeXazXehB+NaJhrfYMXxOoAxm2FEhaP+Oe9YD9sN7TJp/op+B0qs8GX4UBObx3cIIcyRxFnTwJn2MNANYvOhT+wmV01Al9ChC5riKXn1YrHPldIO/vymrzmPVRVgRo4JrTvhwaU22iRoza0jhH7WSF+JGtTy6nLWH5bQgKygnJMa1QZXlbiQnTA3CpC61rLHjT/55jnUmdW0ATSLfX/fikDVBoBaTfkZIDRQYilwxEgIJkK7Ualmz/CzlJuLQbO2/x0CXY6TWBVSANOTcpYpXpd5HtXU7ZjotvHhZwYB4u7xT1kjfYJC0PpOxUnBl1fL4EQIjelGLtSR/1 x-ms-exchange-antispam-messagedata: KdEjNi1VHlMsy8URbXc4b5dImLKUwgEK5+adJdJFd4DpBBEatCrDY3Ri3nxx5/+FJXqRU8mFc76ddvIJroIra+VwSELUyxYSt75v0XxxsxSY3csPOUvHtTIjEXphXKxYsE44lZHh9jfkgai0zfXfoQ== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 1b97aec9-17e3-486f-8dcc-08d7d819287a X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Apr 2020 21:51:25.9777 (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: VIHFjn7YKGJanupSPUHEMAlxI3ixvQJTaekdX9SwnFP4ABs01IpLX1iQN/E2K+lWSV6JvM7KT9QKCX1uVDT+OpUiRuLRy9O7z0kmKU5B2K0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB3035 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 Reviewed-by: Ashley DeSimone -----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 2/3] EdkRepo: Add command complet= ion setup to install.py Add configuration of command completion scripts to install.py This enables = edkrepo command completions to work "out of box" on most Linux systems by a= ppending to the user's .bashrc and .zshrc startup scripts inclusion of the = EdkRepo command completion scripts. 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_installer/linux-scripts/install.py | 285 ++++++++++++++++++++- 1 file changed, 283 insertions(+), 2 deletions(-) diff --git a/edkrepo_installer/linux-scripts/install.py b/edkrepo_installer= /linux-scripts/install.py index b2cdfed..52f0c52 100755 --- a/edkrepo_installer/linux-scripts/install.py +++ b/edkrepo_installer/linux-scripts/install.py @@ -15,6 +15,7 @@ import importlib.util import logging import os import platform +import re import stat import shutil import subprocess @@ -22,7 +23,7 @@ import sys import traceback import xml.etree.ElementTree as et =20 -tool_sign_on =3D 'Installer for edkrepo version {}\nCopyright(c) Intel Cor= poration, 2019' +tool_sign_on =3D 'Installer for edkrepo version {}\nCopyright(c) Intel Cor= poration, 2020' =20 # Data here should be maintained in a configuration file cfg_dir =3D '.ed= krepo' @@ -31,6 +32,21 @@ cfg_src_dir =3D os.path.abspath('config') whl_src_dir = =3D os.path.abspath('wheels') def_python =3D 'python3' =20 +# ZSH Configuration options +prompt_regex =3D=20 +re.compile(r"#\s+[Aa][Dd][Dd]\s+[Ee][Dd][Kk][Rr][Ee][Pp][Oo]\s+&\s+[Gg] +[Ii][Tt]\s+[Tt][Oo]\s+[Tt][Hh][Ee]\s+[Pp][Rr][Oo][Mm][Pp][Tt]") +zsh_autoload_compinit_regex =3D re.compile(r"autoload\s+-U\s+compinit") +zsh_autoload_bashcompinit_regex =3D=20 +re.compile(r"autoload\s+-U\s+bashcompinit") +zsh_autoload_colors_regex =3D re.compile(r"autoload\s+-U\s+colors") +zsh_colors_regex =3D re.compile(r"\n\s*colors\n") zsh_compinit_regex =3D=20 +re.compile(r"compinit\s+-u") zsh_bashcompinit_regex =3D=20 +re.compile(r"\n\s*bashcompinit\n") +zsh_autoload_compinit =3D 'autoload -U compinit' +zsh_autoload_bashcompinit =3D 'autoload -U bashcompinit' +zsh_autoload_colors =3D 'autoload -U colors' +zsh_colors =3D 'colors' +zsh_compinit =3D 'compinit -u' +zsh_bashcompinit =3D 'bashcompinit' + def default_run(cmd): return subprocess.run(cmd, universal_newlines=3DTrue, stdout=3Dsubproc= ess.PIPE, stderr=3Dsubprocess.STDOUT, check=3DTrue) =20 @@ -51,8 +67,85 @@ def get_args(): parser.add_argument('-p', '--py', action=3D'store', default=3DNone, he= lp=3D'Specify the python command to use when installing') parser.add_argument('-u', '--user', action=3D'store', default=3DNone, = help=3D'Specify user account to install edkrepo support on') parser.add_argument('-v', '--verbose', action=3D'store_true', default= =3DFalse, help=3D'Enables verbose output') + parser.add_argument('--no-prompt', action=3D'store_true', default=3DFa= lse, help=3D'Do NOT add EdkRepo combo and git branch to the shell prompt') + parser.add_argument('--prompt', action=3D'store_true', default=3DFalse= ,=20 + help=3D'Add EdkRepo combo and git branch to the shell prompt') return parser.parse_args() =20 +def is_prompt_customization_installed(user_home_dir): + script_files =3D [os.path.join(user_home_dir, '.bashrc'), os.path.join= (user_home_dir, '.zshrc')] + customization_installed =3D True + for script_file in script_files: + if os.path.isfile(script_file): + with open(script_file, 'r') as f: + script =3D f.read().strip() + data =3D prompt_regex.search(script) + if not data: + customization_installed =3D False + break + return customization_installed + +__add_prompt_customization =3D None +def get_add_prompt_customization(args, user_home_dir): + global __add_prompt_customization + if __add_prompt_customization is not None: + return __add_prompt_customization + if args.no_prompt: + __add_prompt_customization =3D False + return False + elif args.prompt: + __add_prompt_customization =3D True + return True + #Check if the prompt customization has already been installed + if is_prompt_customization_installed(user_home_dir): + __add_prompt_customization =3D False + return False + #If the prompt has not been installed and EdkRepo >=3D 2.0.0 is instal= led, then don't install the prompt customization + if shutil.which('edkrepo') is not None: + res =3D default_run(['edkrepo', '--version']) + if _check_version(res.stdout.replace('edkrepo ', '').strip(), '2.0= .0') >=3D 0: + __add_prompt_customization =3D False + return False + #Show the user an advertisement to see if they want the prompt customi= zation + from select import select + import termios + import tty + def get_key(timeout=3D-1): + key =3D None + old_settings =3D termios.tcgetattr(sys.stdin.fileno()) + try: + tty.setraw(sys.stdin.fileno()) + if timeout !=3D -1: + rlist, _, _ =3D select([sys.stdin], [], [], timeout) + if rlist: + key =3D sys.stdin.read(1) + else: + key =3D sys.stdin.read(1) + finally: + termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, old_s= ettings) + return key + print('\nEdkRepo can show the checked out \033[32mcombo\033[00m and \0= 33[36mbranch\033[00m as part of the command prompt') + print('For example, instead of:\n') + print('\033[01;32muser@machine\033[00m:\033[01;34mEdk2\033[00m$ ') + print('\nThe command prompt would look like:\n') + print('\033[01;32muser@machine\033[00m:\033[01;34mEdk2\033[00m \033[32= m[Edk2Master]\033[36m (master)\033[00m$ ') + print('') + while True: + print('Would you like the combo and branch shown on the command pr= ompt? [y/N] ') + key =3D get_key(120) + if key: + if key =3D=3D 'y' or key =3D=3D 'Y': + print('Y') + __add_prompt_customization =3D True + return True + if key =3D=3D 'n' or key =3D=3D 'N': + print('N') + __add_prompt_customization =3D False + return False + else: + print('No response after 2min... assuming no.') + __add_prompt_customization =3D False + return False + def get_installed_packages(python_command): pip_cmd =3D [def_python, '-m', 'pip', 'list', '--legacy'] try: @@ -146,6 +239,176 @@ def set_execute_permissions(): stat_data =3D os.stat(py_file) os.chmod(py_file, stat_data.st_mode | stat.S_IEXEC) =20 +bash_prompt_customization =3D r''' +# Add EdkRepo & git to the prompt +ps1len=3D"${#PS1}" +let "pos3 =3D ps1len - 3" +let "pos2 =3D ps1len - 2" +if [ "${PS1:pos3}" =3D=3D "\\$ " ]; then + newps1=3D"${PS1:0:pos3}" + prompt_suffix=3D"\\$ " +elif [ "${PS1:pos3}" =3D=3D " $ " ]; then + newps1=3D"${PS1:0:pos3}" + prompt_suffix=3D" $ " +elif [ "${PS1:pos2}" =3D=3D "$ " ]; then + newps1=3D"${PS1:0:pos2}" + prompt_suffix=3D"$ " +else + newps1=3D"$PS1" + prompt_suffix=3D"" +fi + +# EdkRepo combo in prompt. +if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v=20 +command_completion_edkrepo)" ]; then + newps1=3D"$newps1\[\033[32m\]\$current_edkrepo_combo" + current_edkrepo_combo=3D$(command_completion_edkrepo current-combo) + + # Determining the current Edkrepo combo requires invoking Python and=20 +parsing + # manifest XML, which is a relatively expensive operation to do every=20 +time + # the user presses . + # As a performance optimization, only do this if the present working=20 +directory + # changed + if [[ ! -z ${PROMPT_COMMAND+x} ]] && [[ "$PROMPT_COMMAND" !=3D "edkrepo_= combo_chpwd" ]]; then + old_prompt_command=3D$PROMPT_COMMAND + fi + old_pwd=3D$(pwd) + edkrepo_combo_chpwd() { + if [[ "$(pwd)" !=3D "$old_pwd" ]]; then + old_pwd=3D$(pwd) + current_edkrepo_combo=3D$(command_completion_edkrepo current-combo= ) + fi + if [[ ! -z ${PROMPT_COMMAND+x} ]]; then + eval $old_prompt_command + fi + } + PROMPT_COMMAND=3Dedkrepo_combo_chpwd +fi + +# Git branch in prompt. +parse_git_branch() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' +} + +PS1=3D"$newps1\[\033[36m\]\$(parse_git_branch)\[\033[00m\]$prompt_suffix" +''' + +zsh_prompt_customization =3D r''' +# Add EdkRepo & git to the prompt +prompt_length=3D"${#PROMPT}" +let "pos4 =3D prompt_length - 3" +let "pos3 =3D prompt_length - 2" +if [ "${PROMPT[$pos4,$prompt_length]}" =3D ' %# ' ]; then + new_prompt=3D"${PROMPT[1,$pos4-1]}" + prompt_suffix=3D" %# " +elif [ "${PROMPT[$pos3,$prompt_length]}" =3D "%# " ]; then + new_prompt=3D"${PROMPT[1,$pos3-1]}" + prompt_suffix=3D"%# " +else + new_prompt=3D"$PROMPT" + prompt_suffix=3D"" +fi + +# EdkRepo combo in prompt. +if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v=20 +command_completion_edkrepo)" ]; then + new_prompt=3D"$new_prompt%{$fg[green]%}\$current_edkrepo_combo%{$reset_c= olor%}" + current_edkrepo_combo=3D$(command_completion_edkrepo current-combo) + + # Determining the current Edkrepo combo requires invoking Python and=20 +parsing + # manifest XML, which is a relatively expensive operation to do every=20 +time + # the user presses . + # As a performance optimization, only do this if the present working=20 +directory + # changed + function edkrepo_combo_chpwd() { + current_edkrepo_combo=3D$(command_completion_edkrepo current-combo) + } + chpwd_functions=3D(${chpwd_functions[@]} "edkrepo_combo_chpwd") fi + +# Load version control information +autoload -Uz vcs_info +precmd() { vcs_info } + +# Format the vcs_info_msg_0_ variable +zstyle ':vcs_info:git:*' formats " %{$fg[cyan]%}(%b)%{$reset_color%}" + +# Set up the prompt (with git branch name) setopt PROMPT_SUBST eval=20 +"PROMPT=3D'$new_prompt\${vcs_info_msg_0_}\$prompt_suffix'" +''' + +def add_command_to_startup_script(script_file, regex, command, username): + script =3D '' + if os.path.isfile(script_file): + with open(script_file, 'r') as f: + script =3D f.read().strip() + data =3D regex.search(script) + if not data: + if script =3D=3D '': + script =3D command + else: + script =3D '{}\n{}'.format(script, command) + with open(script_file, 'w') as f: + f.write(script) + +def add_command_comment_to_startup_script(script_file, regex, command, com= ment, username): + script =3D '' + if os.path.isfile(script_file): + with open(script_file, 'r') as f: + script =3D f.read().strip() + (new_script, subs) =3D re.subn(regex, command, script) + if subs =3D=3D 0: + command =3D '\n{1}\n{0}\n'.format(command, comment) + if script =3D=3D '': + new_script =3D command + else: + new_script =3D '{}\n{}'.format(script, command) + if new_script !=3D script: + with open(script_file, 'w') as f: + f.write(new_script) + shutil.chown(script_file, user=3Dusername) + os.chmod(script_file, 0o644) + +def add_command_completions_to_shell(command_completion_script, args, user= name, user_home_dir): + # Add "source ~/.bashrc" to ~/.bash_profile if it does not have it alr= eady + bash_profile_file =3D os.path.join(user_home_dir, '.bash_profile') + bash_profile =3D '' + if os.path.isfile(bash_profile_file): + with open(bash_profile_file, 'r') as f: + bash_profile =3D f.read().strip() + profile_source_regex =3D re.compile(r"source\s+~/\.bashrc") + profile_source_regex2 =3D re.compile(r".\s+~/\.bashrc") + data =3D profile_source_regex.search(bash_profile) + if not data: + data =3D profile_source_regex2.search(bash_profile) + if not data: + if bash_profile =3D=3D '': + bash_profile =3D 'source ~/.bashrc\n' + else: + bash_profile =3D '{}\nsource ~/.bashrc\n'.format(bash_prof= ile) + with open(bash_profile_file, 'w') as f: + f.write(bash_profile) + shutil.chown(bash_profile_file, user=3Dusername) + os.chmod(bash_profile_file, 0o644) + + # Add edkrepo command completion to ~/.bashrc if it does not have it a= lready + regex =3D r"\[\[\s+-r\s+\"\S*edkrepo_completions.sh\"\s+\]\]\s+&&\s+.\= s+\"\S*edkrepo_completions.sh\"" + new_source_line =3D '[[ -r "{0}" ]] && . "{0}"'.format(command_complet= ion_script) + comment =3D '\n# Add EdkRepo command completions' + bash_rc_file =3D os.path.join(user_home_dir, '.bashrc') + add_command_comment_to_startup_script(bash_rc_file, regex, new_source_= line, comment, username) + if get_add_prompt_customization(args, user_home_dir): + add_command_to_startup_script(bash_rc_file, prompt_regex, bash_pro= mpt_customization, username) + zsh_rc_file =3D os.path.join(user_home_dir, '.zshrc') + add_command_to_startup_script(zsh_rc_file, zsh_autoload_compinit_regex= , zsh_autoload_compinit, username) + add_command_to_startup_script(zsh_rc_file, zsh_autoload_bashcompinit_r= egex, zsh_autoload_bashcompinit, username) + add_command_to_startup_script(zsh_rc_file, zsh_autoload_colors_regex, = zsh_autoload_colors, username) + add_command_to_startup_script(zsh_rc_file, zsh_colors_regex, zsh_color= s, username) + add_command_to_startup_script(zsh_rc_file, zsh_compinit_regex, zsh_com= pinit, username) + add_command_to_startup_script(zsh_rc_file, zsh_bashcompinit_regex, zsh= _bashcompinit, username) + add_command_comment_to_startup_script(zsh_rc_file, regex, new_source_l= ine, comment, username) + if get_add_prompt_customization(args, user_home_dir): + add_command_to_startup_script(zsh_rc_file, prompt_regex,=20 + zsh_prompt_customization, username) + def do_install(): global def_python org_python =3D None @@ -209,6 +472,7 @@ def do_install(): log.info('- Unable to determine users home directory') return 1 default_cfg_dir =3D os.path.join(user_home_dir, cfg_dir) + get_add_prompt_customization(args, user_home_dir) log.info('+ System information collected') =20 # Display current system information. @@ -348,7 +612,7 @@ def do_install(): #Delete obsolete dependencies if updating_edkrepo: installed_packages =3D get_installed_packages(def_python) - for whl_name in ['smmap2', 'gitdb2']: + for whl_name in ['smmap2', 'gitdb2', 'edkrepo-internal']: if whl_name in installed_packages: try: res =3D default_run([def_python, '-m', 'pip', 'uni= nstall', '--yes', whl_name]) @@ -375,6 +639,23 @@ def do_install(): set_execute_permissions() log.info('+ Marked scripts as executable') =20 + + #Install the command completion script + if shutil.which('edkrepo') is not None: + if args.local: + command_completion_script =3D os.path.join(default_cfg_dir, 'e= dkrepo_completions.sh') + else: + command_completion_script =3D os.path.join('/', 'etc', 'profil= e.d', 'edkrepo_completions.sh') + try: + res =3D default_run(['edkrepo', 'generate-command-completion-s= cript', command_completion_script]) + if args.local: + shutil.chown(command_completion_script, user=3Dusername) + os.chmod(command_completion_script, 0o644) + add_command_completions_to_shell(command_completion_script, ar= gs, username, user_home_dir) + except: + log.info('- Failed to configure edkrepo command completion') + if args.verbose: + traceback.print_exc() log.log(logging.PRINT, '\nInstallation complete\n') =20 return 0 -- 2.24.0.windows.2