From 097da5b2382eb146faf082dadee112937243b028 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 12 Mar 2014 13:14:50 -0400 Subject: [PATCH] support for --overwrite flag --- bob/cli.py | 12 +++++++----- bob/models.py | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/bob/cli.py b/bob/cli.py index a135345..64d6d14 100644 --- a/bob/cli.py +++ b/bob/cli.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- """Usage: bob build - bob deploy + bob deploy [--overwrite] Build formula and optionally deploy it. Options: -h --help - --no-deps skip dependency cascading. + --overwrite allow overwriting of deployed archives. Configuration: Environment Variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_BUCKET @@ -53,14 +53,14 @@ def build(formula): # Then, sidestep. -def deploy(formula): +def deploy(formula, overwrite): f = build(formula) print 'Archiving.' f.archive() print 'Deploying.' - f.deploy() + f.deploy(allow_overwrite=overwrite) @@ -71,9 +71,11 @@ def dispatch(): formula = args[''] do_build = args['build'] do_deploy = args['deploy'] + do_overwrite = args['--overwrite'] + if do_build: build(formula) if do_deploy: - deploy(formula) + deploy(formula, overwrite=do_overwrite) diff --git a/bob/models.py b/bob/models.py index 0480c46..61c589a 100644 --- a/bob/models.py +++ b/bob/models.py @@ -79,19 +79,24 @@ class Formula(object): self.archive_path = archive - def deploy(self): - # TODO: potential support for optional prefix? - # TODO: overwrite flag, default to off + def deploy(self, allow_overwrite=False): + """Deploys the formula's archive to S3.""" assert self.archive_path - k = Key(bucket) - k.key = '{}.tar.gz'.format(self.path) + key_name = '{}.tar.gz'.format(self.path) + key = bucket.get_key(key_name) + + if key: + if not allow_overwrite: + print 'WARNING: {} already exists. Use the --overwrite flag to continue.' + exit() + else: + key = bucket.new_key(key_name + + # Upload the archive, set permissions. k.set_contents_from_filename(self.archive_path) k.set_acl('public-read') - - -