Skip to content

Commit

Permalink
Work in progress S3 website command
Browse files Browse the repository at this point in the history
Just the general structure.
  • Loading branch information
jamesls committed Nov 12, 2013
1 parent 5207986 commit 270b513
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions awscli/customizations/s3/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,14 @@ def _create_subcommand_table(self):
for cmd in CMD_DICT.keys():
cmd_specification = CMD_DICT[cmd]
cmd_class = cmd_specification.get('command_class', S3SubCommand)

# If a cmd_class is provided, the we'll try to grab the
# description and usage off of that object, otherwise
# we'll look in the command dict.
description, usage = self._get_command_usage(cmd_class)
subcommand_table[cmd] = cmd_class(
cmd, self._session, cmd_specification['options'],
cmd_specification['description'], cmd_specification['usage'])
cmd_specification.get('description', description),
cmd_specification.get('usage', usage))

self._session.emit('building-operation-table.%s' % self._name,
operation_table=subcommand_table,
Expand All @@ -194,6 +198,10 @@ def _create_subcommand_table(self):
arg_table=None)
return subcommand_table

def _get_command_usage(self, cmd_class):
return (getattr(cmd_class, 'DESCRIPTION', None),
getattr(cmd_class, 'USAGE', None))

def create_help_command(self):
"""
This function returns a help command object with a filled command
Expand All @@ -210,6 +218,8 @@ class S3SubCommand(object):
"""
This is the object corresponding to a S3 subcommand.
"""
DESCRIPTION = None
USAGE = None

def __init__(self, name, session, options, documentation="", usage=""):
"""
Expand Down Expand Up @@ -399,6 +409,31 @@ def _make_size_str(self, size):
return size_str.rjust(10, ' ')


class WebsiteCommand(S3SubCommand):
DESCRIPTION = 'Create website configuration for an S3 bucket'
USAGE = 'Usage?'

def _do_command(self, parsed_args, parsed_globals):
service = self._session.get_service('s3')
endpoint = service.get_endpoint(parsed_globals.region)
operation = service.get_operation('PutBucketWebsite')
bucket = self._get_bucket_name(parsed_args.paths[0])
website_configuration = {}
# operation.call(endpoint, bucket=bucket, website_configuration=website_configuration)

def _get_bucket_name(self, path):
# We support either:
# s3://bucketname
# bucketname
#
# We also strip off the trailing slash if a user
# accidently appends a slash.
if path.startswith('s3://'):
path = path[5:]
if path.endswith('/'):
path = path[:-1]
return path


class S3Parameter(BaseCLIArgument):
"""
Expand Down Expand Up @@ -773,7 +808,10 @@ def check_region(self, parsed_globals):
'params': [], 'default': 's3://',
'command_class': ListCommand},
'mb': {'options': {'nargs': 1}, 'params': []},
'rb': {'options': {'nargs': 1}, 'params': ['force']}
'rb': {'options': {'nargs': 1}, 'params': ['force']},
'website': {'options': {'nargs': 1},
'params': ['index-document', 'error-document'],
'command_class': WebsiteCommand},
}

add_command_descriptions(CMD_DICT)
Expand Down Expand Up @@ -812,6 +850,7 @@ def check_region(self, parsed_globals):
'content-encoding': {'options': {'nargs': 1}},
'content-language': {'options': {'nargs': 1}},
'expires': {'options': {'nargs': 1}},
'index-document': {'options': {}, 'documents': 'The foo of bar.'},
'error-document': {'options': {}, 'documents': 'The bar of foo.'},
}

add_param_descriptions(PARAMS_DICT)

0 comments on commit 270b513

Please sign in to comment.