mirror of
https://github.com/kennethreitz/bob-builder-1.git
synced 2026-06-05 23:10:17 +00:00
support for --overwrite flag
This commit is contained in:
+7
-5
@@ -1,13 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Usage: bob build <formula>
|
||||
bob deploy <formula>
|
||||
bob deploy <formula> [--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['<formula>']
|
||||
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)
|
||||
|
||||
+13
-8
@@ -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')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user