From 552d49a3c1fbbeef919f515dc266dcd5ee997ef3 Mon Sep 17 00:00:00 2001 From: Daniel Norman Date: Wed, 19 Aug 2020 15:00:54 -0700 Subject: [PATCH] Adds an --overwrite flag to always overwrite install dir. This is useful for calling update.py from other scripts. Test: Calls 'update.py --overwrite' with an existing install-dir. Change-Id: Idc43afbf3e80150b589630dea28004726dccf808 --- vendor_snapshot/update.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/vendor_snapshot/update.py b/vendor_snapshot/update.py index 71e2ffdf6..b89c49113 100644 --- a/vendor_snapshot/update.py +++ b/vendor_snapshot/update.py @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -"""Installs vendor snapshot under prebuilts/vendor/v{version}.""" +"""Unzips and installs the vendor snapshot.""" import argparse import glob @@ -359,6 +359,11 @@ def get_args(): help=( 'Base directory to which vendor snapshot artifacts are installed. ' 'Example: --install-dir vendor//vendor_snapshot/v30')) + parser.add_argument( + '--overwrite', + action='store_true', + help=( + 'If provided, does not ask before overwriting the install-dir.')) parser.add_argument( '-v', @@ -405,16 +410,21 @@ def main(): install_dir = os.path.expanduser(args.install_dir) if os.path.exists(install_dir): - resp = input('Directory {} already exists. IT WILL BE REMOVED.\n' - 'Are you sure? (yes/no): '.format(install_dir)) - if resp == 'yes': + def remove_dir(): logging.info('Removing {}'.format(install_dir)) check_call(['rm', '-rf', install_dir]) - elif resp == 'no': - logging.info('Cancelled snapshot install.') - return + if args.overwrite: + remove_dir() else: - raise ValueError('Did not understand: ' + resp) + resp = input('Directory {} already exists. IT WILL BE REMOVED.\n' + 'Are you sure? (yes/no): '.format(install_dir)) + if resp == 'yes': + remove_dir() + elif resp == 'no': + logging.info('Cancelled snapshot install.') + return + else: + raise ValueError('Did not understand: ' + resp) check_call(['mkdir', '-p', install_dir]) install_artifacts(